The base commit
This commit is contained in:
commit
9f3b274086
27
.editorconfig
Normal file
27
.editorconfig
Normal file
@ -0,0 +1,27 @@
|
||||
# https://EditorConfig.org
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.rs]
|
||||
max_line_length = 100
|
||||
|
||||
[*.{py,pyi}]
|
||||
max_line_length = 100
|
||||
|
||||
[*.md]
|
||||
max_line_length = 150
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.sh]
|
||||
indent_size = 2
|
||||
|
||||
[*.{yaml,yml}]
|
||||
indent_size = 2
|
||||
53
.gitattributes
vendored
Normal file
53
.gitattributes
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
# Normalize all text files to LF line endings
|
||||
* text=auto eol=lf
|
||||
|
||||
# Go source files
|
||||
*.go text
|
||||
*.mod text
|
||||
*.sum text
|
||||
|
||||
# Markdown and documentation files
|
||||
*.md text
|
||||
*.rst text
|
||||
|
||||
# JSON, YAML, and configuration files
|
||||
*.json text
|
||||
*.yaml text
|
||||
*.yml text
|
||||
*.toml text
|
||||
|
||||
# Shell scripts
|
||||
*.sh text eol=lf
|
||||
|
||||
# Static files
|
||||
*.html text
|
||||
*.css text
|
||||
*.js text
|
||||
*.svg text
|
||||
*.xml text
|
||||
|
||||
# Large assets (use Git LFS)
|
||||
*.png filter=lfs diff=lfs merge=lfs -text
|
||||
*.jpg filter=lfs diff=lfs merge=lfs -text
|
||||
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
||||
*.gif filter=lfs diff=lfs merge=lfs -text
|
||||
*.ico filter=lfs diff=lfs merge=lfs -text
|
||||
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
||||
*.mov filter=lfs diff=lfs merge=lfs -text
|
||||
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||
*.tar filter=lfs diff=lfs merge=lfs -text
|
||||
*.gz filter=lfs diff=lfs merge=lfs -text
|
||||
*.tgz filter=lfs diff=lfs merge=lfs -text
|
||||
|
||||
# Font files (binary, tracked via LFS)
|
||||
*.ttf filter=lfs diff=lfs merge=lfs -text
|
||||
*.woff filter=lfs diff=lfs merge=lfs -text
|
||||
*.woff2 filter=lfs diff=lfs merge=lfs -text
|
||||
|
||||
# Build artifacts (binary, optional LFS tracking)
|
||||
*.exe filter=lfs diff=lfs merge=lfs -text
|
||||
*.dll filter=lfs diff=lfs merge=lfs -text
|
||||
*.so filter=lfs diff=lfs merge=lfs -text
|
||||
*.out filter=lfs diff=lfs merge=lfs -text
|
||||
*.a filter=lfs diff=lfs merge=lfs -text
|
||||
*.o filter=lfs diff=lfs merge=lfs -text
|
||||
85
.gitignore
vendored
Normal file
85
.gitignore
vendored
Normal file
@ -0,0 +1,85 @@
|
||||
# Python specific
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# Virtual environments
|
||||
.env/
|
||||
env/
|
||||
.venv/
|
||||
venv/
|
||||
|
||||
# Packaging and distribution files
|
||||
.Python
|
||||
build/
|
||||
dist/
|
||||
*.egg-info/
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# Dependency directories
|
||||
develop-eggs/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
.installed.cfg
|
||||
|
||||
# Test and coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
|
||||
# IDE specific files and directories
|
||||
.idea/
|
||||
*.iml
|
||||
.vscode/
|
||||
|
||||
# Jupyter Notebook files
|
||||
.ipynb_checkpoints
|
||||
|
||||
# Temporary files created by editors and the system and folders to ignore
|
||||
*.swp
|
||||
*~
|
||||
*.bak
|
||||
*.tmp
|
||||
temp/
|
||||
tmp/
|
||||
|
||||
# Database files (SQLite, DuckDB, etc.)
|
||||
*.duckdb
|
||||
*.db
|
||||
*.wal
|
||||
*.sqlite
|
||||
|
||||
# Dependency lock files (uncomment to ignore)
|
||||
poetry.lock
|
||||
|
||||
# Rust specific
|
||||
/target/
|
||||
.cargo-ok
|
||||
cobertura.xml
|
||||
tarpaulin-report.html
|
||||
|
||||
# Comment out the next line if you want to checkin your lock file for Cargo
|
||||
Cargo.lock
|
||||
|
||||
# Miscellaneous files and directories to ignore
|
||||
# Add any additional file patterns a directory names that should be ignored down here
|
||||
.DS_Store
|
||||
tests/testdata/*.csv
|
||||
tests/testdata/*.parquet
|
||||
.benchmarks
|
||||
.env
|
||||
43
.pre-commit-config.yaml
Normal file
43
.pre-commit-config.yaml
Normal file
@ -0,0 +1,43 @@
|
||||
default_stages: [ pre-push ]
|
||||
fail_fast: false
|
||||
exclude: '^(benches/|tests/|examples/|docs/)'
|
||||
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v5.0.0
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
args: [ --markdown-linebreak-ext=md ]
|
||||
- id: end-of-file-fixer
|
||||
- id: mixed-line-ending
|
||||
- id: check-merge-conflict
|
||||
- id: check-added-large-files
|
||||
- id: detect-private-key
|
||||
- id: check-yaml
|
||||
- id: check-toml
|
||||
- id: check-json
|
||||
- id: check-docstring-first
|
||||
- id: pretty-format-json
|
||||
args: [ --autofix, --no-sort-keys ]
|
||||
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: format
|
||||
name: Format Code
|
||||
entry: make format
|
||||
language: system
|
||||
pass_filenames: false
|
||||
stages: [ pre-commit ]
|
||||
|
||||
- id: lint
|
||||
name: Check Code Style
|
||||
entry: make lint
|
||||
language: system
|
||||
pass_filenames: false
|
||||
stages: [ pre-commit ]
|
||||
|
||||
- id: test
|
||||
name: Run Tests
|
||||
entry: make nexttest
|
||||
language: system
|
||||
pass_filenames: false
|
||||
201
LICENSE-APACHE
Normal file
201
LICENSE-APACHE
Normal file
@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
21
LICENSE-MIT
Normal file
21
LICENSE-MIT
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 Obsidian Systems LLC
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
140
Makefile
Normal file
140
Makefile
Normal file
@ -0,0 +1,140 @@
|
||||
# Load environment variables from .env file
|
||||
ifneq (,$(wildcard ./.env))
|
||||
include .env
|
||||
export $(shell sed 's/=.*//' .env)
|
||||
else
|
||||
$(warning .env file not found. Environment variables not loaded.)
|
||||
endif
|
||||
|
||||
# Variables
|
||||
PROJ_REPO = github.com/habedi/template-rust-project
|
||||
BINARY_NAME := $(or $(PROJ_BINARY), $(notdir $(PROJ_REPO)))
|
||||
BINARY := target/release/$(BINARY_NAME)
|
||||
PATH := /snap/bin:$(PATH)
|
||||
DEBUG_PROJ := 0
|
||||
RUST_BACKTRACE := 1
|
||||
ASSET_DIR := assets
|
||||
TEST_DATA_DIR := tests/testdata
|
||||
SHELL := /bin/bash
|
||||
|
||||
# Default target
|
||||
.DEFAULT_GOAL := help
|
||||
|
||||
.PHONY: help
|
||||
help: ## Show help messages for all available targets
|
||||
@grep -E '^[a-zA-Z_-]+:.*## .*$$' Makefile | \
|
||||
awk 'BEGIN {FS = ":.*## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
||||
|
||||
.PHONY: format
|
||||
format: ## Format Rust files
|
||||
@echo "Formatting Rust files..."
|
||||
@cargo fmt
|
||||
|
||||
.PHONY: test
|
||||
test: format ## Run the tests
|
||||
@echo "Running tests..."
|
||||
@DEBUG_PROJ=$(DEBUG_PROJ) RUST_BACKTRACE=$(RUST_BACKTRACE) cargo test --all-targets --workspace -- --nocapture
|
||||
|
||||
.PHONY: coverage
|
||||
coverage: format ## Generate test coverage report
|
||||
@echo "Generating test coverage report..."
|
||||
@DEBUG_PROJ=$(DEBUG_PROJ) cargo tarpaulin --out Xml --out Html
|
||||
|
||||
.PHONY: build
|
||||
build: format ## Build the binary for the current platform
|
||||
@echo "Building the project..."
|
||||
@DEBUG_PROJ=$(DEBUG_PROJ) cargo build --release
|
||||
|
||||
.PHONY: run
|
||||
run: build ## Build and run the binary
|
||||
@echo "Running the $(BINARY) binary..."
|
||||
@DEBUG_PROJ=$(DEBUG_PROJ) ./$(BINARY)
|
||||
|
||||
.PHONY: clean
|
||||
clean: ## Remove generated and temporary files
|
||||
@echo "Cleaning up..."
|
||||
@cargo clean
|
||||
@rm -f $(ASSET_DIR)/*.svg && echo "Removed SVG files; might want to run 'make figs' to regenerate them."
|
||||
|
||||
.PHONY: install-snap
|
||||
install-snap: ## Install a few dependencies using Snapcraft
|
||||
@echo "Installing the snap package..."
|
||||
@sudo apt-get update
|
||||
@sudo apt-get install -y snapd graphviz wget
|
||||
@sudo snap refresh
|
||||
@sudo snap install rustup --classic
|
||||
|
||||
.PHONY: install-deps
|
||||
install-deps: install-snap ## Install development dependencies
|
||||
@echo "Installing dependencies..."
|
||||
@rustup component add rustfmt clippy
|
||||
@cargo install cargo-tarpaulin
|
||||
@cargo install cargo-audit
|
||||
@cargo install cargo-careful
|
||||
@cargo install cargo-nextest
|
||||
|
||||
.PHONY: lint
|
||||
lint: format ## Run the linters
|
||||
@echo "Linting Rust files..."
|
||||
@DEBUG_PROJ=$(DEBUG_PROJ) cargo clippy -- -D warnings -D clippy::unwrap_used -D clippy::expect_used
|
||||
|
||||
.PHONY: publish
|
||||
publish: ## Publish the package to crates.io (requires CARGO_REGISTRY_TOKEN to be set)
|
||||
@echo "Publishing the package to Cargo registry..."
|
||||
@cargo publish --token $(CARGO_REGISTRY_TOKEN)
|
||||
|
||||
.PHONY: bench
|
||||
bench: ## Run the benchmarks
|
||||
@echo "Running benchmarks..."
|
||||
@DEBUG_PROJ=$(DEBUG_PROJ) cargo bench
|
||||
|
||||
.PHONY: audit
|
||||
audit: ## Run security audit on Rust dependencies
|
||||
@echo "Running security audit..."
|
||||
@cargo audit
|
||||
|
||||
.PHONY: rust-careful
|
||||
careful: ## Run security checks on Rust code
|
||||
@echo "Running security checks..."
|
||||
@cargo careful
|
||||
|
||||
.PHONY: docs
|
||||
docs: format ## Generate the documentation
|
||||
@echo "Generating documentation..."
|
||||
@cargo doc --no-deps --document-private-items
|
||||
|
||||
.PHONE: figs
|
||||
figs: ## Generate the figures in the assets directory
|
||||
@echo "Generating figures..."
|
||||
@$(SHELL) $(ASSET_DIR)/make_figures.sh $(ASSET_DIR)
|
||||
|
||||
.PHONY: fix-lint
|
||||
fix-lint: ## Fix the linter warnings
|
||||
@echo "Fixing linter warnings..."
|
||||
@cargo clippy --fix --allow-dirty --allow-staged --all-targets --workspace --all-features -- -D warnings -D clippy::unwrap_used -D clippy::expect_used
|
||||
|
||||
.PHONY: testdata
|
||||
testdata: ## Download the datasets used in tests
|
||||
@echo "Downloading test data..."
|
||||
@$(SHELL) $(TEST_DATA_DIR)/download_datasets.sh $(TEST_DATA_DIR)
|
||||
|
||||
.PHONY: nextest
|
||||
nextest: ## Run tests using nextest
|
||||
@echo "Running tests using nextest..."
|
||||
@DEBUG_PROJ=$(DEBUG_PROJ) RUST_BACKTRACE=$(RUST_BACKTRACE) cargo nextest run
|
||||
|
||||
.PHONY: setup-hooks
|
||||
setup-hooks: ## Install Git hooks (pre-commit and pre-push)
|
||||
@echo "Setting up Git hooks..."
|
||||
@if ! command -v pre-commit &> /dev/null; then \
|
||||
echo "pre-commit not found. Please install it using 'pip install pre-commit'"; \
|
||||
exit 1; \
|
||||
fi
|
||||
@pre-commit install --hook-type pre-commit
|
||||
@pre-commit install --hook-type pre-push
|
||||
@pre-commit install-hooks
|
||||
|
||||
.PHONY: test-hooks
|
||||
test-hooks: ## Test Git hooks on all files
|
||||
@echo "Testing Git hooks..."
|
||||
@pre-commit run --all-files --show-diff-on-failure
|
||||
12
README.md
Normal file
12
README.md
Normal file
@ -0,0 +1,12 @@
|
||||
## Integrations
|
||||
|
||||
---
|
||||
|
||||
To be added.
|
||||
|
||||
### License
|
||||
|
||||
This project is licensed under either of these:
|
||||
|
||||
* MIT License (see [LICENSE-MIT](LICENSE-MIT))
|
||||
* Apache License, Version 2.0 (see [LICENSE-APACHE](LICENSE-APACHE))
|
||||
153
haskell/notes/001-garnet.md
Normal file
153
haskell/notes/001-garnet.md
Normal file
@ -0,0 +1,153 @@
|
||||
# Garnet findings
|
||||
|
||||
Date: 2026-03-24
|
||||
Path inspected: `./tmp/garnet`
|
||||
|
||||
## Plain-English summary
|
||||
|
||||
`./tmp/garnet` is a small experiment for calling Rust from Haskell.
|
||||
|
||||
The flow is:
|
||||
|
||||
1. Define Rust functions and data types.
|
||||
2. Export them as a C ABI.
|
||||
3. Generate a C header with `cbindgen`.
|
||||
4. Generate Haskell-side low-level bindings with `hs-bindgen`.
|
||||
5. Add hand-written Haskell wrappers on top.
|
||||
6. Run a demo executable to show the setup works.
|
||||
|
||||
This looks like a prototype or reference repo, not a finished product.
|
||||
|
||||
## What it is
|
||||
|
||||
This is a mixed Haskell/Rust FFI demo.
|
||||
|
||||
It contains:
|
||||
|
||||
- a Cabal package named `garnet`
|
||||
- a Rust static library in `./tmp/garnet/rust`
|
||||
- Haskell modules for raw bindings and higher-level wrappers
|
||||
- a small executable that exercises the API
|
||||
- a shell build script
|
||||
- a Nix flake for the development environment
|
||||
|
||||
## What it is trying to prove
|
||||
|
||||
The repo appears to be testing whether this toolchain is practical:
|
||||
|
||||
Rust -> `cbindgen` -> C header -> `hs-bindgen` -> Haskell wrappers
|
||||
|
||||
It also tests whether the approach can handle more than trivial examples, including:
|
||||
|
||||
- C strings
|
||||
- plain structs
|
||||
- enums
|
||||
- simple arithmetic
|
||||
- recursive tree-shaped data
|
||||
|
||||
## Key files
|
||||
|
||||
- `./tmp/garnet/rust/lib.rs`
|
||||
- Rust definitions for exported FFI functions and example types
|
||||
- `./tmp/garnet/rust/build.rs`
|
||||
- generates `garnet_rs.h` and patches it for compatibility with `hs-bindgen`
|
||||
- `./tmp/garnet/lib/GarnetRs/Raw.hs`
|
||||
- drives low-level binding generation from the generated header
|
||||
- `./tmp/garnet/lib/GarnetRs/Wrapped.hs`
|
||||
- adds Haskell-friendly wrapper types and conversion code
|
||||
- `./tmp/garnet/exe/Main.hs`
|
||||
- demo executable using the wrapper API
|
||||
- `./tmp/garnet/build`
|
||||
- custom build script for Rust + Cabal coordination
|
||||
|
||||
## Easy reading of the design
|
||||
|
||||
### Rust side
|
||||
|
||||
The Rust library exports a handful of example FFI functions:
|
||||
|
||||
- `hello`
|
||||
- `hello_struct`
|
||||
- `hello_shape`
|
||||
- `add`
|
||||
- `sum_tree`
|
||||
|
||||
These are not a product API. They are examples chosen to stress different interop cases.
|
||||
|
||||
### Haskell side
|
||||
|
||||
The Haskell code is split into two layers:
|
||||
|
||||
- `GarnetRs.Raw`
|
||||
- low-level generated bindings
|
||||
- `GarnetRs.Wrapped`
|
||||
- nicer Haskell-facing types and functions
|
||||
|
||||
This separation is a good design choice. It keeps generated code concerns away from the public API.
|
||||
|
||||
## Critical assessment
|
||||
|
||||
This repo is technically promising, but clearly unfinished.
|
||||
|
||||
What looks good:
|
||||
|
||||
- It demonstrates the full end-to-end workflow.
|
||||
- It goes beyond the easiest possible FFI examples.
|
||||
- It keeps raw and wrapped APIs separate.
|
||||
- It includes a dev shell, which improves reproducibility.
|
||||
|
||||
What looks weak:
|
||||
|
||||
- The build flow is manual and somewhat brittle.
|
||||
- The project depends on pinned git sources and alpha-stage tooling.
|
||||
- The Rust build script contains a workaround for upstream tooling issues.
|
||||
- The Haskell wrapper layer still requires manual boilerplate.
|
||||
- There is no obvious sign of tests, CI, or a stability story.
|
||||
|
||||
## Pros of the approach
|
||||
|
||||
- **Clear architecture**: raw bindings and ergonomic wrappers are separated well.
|
||||
- **Good exploration value**: useful for learning the actual friction points in Rust/Haskell interop.
|
||||
- **Covers realistic cases**: includes enums and recursive data, not just simple integers.
|
||||
- **Small and understandable**: the repo is compact enough to inspect quickly.
|
||||
- **Useful as a reference**: someone exploring `hs-bindgen` could learn from it.
|
||||
|
||||
## Cons of the approach
|
||||
|
||||
- **Custom build glue**: the shell script and symlink step suggest the toolchain is not yet smooth.
|
||||
- **Dependency fragility**: pinned git dependencies increase maintenance burden.
|
||||
- **Tooling immaturity**: the repo already needs local workarounds for upstream issues.
|
||||
- **Manual wrapper overhead**: generated bindings do not remove the need for hand-written API cleanup.
|
||||
- **Potential safety complexity**: FFI, pointer conversions, and `unsafe` code are easy to get wrong.
|
||||
- **Weak production story**: this setup does not yet look ready for long-term team use.
|
||||
|
||||
## Status of the work
|
||||
|
||||
My assessment of current status:
|
||||
|
||||
- **Stage**: proof of concept / exploration
|
||||
- **Scope**: enough code exists to show the full path works
|
||||
- **Maturity**: decent as an experiment, weak as a reusable foundation
|
||||
- **Stability**: uncertain because of upstream pins and workarounds
|
||||
- **Readiness**: not production-ready
|
||||
|
||||
In simple terms: this looks like “we got it working” rather than “we finished the system.”
|
||||
|
||||
## Likely next problems if this grows
|
||||
|
||||
If someone tried to turn this into a serious integration layer, the next hard problems would likely be:
|
||||
|
||||
- making the build process less custom
|
||||
- reducing wrapper boilerplate
|
||||
- keeping generated headers and bindings in sync
|
||||
- handling more complex Rust types safely
|
||||
- upgrading upstream tooling without breakage
|
||||
- adding tests that catch FFI regressions early
|
||||
|
||||
## Bottom line
|
||||
|
||||
`./tmp/garnet` is a useful and interesting interop prototype.
|
||||
|
||||
It succeeds as a demonstration that Rust -> C header -> Haskell bindings -> Haskell wrapper can work. But it also shows the current cost of that path: manual build glue, unstable dependencies, wrapper code, and reliance on tool-specific workarounds.
|
||||
|
||||
Overall: good experiment, useful reference, not mature infrastructure yet.
|
||||
10
pyproject.toml
Normal file
10
pyproject.toml
Normal file
@ -0,0 +1,10 @@
|
||||
[project]
|
||||
name = "integrations"
|
||||
version = "0.1.0"
|
||||
description = "Python environment for the integrations project"
|
||||
|
||||
requires-python = ">=3.10,<4.0"
|
||||
dependencies = [
|
||||
"maturin[zig] (>=1.8.3,<2.0.0)",
|
||||
"numpy (>=2.2.6,<3.0.0)",
|
||||
]
|
||||
3
rust-toolchain.toml
Normal file
3
rust-toolchain.toml
Normal file
@ -0,0 +1,3 @@
|
||||
[toolchain]
|
||||
channel = "1.83.0"
|
||||
components = ["rustfmt", "clippy", "rust-analyzer"]
|
||||
34
rust/cli.rs
Normal file
34
rust/cli.rs
Normal file
@ -0,0 +1,34 @@
|
||||
use std::ffi::OsString;
|
||||
use tracing::error;
|
||||
|
||||
pub fn run(args: impl IntoIterator<Item = OsString>) -> Result<(), i32> {
|
||||
let _args: Vec<OsString> = args.into_iter().collect();
|
||||
// Your implementation here
|
||||
// Expecting at least 2 arguments
|
||||
if _args.len() < 2 {
|
||||
error!("Expecting at least 2 arguments");
|
||||
return Err(1);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Unit tests
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::ffi::OsString;
|
||||
|
||||
#[test]
|
||||
fn test_run_with_valid_args() {
|
||||
let args = vec![OsString::from("arg1"), OsString::from("arg2")];
|
||||
let result = run(args);
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_run_with_invalid_args() {
|
||||
let args = vec![OsString::from("invalid_arg")];
|
||||
let result = run(args);
|
||||
assert!(result.is_err());
|
||||
}
|
||||
}
|
||||
2
rust/lib.rs
Normal file
2
rust/lib.rs
Normal file
@ -0,0 +1,2 @@
|
||||
pub mod cli;
|
||||
pub mod logging;
|
||||
17
rust/logging.rs
Normal file
17
rust/logging.rs
Normal file
@ -0,0 +1,17 @@
|
||||
use ctor::ctor;
|
||||
use tracing::Level;
|
||||
use tracing_subscriber;
|
||||
|
||||
#[ctor]
|
||||
fn set_debug_level() {
|
||||
// If DEBUG_PROJ is not set or set to false, disable logging. Otherwise, enable logging
|
||||
if std::env::var("DEBUG_PROJ").map_or(true, |v| v == "0" || v == "false" || v.is_empty()) {
|
||||
// Disable logging
|
||||
} else {
|
||||
tracing_subscriber::fmt()
|
||||
.with_max_level(Level::DEBUG)
|
||||
.init();
|
||||
}
|
||||
|
||||
//println!("DEBUG_PROJ: {:?}", std::env::var("DEBUG_PROJ"));
|
||||
}
|
||||
7
rust/main.rs
Normal file
7
rust/main.rs
Normal file
@ -0,0 +1,7 @@
|
||||
use template_rust_project::cli::run;
|
||||
|
||||
fn main() {
|
||||
if let Err(code) = run(std::env::args_os()) {
|
||||
std::process::exit(code);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user