Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop cap-std from our public APIs #3027

Merged
merged 3 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 5 additions & 22 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ 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
ACTION_LINTS_TOOLCHAIN: 1.64.0

jobs:
build:
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 3 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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"
Expand All @@ -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"]
Expand Down
2 changes: 0 additions & 2 deletions rust-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
28 changes: 10 additions & 18 deletions rust-bindings/src/repo.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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<Repo, glib::Error> {
/// Open using the target directory file descriptor.
#[cfg(any(feature = "v2017_10", feature = "dox"))]
pub fn open_at_dir(dir: BorrowedFd<'_>, path: &str) -> Result<Repo, glib::Error> {
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>,
Expand Down Expand Up @@ -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<cap_std::fs::Dir> {
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.
Expand Down
14 changes: 11 additions & 3 deletions rust-bindings/tests/repo/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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());

Expand All @@ -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");
Expand Down
11 changes: 8 additions & 3 deletions rust-bindings/tests/util/mod.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -28,21 +32,22 @@ 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)
}

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 }
}
}
Expand Down
Loading