Skip to content

Commit

Permalink
capi: switch to cargo-c
Browse files Browse the repository at this point in the history
It seems cargo-c is the "recommended" way of building distro-friendly
.so's for Rust crates and so switch to that.

The lack of fine-grained SONAME control might be an issue in the future
(when we do a 1.0 release, we probably don't want to do a full SONAME
API breakage -- but maybe we can do a 1.0 release when pathrs is ready
for packaging anyway). It also seems that the ability to do Version.map
stuff is limited with cargo-c, but we can cross that bridge when we get
to it (for the most part there aren't many cargo-c-specific changes).

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
  • Loading branch information
cyphar committed Sep 7, 2024
1 parent b5d1436 commit d1d6efb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 39 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/bindings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jobs:
- uses: actions/checkout@v4
# Build and install libpathrs.so.
- uses: dtolnay/rust-toolchain@stable
- uses: taiki-e/install-action@v2
with:
tool: cargo-c
- name: build libpathrs
run: make release
- name: install libpathrs
Expand All @@ -50,6 +53,9 @@ jobs:
- uses: actions/checkout@v4
# Build and install libpathrs.so.
- uses: dtolnay/rust-toolchain@stable
- uses: taiki-e/install-action@v2
with:
tool: cargo-c
- name: build libpathrs
run: make release
- name: install libpathrs
Expand All @@ -73,6 +79,9 @@ jobs:
- uses: actions/checkout@v4
# Build and install libpathrs.so.
- uses: dtolnay/rust-toolchain@stable
- uses: taiki-e/install-action@v2
with:
tool: cargo-c
- name: build libpathrs
run: make release
- name: install libpathrs
Expand Down
18 changes: 14 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,20 @@ rust-version = "1.63"
maintenance = { status = "experimental" }

[lib]
crate-type = ["rlib", "cdylib", "staticlib"]
crate-type = ["rlib"]

[package.metadata.capi.header]
subdirectory = false

[package.metadata.capi.library]
name = "pathrs"
# TODO: In order to avoid breaking dependencies when we do our 1.0 release, we
# might need to fake the so version...
#version = "1.0.0"
#version_suffix_components = 1
# Since we are cdylib, panic!s will cause aborts once they hit the FFI barrier
# anyway. We might as well reduce our code size if we're doing it.
rustflags = "-Cpanic=abort"

[features]
capi = ["dep:rand"]
Expand All @@ -43,9 +56,6 @@ _test_as_root = []
[profile.release]
# Enable link-time optimisations.
lto = true
# Since we are cdylib, panic!s will cause aborts once they hit the FFI barrier
# anyway. We might as well reduce our code size if we're doing it.
panic = "abort"

[dependencies]
bitflags = "^2"
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ CARGO ?= cargo
CARGO_NIGHTLY ?= cargo +nightly

SRC_FILES = $(shell find . -name '*.rs')
CAPI_FEATURES = --features=capi
DESTDIR ?= /

.PHONY: debug
debug: target/debug

target/debug: $(SRC_FILES)
$(CARGO) build $(CAPI_FEATURES)
$(CARGO) cbuild

.PHONY: release
release: target/release

target/release: $(SRC_FILES)
$(CARGO) build $(CAPI_FEATURES) --release
$(CARGO) cbuild --release

.PHONY: smoke-test
smoke-test:
Expand Down Expand Up @@ -83,7 +83,7 @@ docs:

.PHONY: install
install: release
@echo "If you want to configure the install paths, use ./install.sh directly."
@echo "If you want to configure the install paths, use 'cargo cinstall' directly."
@echo "[Sleeping for 3 seconds.]"
@sleep 3s
./install.sh
cargo cinstall --release --destdir=$(DESTDIR) --prefix=/usr
30 changes: 0 additions & 30 deletions build.rs

This file was deleted.

0 comments on commit d1d6efb

Please sign in to comment.