From eec67ec109d63b516f7ba1991f343bb82ff41bb4 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 31 Aug 2023 14:08:15 -0400 Subject: [PATCH 1/3] Drop cap-std from our public APIs Since it bumped semver (when I didn't expect it to; xref https://github.com/bytecodealliance/cap-std/commit/963eebf3ab52b04a2e8b9ba88ce6308bbed5cbd0#r121651362 It's not load-bearing enough here to matter versus just passing an untyped file descriptor. This mainly means that it will be the `glib` ecosystem which forces transitive semver bumps for us, not both. --- .github/workflows/rust.yml | 2 +- Cargo.toml | 6 ++---- rust-bindings/src/lib.rs | 2 -- rust-bindings/src/repo.rs | 28 ++++++++++------------------ rust-bindings/tests/repo/mod.rs | 14 +++++++++++--- rust-bindings/tests/util/mod.rs | 11 ++++++++--- 6 files changed, 32 insertions(+), 31 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a3bb8678b8..faa44bab2d 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -11,7 +11,7 @@ on: env: CARGO_TERM_COLOR: always - CARGO_PROJECT_FEATURES: "v2021_5,cap-std-apis" + CARGO_PROJECT_FEATURES: "v2022_6" # TODO: Automatically query this from the C side LATEST_LIBOSTREE: "v2022_6" # Pinned toolchain for linting diff --git a/Cargo.toml b/Cargo.toml index 37959f6df8..21f4a2f110 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,8 +40,6 @@ members = [".", "rust-bindings/sys"] [dependencies] base64 = "0.20.0" bitflags = "1.2.1" -cap-std = { version = "1.0", optional = true} -io-lifetimes = { version = "1.0", optional = true} ffi = { package = "ostree-sys", path = "rust-bindings/sys", version = "0.13.0" } gio = "0.16" glib = "0.16" @@ -53,10 +51,10 @@ thiserror = "1.0.20" [dev-dependencies] maplit = "1.0.2" tempfile = "3" -cap-tempfile = "1.0" +io-lifetimes = "1" +cap-tempfile = "2" [features] -cap-std-apis = ["cap-std", "io-lifetimes", "v2017_10"] dox = ["ffi/dox"] v2014_9 = ["ffi/v2014_9"] v2015_7 = ["v2014_9", "ffi/v2015_7"] diff --git a/rust-bindings/src/lib.rs b/rust-bindings/src/lib.rs index 01f8ad08f5..69a72cdc4a 100644 --- a/rust-bindings/src/lib.rs +++ b/rust-bindings/src/lib.rs @@ -12,8 +12,6 @@ // Re-export our dependencies. See https://gtk-rs.org/blog/2021/06/22/new-release.html // "Dependencies are re-exported". Users will need e.g. `gio::File`, so this avoids // them needing to update matching versions. -#[cfg(feature = "cap-std-apis")] -pub use cap_std; pub use ffi; pub use gio; pub use glib; diff --git a/rust-bindings/src/repo.rs b/rust-bindings/src/repo.rs index 1333fd5f65..5739953e50 100644 --- a/rust-bindings/src/repo.rs +++ b/rust-bindings/src/repo.rs @@ -1,11 +1,11 @@ #[cfg(any(feature = "v2016_4", feature = "dox"))] use crate::RepoListRefsExtFlags; -#[cfg(feature = "cap-std-apis")] use crate::RepoMode; use crate::{Checksum, ObjectDetails, ObjectName, ObjectType, Repo, RepoTransactionStats}; use ffi::OstreeRepoListObjectsFlags; use glib::ffi as glib_sys; use glib::{self, translate::*, Error, IsA}; +use std::os::fd::BorrowedFd; use std::{ collections::{HashMap, HashSet}, future::Future, @@ -105,17 +105,17 @@ impl Repo { Repo::new(&gio::File::for_path(path.as_ref())) } - #[cfg(feature = "cap-std-apis")] - /// A version of [`open_at`] which uses cap-std. - pub fn open_at_dir(dir: &cap_std::fs::Dir, path: &str) -> Result { + /// Open using the target directory file descriptor. + #[cfg(any(feature = "v2017_10", feature = "dox"))] + pub fn open_at_dir(dir: BorrowedFd<'_>, path: &str) -> Result { use std::os::unix::io::AsRawFd; crate::Repo::open_at(dir.as_raw_fd(), path, gio::Cancellable::NONE) } - #[cfg(feature = "cap-std-apis")] - /// A version of [`create_at`] which uses cap-std, and also returns the opened repo. + /// A version of [`create_at`] which resolves the path relative to the provided directory file descriptor, and also returns the opened repo. + #[cfg(any(feature = "v2017_10", feature = "dox"))] pub fn create_at_dir( - dir: &cap_std::fs::Dir, + dir: BorrowedFd<'_>, path: &str, mode: RepoMode, options: Option<&glib::Variant>, @@ -152,17 +152,9 @@ impl Repo { } /// Borrow the directory file descriptor for this repository. - #[cfg(feature = "cap-std-apis")] - pub fn dfd_borrow(&self) -> io_lifetimes::BorrowedFd { - unsafe { io_lifetimes::BorrowedFd::borrow_raw(self.dfd()) } - } - - /// Return a new `cap-std` directory reference for this repository. - #[cfg(feature = "cap-std-apis")] - pub fn dfd_as_dir(&self) -> std::io::Result { - use io_lifetimes::AsFd; - let dfd = self.dfd_borrow(); - cap_std::fs::Dir::reopen_dir(&dfd.as_fd()) + #[cfg(feature = "v2017_10")] + pub fn dfd_borrow(&self) -> BorrowedFd { + unsafe { BorrowedFd::borrow_raw(self.dfd()) } } /// Find all objects reachable from a commit. diff --git a/rust-bindings/tests/repo/mod.rs b/rust-bindings/tests/repo/mod.rs index a8d2b9d05c..f0b562f6a7 100644 --- a/rust-bindings/tests/repo/mod.rs +++ b/rust-bindings/tests/repo/mod.rs @@ -1,6 +1,12 @@ use crate::util::*; +#[cfg(feature = "v2017_10")] +use cap_std::fs::Dir; +#[cfg(feature = "v2017_10")] +use cap_tempfile::cap_std; use ostree::prelude::*; use ostree::{ObjectName, ObjectType}; +#[cfg(feature = "v2017_10")] +use std::os::fd::AsFd; #[cfg(any(feature = "v2016_8", feature = "dox"))] mod checkout_at; @@ -54,13 +60,15 @@ fn list_commits() { } #[test] -#[cfg(feature = "cap-std-apis")] +#[cfg(feature = "v2017_10")] fn cap_std_commit() { let test_repo = CapTestRepo::new(); assert!(test_repo.dir.exists("config")); // Also test re-acquiring a new dfd - assert!(test_repo.repo.dfd_as_dir().unwrap().exists("config")); + assert!(Dir::reopen_dir(&test_repo.repo.dfd_borrow()) + .unwrap() + .exists("config")); assert!(test_repo.repo.require_rev("nosuchrev").is_err()); @@ -69,7 +77,7 @@ fn cap_std_commit() { assert_eq!(test_repo.repo.require_rev("test").unwrap(), checksum); - let repo2 = ostree::Repo::open_at_dir(&test_repo.dir, ".").unwrap(); + let repo2 = ostree::Repo::open_at_dir(test_repo.dir.as_fd(), ".").unwrap(); let refs = repo2 .list_refs(None, gio::Cancellable::NONE) .expect("failed to list refs"); diff --git a/rust-bindings/tests/util/mod.rs b/rust-bindings/tests/util/mod.rs index 80886910c9..aed56d431a 100644 --- a/rust-bindings/tests/util/mod.rs +++ b/rust-bindings/tests/util/mod.rs @@ -1,5 +1,9 @@ +#[cfg(feature = "v2017_10")] +use cap_tempfile::cap_std; use glib::prelude::*; use glib::GString; +#[cfg(feature = "v2017_10")] +use std::os::fd::AsFd; use std::path::Path; #[derive(Debug)] @@ -28,13 +32,13 @@ impl TestRepo { } #[derive(Debug)] -#[cfg(feature = "cap-std-apis")] +#[cfg(feature = "v2017_10")] pub struct CapTestRepo { pub dir: cap_tempfile::TempDir, pub repo: ostree::Repo, } -#[cfg(feature = "cap-std-apis")] +#[cfg(feature = "v2017_10")] impl CapTestRepo { pub fn new() -> Self { Self::new_with_mode(ostree::RepoMode::Archive) @@ -42,7 +46,8 @@ impl CapTestRepo { pub fn new_with_mode(repo_mode: ostree::RepoMode) -> Self { let dir = cap_tempfile::tempdir(cap_std::ambient_authority()).unwrap(); - let repo = ostree::Repo::create_at_dir(&dir, ".", repo_mode, None).expect("repo create"); + let repo = + ostree::Repo::create_at_dir(dir.as_fd(), ".", repo_mode, None).expect("repo create"); Self { dir, repo } } } From 242a9015248026a2335df3b503d320dd91d7b5cb Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 31 Aug 2023 15:23:57 -0400 Subject: [PATCH 2/3] rust: Bump rust-version = 1.70 To pick up the new `AsFd` etc. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 21f4a2f110..bdfa604e73 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT" name = "ostree" readme = "rust-bindings/README.md" repository = "https://github.com/ostreedev/ostree" -rust-version = "1.64.0" +rust-version = "1.70.0" version = "0.18.0" exclude = [ From 9121297e7b549d94fc5a5451ecf826e31507ef64 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 31 Aug 2023 16:33:07 -0400 Subject: [PATCH 3/3] ci: Move lints into main build And drop another hardcoded MSRV. --- .github/workflows/rust.yml | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index faa44bab2d..dd159dd96c 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -14,8 +14,6 @@ env: CARGO_PROJECT_FEATURES: "v2022_6" # TODO: Automatically query this from the C side LATEST_LIBOSTREE: "v2022_6" - # Pinned toolchain for linting - ACTION_LINTS_TOOLCHAIN: 1.64.0 jobs: build: @@ -25,10 +23,14 @@ jobs: - uses: actions/checkout@v2 - name: Cache Dependencies uses: Swatinem/rust-cache@ce325b60658c1b38465c06cc965b79baf32c1e72 + - name: cargo fmt (check) + run: cargo fmt -p ostree -- --check -l - name: Build run: cargo build --verbose --features=${{ env['CARGO_PROJECT_FEATURES'] }} - name: Run tests run: cargo test --verbose --features=${{ env['CARGO_PROJECT_FEATURES'] }} + - name: cargo clippy (non-gating) + run: cargo clippy -p ostree --features=${{ env['CARGO_PROJECT_FEATURES'] }} build-minimum-toolchain: name: "Build, minimum supported toolchain (MSRV)" runs-on: ubuntu-latest @@ -83,25 +85,6 @@ jobs: run: cargo test --no-run --verbose --features=${{ env['LATEST_LIBOSTREE'] }} - name: Run tests run: cargo test --verbose --features=${{ env['LATEST_LIBOSTREE'] }} - linting: - name: "Lints, pinned toolchain" - runs-on: ubuntu-latest - container: quay.io/coreos-assembler/fcos-buildroot:testing-devel - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - name: Remove system Rust toolchain - run: dnf remove -y rust cargo - - name: Install toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ env['ACTION_LINTS_TOOLCHAIN'] }} - default: true - components: rustfmt, clippy - - name: cargo fmt (check) - run: cargo fmt -p ostree -- --check -l - - name: cargo clippy (warnings) - run: cargo clippy -p ostree --features=${{ env['CARGO_PROJECT_FEATURES'] }} -- -D warnings cargo-deny: runs-on: ubuntu-latest steps: