From 526cc8d389233a344b332bccd552a645824874e6 Mon Sep 17 00:00:00 2001 From: "Richard J. Safier" Date: Fri, 7 Aug 2026 10:16:24 -0400 Subject: [PATCH 1/2] fix(store): gate io-uring dependency and leftovers to Linux io_uring call sites were already #[cfg(target_os = "linux")]-gated with darwin fallbacks, but the crate dependency was unconditional so cargo compiled the Linux-only io-uring crate on macOS and failed. Move it to a target-gated dependency and cfg-gate the remaining Linux-only items (RING_ENTRIES, Path import, dontcache fields) that -Dwarnings flags as dead code on darwin. Cargo.lock is unchanged. --- crates/rbitcoin-store/Cargo.toml | 7 +++++-- crates/rbitcoin-store/src/bulk_io.rs | 5 +++++ crates/rbitcoin-store/src/uring_session.rs | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/rbitcoin-store/Cargo.toml b/crates/rbitcoin-store/Cargo.toml index 22dd2e6..bbe9ea0 100644 --- a/crates/rbitcoin-store/Cargo.toml +++ b/crates/rbitcoin-store/Cargo.toml @@ -14,8 +14,6 @@ rbitcoin-log = { workspace = true } bitcoin_hashes = { workspace = true } # fallocate / punch-hole for multi‑GiB grows without zero-fill storms (Linux). libc = "0.2" -# Bulk pread submission for head-resolve / confirm body load (Linux). -io-uring = "0.7" # Datadir store.secret CSPRNG. getrandom = "0.2" # Sealed segment binary fuse8 (~9 bits/key). @@ -24,6 +22,11 @@ bincode = { workspace = true } # Product bin only (store_bench); library tests keep the platform allocator. mimalloc = { workspace = true } +# Bulk pread submission for head-resolve / confirm body load. Linux-only crate; +# all uses in src are #[cfg(target_os = "linux")]-gated with darwin fallbacks. +[target.'cfg(target_os = "linux")'.dependencies] +io-uring = "0.7" + [[bin]] name = "rbitcoin-store-bench" path = "src/bin/store_bench.rs" diff --git a/crates/rbitcoin-store/src/bulk_io.rs b/crates/rbitcoin-store/src/bulk_io.rs index 1981227..0f41032 100644 --- a/crates/rbitcoin-store/src/bulk_io.rs +++ b/crates/rbitcoin-store/src/bulk_io.rs @@ -33,6 +33,7 @@ use std::os::fd::RawFd; use std::sync::atomic::{AtomicBool, AtomicU8, AtomicUsize, Ordering}; /// SQ/CQ depth for bulk batch sessions. +#[cfg(target_os = "linux")] const RING_ENTRIES: u32 = crate::uring_session::DEFAULT_ENTRIES; /// One independent pread. Caller owns `buf` for the full submit/wait. @@ -43,6 +44,8 @@ pub struct ReadOp<'a> { /// Filled: bytes read (≥0) or negated errno on failure. pub result: i32, /// When true, SQE uses [`crate::uring_session::RWF_DONTCACHE`]. + // Only read on the Linux io_uring submit path. + #[cfg_attr(not(target_os = "linux"), allow(dead_code))] pub dontcache: bool, } @@ -54,6 +57,8 @@ pub struct WriteOp<'a> { /// Filled: bytes written (≥0) or negated errno on failure. pub result: i32, /// When true, SQE uses [`crate::uring_session::RWF_DONTCACHE`]. + // Only read on the Linux io_uring submit path. + #[cfg_attr(not(target_os = "linux"), allow(dead_code))] pub dontcache: bool, } diff --git a/crates/rbitcoin-store/src/uring_session.rs b/crates/rbitcoin-store/src/uring_session.rs index 719effc..a72facb 100644 --- a/crates/rbitcoin-store/src/uring_session.rs +++ b/crates/rbitcoin-store/src/uring_session.rs @@ -15,6 +15,7 @@ use crate::error::StoreError; use std::os::fd::RawFd; +#[cfg(target_os = "linux")] use std::path::Path; /// Default SQ/CQ depth for all store io_uring sessions (bulk, plan head-resolve, From 15ec3c2e34f04bc840638df16edcd25172ebb59d Mon Sep 17 00:00:00 2001 From: "Richard J. Safier" Date: Fri, 7 Aug 2026 10:16:28 -0400 Subject: [PATCH 2/2] feat(nix): darwin systems in flake; native build as macOS default Add x86_64-darwin/aarch64-darwin to the flake systems so 'nix build' works on Macs. The static musl package stays the default on Linux; darwin defaults to a native stdenv build (musl is Linux-only). Widen meta.platforms accordingly and point checks at the per-system default. --- flake.nix | 29 ++++++++++++++++++----------- nix/rbitcoin.nix | 2 +- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/flake.nix b/flake.nix index 94b8eea..4443dbc 100644 --- a/flake.nix +++ b/flake.nix @@ -15,6 +15,8 @@ systems = [ "x86_64-linux" "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" ]; forAllSystems = nixpkgs.lib.genAttrs systems; @@ -34,19 +36,23 @@ config = { }; overlays = [ ]; }; - # Optional dynamic glibc package (Nix-store linked; not portable off-store). - rbitcoin-glibc = mkRbitcoin pkgs; - # Primary / default: fully static musl — portable operator binary. - rbitcoin-musl = mkRbitcoin pkgs.pkgsStatic; + isLinux = nixpkgs.lib.hasSuffix "-linux" system; + # Native build (Nix-store linked): glibc on Linux, plain darwin stdenv on macOS. + rbitcoin-native = mkRbitcoin pkgs; + # Primary / default on Linux: fully static musl — portable operator binary. + # musl is Linux-only, so darwin defaults to the native build instead. + rbitcoin-default = if isLinux then mkRbitcoin pkgs.pkgsStatic else rbitcoin-native; in { - default = rbitcoin-musl; - rbitcoin = rbitcoin-musl; - rbitcoin-node = rbitcoin-musl; - rbitcoin-cli = rbitcoin-musl; - rbitcoin-musl = rbitcoin-musl; + default = rbitcoin-default; + rbitcoin = rbitcoin-default; + rbitcoin-node = rbitcoin-default; + rbitcoin-cli = rbitcoin-default; + } + // nixpkgs.lib.optionalAttrs isLinux { + rbitcoin-musl = rbitcoin-default; # Kept for store-native Nix environments / optional dual-platform repro. - rbitcoin-glibc = rbitcoin-glibc; + rbitcoin-glibc = rbitcoin-native; } // nixpkgs.lib.optionalAttrs (system == "x86_64-linux") { # Optional third platform: aarch64-linux cross from x86_64 (heavy toolchain). @@ -103,7 +109,8 @@ checks = forAllSystems ( system: { - rbitcoin = self.packages.${system}.rbitcoin-musl; + # musl on Linux, native on darwin — matches the default package. + rbitcoin = self.packages.${system}.default; } ); }; diff --git a/nix/rbitcoin.nix b/nix/rbitcoin.nix index 97bef46..ea8b1ce 100644 --- a/nix/rbitcoin.nix +++ b/nix/rbitcoin.nix @@ -114,7 +114,7 @@ let asl20 ]; mainProgram = "rbitcoin-node"; - platforms = platforms.linux; + platforms = platforms.linux ++ platforms.darwin; }; } );