Skip to content

Commit 621867e

Browse files
Copiloterikd
andcommitted
Add Makefile with common Rust project targets
* Adds pkgconfig target to generate pkg-config file * Extract version from Cargo.toml and make install platform-aware * Build static lib only, use INSTALL env var, generate pkg-config from template Co-authored-by: Erik de Castro Lopo <erikd@mega-nerd.com>
1 parent 91cd165 commit 621867e

File tree

3 files changed

+105
-1
lines changed

3 files changed

+105
-1
lines changed

Makefile

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
.PHONY: all build build-release test clean fmt fmt-check clippy check doc doc-open ci help pkgconfig install
2+
3+
# Default target
4+
all: build
5+
6+
# Build the project in debug mode
7+
build:
8+
cd rust_accumulator && cargo build
9+
10+
# Build the project in release mode
11+
build-release:
12+
cd rust_accumulator && cargo build --release
13+
14+
# Run tests
15+
test:
16+
cd rust_accumulator && cargo test
17+
18+
# Format code using rustfmt
19+
fmt:
20+
cd rust_accumulator && cargo fmt
21+
22+
# Check formatting
23+
fmt-check:
24+
cd rust_accumulator && cargo fmt --check
25+
26+
# Run clippy linter
27+
clippy:
28+
cd rust_accumulator && cargo clippy -- -D warnings
29+
30+
# Clean build artifacts
31+
clean:
32+
cd rust_accumulator && cargo clean
33+
34+
# Check the project (quick verification without building)
35+
check:
36+
cd rust_accumulator && cargo check
37+
38+
# Build documentation
39+
doc:
40+
cd rust_accumulator && cargo doc --no-deps
41+
42+
# Open documentation in browser
43+
doc-open:
44+
cd rust_accumulator && cargo doc --no-deps --open
45+
46+
# Run all checks (format, clippy, test)
47+
ci: fmt-check clippy test
48+
49+
# Generate pkg-config file
50+
pkgconfig: build-release
51+
@if [ -z "$$INSTALL" ]; then \
52+
echo "Error: INSTALL environment variable is not set."; \
53+
echo "Please set INSTALL to the installation directory, e.g.: export INSTALL=/usr/local"; \
54+
exit 1; \
55+
fi
56+
@mkdir -p rust_accumulator/target/pkgconfig
57+
@VERSION=$$(grep '^version' rust_accumulator/Cargo.toml | head -1 | cut -d'"' -f2); \
58+
sed -e "s|@PREFIX@|$$INSTALL|g" -e "s|@VERSION@|$$VERSION|g" \
59+
librust_accumulator.pc.in > rust_accumulator/target/pkgconfig/librust_accumulator.pc
60+
@echo "pkg-config file created at rust_accumulator/target/pkgconfig/librust_accumulator.pc"
61+
62+
# Install library and pkg-config file
63+
install: build-release pkgconfig
64+
@if [ -z "$$INSTALL" ]; then \
65+
echo "Error: INSTALL environment variable is not set."; \
66+
echo "Please set INSTALL to the installation directory, e.g.: export INSTALL=/usr/local"; \
67+
exit 1; \
68+
fi
69+
@echo "Installing to: $$INSTALL"
70+
install -d $$INSTALL/lib
71+
install -m 644 rust_accumulator/target/release/librust_accumulator.a $$INSTALL/lib/
72+
install -d $$INSTALL/lib/pkgconfig
73+
install -m 644 rust_accumulator/target/pkgconfig/librust_accumulator.pc $$INSTALL/lib/pkgconfig/
74+
@echo "Installation complete. Library installed to $$INSTALL/lib/"
75+
76+
# Show help
77+
help:
78+
@echo "Available targets:"
79+
@echo " all - Build the project in debug mode (default)"
80+
@echo " build - Build the project in debug mode"
81+
@echo " build-release - Build the project in release mode"
82+
@echo " test - Run tests"
83+
@echo " fmt - Format code using rustfmt"
84+
@echo " fmt-check - Check if code is formatted correctly"
85+
@echo " clippy - Run clippy linter"
86+
@echo " check - Quick check without building"
87+
@echo " clean - Clean build artifacts"
88+
@echo " doc - Build documentation"
89+
@echo " doc-open - Build and open documentation in browser"
90+
@echo " ci - Run all checks (format, clippy, test)"
91+
@echo " pkgconfig - Generate pkg-config file (requires INSTALL env var)"
92+
@echo " install - Install library and pkg-config file (requires INSTALL env var)"
93+
@echo " help - Show this help message"

librust_accumulator.pc.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
prefix=@PREFIX@
2+
exec_prefix=${prefix}
3+
libdir=${exec_prefix}/lib
4+
includedir=${prefix}/include
5+
6+
Name: librust_accumulator
7+
Description: A rust based lib for a PCS based accumulator
8+
Version: @VERSION@
9+
10+
Cflags: -I${includedir}
11+
Libs: -L${libdir} -lrust_accumulator

rust_accumulator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2018"
55

66
[lib]
77
name = "rust_accumulator"
8-
crate-type = ["cdylib", "rlib"]
8+
crate-type = ["staticlib"]
99

1010
[dependencies]
1111
blstrs = "0.7.1"

0 commit comments

Comments
 (0)