Skip to content

Commit

Permalink
merge #59 into openSUSE/libpathrs:main
Browse files Browse the repository at this point in the history
Aleksa Sarai (11):
  tests: handle: verify file and fd flags when doing a reopen
  tests: add integration tests for capi from Rust
  tests: procfs: rework macro to be trait-friendly
  tests: use traits to test owned and borrowed types
  procfs: use Into<OpenFlags> for oflags
  capi: correctly mark our extern "C" fns as unsafe
  capi: make opt-in via 'capi' feature
  capi: move all C-specific stuff into capi
  capi: mkdir_all: don't clear mode
  capi: don't return 0..4096 error values
  tests: use pub(in crate::tests) as much as possible

LGTMs: cyphar
  • Loading branch information
cyphar committed Sep 10, 2024
2 parents 086cae8 + 38afe0b commit a1f8e39
Show file tree
Hide file tree
Showing 34 changed files with 3,172 additions and 1,203 deletions.
15 changes: 10 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ rust-version = "1.63"

[badges]
maintenance = { status = "experimental" }
travis-ci = { repository = "openSUSE/libpathrs" }

[lib]
crate-type = ["rlib", "cdylib", "staticlib"]
# When building the CAPI, our Makefile adds --crate-type={cdylib,staticlib}.
crate-type = ["rlib"]

[features]
capi = ["dep:rand"]
# Only used for tests.
_test_as_root = []

Expand All @@ -55,7 +56,7 @@ itertools = "^0.13"
lazy_static = "^1"
libc = "^0.2"
memchr = "^2"
rand = "^0.8"
rand = { version = "^0.8", optional = true }
# MSRV(1.65): Use regex >= 1.10.
regex = "1.9.*"
rustix = { version = "^0.38", features = ["fs"] }
Expand All @@ -72,5 +73,9 @@ pretty_assertions = "^1"
rustix = { version = "^0.38", features = ["process"] }

[lints.rust]
# We have special handling for coverage runs (which set cfg(coverage)).
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(coverage)'] }
unexpected_cfgs = { level = "warn", check-cfg = [
# We have special handling for coverage runs (which set cfg(coverage)).
'cfg(coverage)',
# We set these cfgs when building with --features=capi.
'cfg(cdylib)', 'cfg(staticlib)'
] }
21 changes: 15 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,26 @@ CARGO_NIGHTLY ?= cargo +nightly

SRC_FILES = $(shell find . -name '*.rs')

.DEFAULT: debug
.PHONY: debug
debug: target/debug

target/debug: $(SRC_FILES)
$(CARGO) build
# For some reason, --crate-types needs separate invocations. We can't use
# #![crate_type] unfortunately, as using it with #![cfg_attr] has been
# deprecated. <https://github.com/rust-lang/rust/issues/91632>
$(CARGO) rustc --features=capi --crate-type=cdylib
$(CARGO) rustc --features=capi --crate-type=staticlib

.PHONY: release
release: target/release

target/release: $(SRC_FILES)
$(CARGO) build --release
# For some reason, --crate-types needs separate invocations. We can't use
# #![crate_type] unfortunately, as using it with #![cfg_attr] has been
# deprecated. <https://github.com/rust-lang/rust/issues/91632>
$(CARGO) rustc --features=capi --crate-type=cdylib --release
$(CARGO) rustc --features=capi --crate-type=staticlib --release

.PHONY: smoke-test
smoke-test:
Expand All @@ -50,11 +59,11 @@ lint-rust:

.PHONY: test-rust-doctest
test-rust-doctest:
$(CARGO_NIGHTLY) llvm-cov --no-report --branch --doc
$(CARGO_NIGHTLY) llvm-cov --no-report --branch --all-features --doc

.PHONY: test-rust-unpriv
test-rust-unpriv:
$(CARGO_NIGHTLY) llvm-cov --no-report --branch nextest --no-fail-fast
$(CARGO_NIGHTLY) llvm-cov --no-report --branch --features capi nextest --no-fail-fast

.PHONY: test-rust-root
test-rust-root:
Expand All @@ -64,7 +73,7 @@ test-rust-root:
# support cfg(feature=...) for target runner configs.
# See <https://github.com/rust-lang/cargo/issues/14306>.
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER='sudo -E' \
$(CARGO_NIGHTLY) llvm-cov --no-report --branch --features _test_as_root nextest --no-fail-fast
$(CARGO_NIGHTLY) llvm-cov --no-report --branch --features capi,_test_as_root nextest --no-fail-fast

.PHONY: test-rust
test-rust:
Expand All @@ -78,7 +87,7 @@ test: test-rust

.PHONY: docs
docs:
$(CARGO) doc --document-private-items --open
$(CARGO) doc --all-features --document-private-items --open

.PHONY: install
install: release
Expand Down
18 changes: 11 additions & 7 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@
use std::env;

fn main() {
// Add DT_SONAME to our cdylibs.
let name = "pathrs";
let major = env::var("CARGO_PKG_VERSION_MAJOR").unwrap();
println!(
"cargo:rustc-cdylib-link-arg=-Wl,-soname,lib{}.so.{}",
name, major
);
// Add DT_SONAME to our cdylibs. We can't check the crate-type here
// directly, but we can at least avoid needless warnings for "cargo build"
// by only emitting this when the capi feature is enabled.
if cfg!(feature = "capi") {
let name = "pathrs";
let major = env::var("CARGO_PKG_VERSION_MAJOR").unwrap();
println!(
"cargo:rustc-cdylib-link-arg=-Wl,-soname,lib{}.so.{}",
name, major
);
}
}
7 changes: 7 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ includedir="${includedir:-$prefix/include}"
libdir="${libdir:-$(find_libdir "$exec_prefix")}"
pkgconfigdir="${pkgconfigdir:-$libdir/pkgconfig}"

# TODO: These flags come from RUSTFLAGS="--print=native-static-libs".
# Unfortunately, getting this information from cargo is incredibly unergonomic
# and will hopefully be fixed at some point.
# <https://github.com/rust-lang/rust/pull/43067#issuecomment-330625316>
native_static_libs="-lgcc_s -lutil -lrt -lpthread -lm -ldl -lc"

echo "[pkg-config] generating pathrs pkg-config"
cat >"pathrs.pc" <<EOF
# libpathrs: safe path resolution on Linux
Expand Down Expand Up @@ -165,6 +171,7 @@ Description: Safe path resolution library for Linux
URL: https://github.com/openSUSE/libpathrs
Cflags: -I\${includedir}
Libs: -L\${libdir} -lpathrs
Libs.private: $native_static_libs
EOF

echo "[install] installing libpathrs into DESTDIR=${DESTDIR:-/}"
Expand Down
Loading

0 comments on commit a1f8e39

Please sign in to comment.