From 517ed56b1e385d310da39f7c09ff570009932225 Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Mon, 1 Jul 2024 13:29:10 -0400 Subject: [PATCH 1/3] Allow missing AR/CC/etc tools for precompiled rubies --- crates/rb-sys-build/src/bindings/stable_api.rs | 1 + crates/rb-sys-build/src/cc.rs | 13 +++++++++++-- crates/rb-sys-build/src/utils.rs | 2 +- .../rb-sys-test-helpers/src/ruby_test_executor.rs | 1 + crates/rb-sys/build/main.rs | 2 +- crates/rb-sys/build/stable_api_config.rs | 2 ++ crates/rb-sys/src/tracking_allocator.rs | 1 + 7 files changed, 18 insertions(+), 4 deletions(-) diff --git a/crates/rb-sys-build/src/bindings/stable_api.rs b/crates/rb-sys-build/src/bindings/stable_api.rs index fe5afea4..56d2e948 100644 --- a/crates/rb-sys-build/src/bindings/stable_api.rs +++ b/crates/rb-sys-build/src/bindings/stable_api.rs @@ -166,6 +166,7 @@ pub fn categorize_bindings(syntax: &mut syn::File) { } /// Unstable items for usage internally in rb_sys to avoid deprecated warnings. + #[allow(dead_code)] pub (crate) mod internal { use super::uncategorized::*; diff --git a/crates/rb-sys-build/src/cc.rs b/crates/rb-sys-build/src/cc.rs index f45bdf71..c0cc59f5 100644 --- a/crates/rb-sys-build/src/cc.rs +++ b/crates/rb-sys-build/src/cc.rs @@ -52,9 +52,12 @@ impl Build { let rb = rb_config(); let object_files = self.compile_each_file(compiler, &rb, &out_dir)?; + debug_log!("INFO: compiled object files: {:?}", object_files); let (lib_path, lib_name) = self.archive_object_files(archiver.copied(), name, &out_dir, object_files)?; - self.strip_archived_objects(archiver, &lib_path)?; + if let Err(e) = self.strip_archived_objects(archiver, &lib_path) { + debug_log!("WARN: failed to strip archived objects: {:?}", e); + } println!("cargo:rustc-link-search=native={}", out_dir.display()); println!("cargo:rustc-link-lib=static={}", lib_name); @@ -270,7 +273,13 @@ fn get_tool(env_var: &str, default: &str) -> Command { let mut tool_args = shellsplit(tool_args).into_iter(); let tool = tool_args.next().unwrap_or_else(|| default.to_string()); - let mut cmd = new_command(&tool); + let mut cmd = if !Path::new(&tool).is_file() { + debug_log!("[WARN] {tool} tool not found, falling back to {default}"); + new_command(default) + } else { + new_command(&tool) + }; + cmd.args(tool_args.clone()); debug_log!("INFO: found {:?} tool ({:?})", env_var, &cmd); diff --git a/crates/rb-sys-build/src/utils.rs b/crates/rb-sys-build/src/utils.rs index a11e7a27..dc768ec7 100644 --- a/crates/rb-sys-build/src/utils.rs +++ b/crates/rb-sys-build/src/utils.rs @@ -24,7 +24,7 @@ pub fn shellsplit>(s: S) -> Vec { match shell_words::split(s) { Ok(v) => v, Err(e) => { - debug_log!("shellsplit failed: {}", e); + debug_log!("WARN: shellsplit failed: {}", e); s.split_whitespace().map(Into::into).collect() } } diff --git a/crates/rb-sys-test-helpers/src/ruby_test_executor.rs b/crates/rb-sys-test-helpers/src/ruby_test_executor.rs index ee718bb7..2c1a1fc5 100644 --- a/crates/rb-sys-test-helpers/src/ruby_test_executor.rs +++ b/crates/rb-sys-test-helpers/src/ruby_test_executor.rs @@ -121,6 +121,7 @@ impl Drop for RubyTestExecutor { } pub fn global_executor() -> &'static RubyTestExecutor { + #[allow(static_mut_refs)] unsafe { &GLOBAL_EXECUTOR }.get_or_init(RubyTestExecutor::start) } diff --git a/crates/rb-sys/build/main.rs b/crates/rb-sys/build/main.rs index 07676c54..8b6a9323 100644 --- a/crates/rb-sys/build/main.rs +++ b/crates/rb-sys/build/main.rs @@ -61,7 +61,7 @@ fn main() { export_cargo_cfg(&mut rbconfig, &mut cfg_capture_file); #[cfg(feature = "stable-api")] - stable_api_config::setup(Version::current(&rbconfig)).unwrap(); + stable_api_config::setup(Version::current(&rbconfig)).expect("could not setup stable API"); if is_link_ruby_enabled() { link_libruby(&mut rbconfig); diff --git a/crates/rb-sys/build/stable_api_config.rs b/crates/rb-sys/build/stable_api_config.rs index 3ec20d0c..91e38ae9 100644 --- a/crates/rb-sys/build/stable_api_config.rs +++ b/crates/rb-sys/build/stable_api_config.rs @@ -124,9 +124,11 @@ fn maybe_warn_old_ruby_version(current_ruby_version: Version) { } fn compile() -> Result<(), Box> { + eprintln!("INFO: Compiling the stable API compiled module"); let mut build = rb_sys_build::cc::Build::new(); let crate_dir = Path::new(env!("CARGO_MANIFEST_DIR")); let path = crate_dir.join("src").join("stable_api").join("compiled.c"); + eprintln!("cargo:rerun-if-changed={}", path.display()); build.file(path); build.try_compile("compiled") diff --git a/crates/rb-sys/src/tracking_allocator.rs b/crates/rb-sys/src/tracking_allocator.rs index 4f47eeb3..37f905f2 100644 --- a/crates/rb-sys/src/tracking_allocator.rs +++ b/crates/rb-sys/src/tracking_allocator.rs @@ -18,6 +18,7 @@ pub struct TrackingAllocator; impl TrackingAllocator { /// Create a new [`TrackingAllocator`]. + #[allow(clippy::new_without_default)] pub const fn new() -> Self { Self } From 18099f0fb6bc289b6ab227f63bf162dec677e57f Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Mon, 1 Jul 2024 14:11:38 -0400 Subject: [PATCH 2/3] Drop 2.5 support --- .github/workflows/ci.yml | 2 +- data/toolchains.json | 4 ++-- docker/Dockerfile.aarch64-linux | 3 ++- docker/Dockerfile.aarch64-linux-musl | 3 ++- docker/Dockerfile.arm-linux | 3 ++- docker/Dockerfile.arm64-darwin | 3 ++- docker/Dockerfile.x64-mingw-ucrt | 3 ++- docker/Dockerfile.x64-mingw32 | 3 ++- docker/Dockerfile.x86-linux | 3 ++- docker/Dockerfile.x86-mingw32 | 3 ++- docker/Dockerfile.x86_64-darwin | 3 ++- docker/Dockerfile.x86_64-linux | 3 ++- docker/Dockerfile.x86_64-linux-musl | 3 ++- 13 files changed, 25 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c66db56d..2eb7aaac 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,7 @@ jobs: fail-fast: false matrix: # Test against all versions supported by rubygems - ruby_version: ["2.5", "2.6", "2.7", "3.0", "3.1", "3.2", "3.3"] + ruby_version: ["2.6", "2.7", "3.0", "3.1", "3.2", "3.3"] sys: - os: ubuntu-latest rust_toolchain: ${{ needs.fetch_ci_data.outputs.minimum-supported-rust-version }} diff --git a/data/toolchains.json b/data/toolchains.json index 51048801..86cd8c29 100644 --- a/data/toolchains.json +++ b/data/toolchains.json @@ -1,6 +1,6 @@ { "policy": { - "minimum-supported-ruby-version": "2.5", + "minimum-supported-ruby-version": "2.6", "minimum-supported-rust-version": "1.63" }, "toolchains": [ @@ -115,4 +115,4 @@ "supported": true } ] -} +} \ No newline at end of file diff --git a/docker/Dockerfile.aarch64-linux b/docker/Dockerfile.aarch64-linux index 53880034..4150db06 100644 --- a/docker/Dockerfile.aarch64-linux +++ b/docker/Dockerfile.aarch64-linux @@ -1,6 +1,7 @@ FROM ghcr.io/rake-compiler/rake-compiler-dock-image:1.5.0-mri-aarch64-linux -ENV RUBY_TARGET="aarch64-linux" \ +ENV RUBY_CC_VERSION="3.3.0:3.2.0:3.1.0:3.0.0:2.7.0:2.6.0" \ + RUBY_TARGET="aarch64-linux" \ RUST_TARGET="aarch64-unknown-linux-gnu" \ RUSTUP_DEFAULT_TOOLCHAIN="stable" \ PKG_CONFIG_ALLOW_CROSS="1" \ diff --git a/docker/Dockerfile.aarch64-linux-musl b/docker/Dockerfile.aarch64-linux-musl index 9fd53d37..012e4ba0 100644 --- a/docker/Dockerfile.aarch64-linux-musl +++ b/docker/Dockerfile.aarch64-linux-musl @@ -1,6 +1,7 @@ FROM ghcr.io/rake-compiler/rake-compiler-dock-image:1.5.0-mri-aarch64-linux-musl -ENV RUBY_TARGET="aarch64-linux-musl" \ +ENV RUBY_CC_VERSION="3.3.0:3.2.0:3.1.0:3.0.0:2.7.0:2.6.0" \ + RUBY_TARGET="aarch64-linux-musl" \ RUST_TARGET="aarch64-unknown-linux-musl" \ RUSTUP_DEFAULT_TOOLCHAIN="stable" \ RUSTUP_HOME="/usr/local/rustup" \ diff --git a/docker/Dockerfile.arm-linux b/docker/Dockerfile.arm-linux index 6a0cf163..30cef1f6 100644 --- a/docker/Dockerfile.arm-linux +++ b/docker/Dockerfile.arm-linux @@ -1,6 +1,7 @@ FROM ghcr.io/rake-compiler/rake-compiler-dock-image:1.5.0-mri-arm-linux -ENV RUBY_TARGET="arm-linux" \ +ENV RUBY_CC_VERSION="3.3.0:3.2.0:3.1.0:3.0.0:2.7.0:2.6.0" \ + RUBY_TARGET="arm-linux" \ RUST_TARGET="arm-unknown-linux-gnueabihf" \ RUSTUP_DEFAULT_TOOLCHAIN="stable" \ PKG_CONFIG_ALLOW_CROSS="1" \ diff --git a/docker/Dockerfile.arm64-darwin b/docker/Dockerfile.arm64-darwin index 2d3056f7..1ea57353 100644 --- a/docker/Dockerfile.arm64-darwin +++ b/docker/Dockerfile.arm64-darwin @@ -1,6 +1,7 @@ FROM ghcr.io/rake-compiler/rake-compiler-dock-image:1.5.0-mri-arm64-darwin -ENV RUBY_TARGET="arm64-darwin" \ +ENV RUBY_CC_VERSION="3.3.0:3.2.0:3.1.0:3.0.0:2.7.0:2.6.0" \ + RUBY_TARGET="arm64-darwin" \ RUST_TARGET="aarch64-apple-darwin" \ RUSTUP_DEFAULT_TOOLCHAIN="stable" \ PKG_CONFIG_ALLOW_CROSS="1" \ diff --git a/docker/Dockerfile.x64-mingw-ucrt b/docker/Dockerfile.x64-mingw-ucrt index 4457ac1c..f6836495 100644 --- a/docker/Dockerfile.x64-mingw-ucrt +++ b/docker/Dockerfile.x64-mingw-ucrt @@ -1,6 +1,7 @@ FROM ghcr.io/rake-compiler/rake-compiler-dock-image:1.5.0-mri-x64-mingw-ucrt -ENV RUBY_TARGET="x64-mingw-ucrt" \ +ENV RUBY_CC_VERSION="3.3.0:3.2.0:3.1.0:3.0.0:2.7.0:2.6.0" \ + RUBY_TARGET="x64-mingw-ucrt" \ RUST_TARGET="x86_64-pc-windows-gnu" \ RUSTUP_DEFAULT_TOOLCHAIN="stable" \ PKG_CONFIG_ALLOW_CROSS="1" \ diff --git a/docker/Dockerfile.x64-mingw32 b/docker/Dockerfile.x64-mingw32 index a561b5a3..ae38178d 100644 --- a/docker/Dockerfile.x64-mingw32 +++ b/docker/Dockerfile.x64-mingw32 @@ -1,6 +1,7 @@ FROM ghcr.io/rake-compiler/rake-compiler-dock-image:1.5.0-mri-x64-mingw32 -ENV RUBY_TARGET="x64-mingw32" \ +ENV RUBY_CC_VERSION="3.3.0:3.2.0:3.1.0:3.0.0:2.7.0:2.6.0" \ + RUBY_TARGET="x64-mingw32" \ RUST_TARGET="x86_64-pc-windows-gnu" \ RUSTUP_DEFAULT_TOOLCHAIN="stable" \ PKG_CONFIG_ALLOW_CROSS="1" \ diff --git a/docker/Dockerfile.x86-linux b/docker/Dockerfile.x86-linux index 0eb077b4..be4a2721 100644 --- a/docker/Dockerfile.x86-linux +++ b/docker/Dockerfile.x86-linux @@ -1,6 +1,7 @@ FROM ghcr.io/rake-compiler/rake-compiler-dock-image:1.5.0-mri-x86-linux -ENV RUBY_TARGET="x86-linux" \ +ENV RUBY_CC_VERSION="3.3.0:3.2.0:3.1.0:3.0.0:2.7.0:2.6.0" \ + RUBY_TARGET="x86-linux" \ RUST_TARGET="i686-unknown-linux-gnu" \ RUSTUP_DEFAULT_TOOLCHAIN="stable" \ PKG_CONFIG_ALLOW_CROSS="1" \ diff --git a/docker/Dockerfile.x86-mingw32 b/docker/Dockerfile.x86-mingw32 index fb45e351..7b111c14 100644 --- a/docker/Dockerfile.x86-mingw32 +++ b/docker/Dockerfile.x86-mingw32 @@ -4,7 +4,8 @@ ARG LLVM_MINGW_VERSION=20231128 \ LLVM_MINGW_SHA256=2d532648bfd202bfe5edfa8b7f6c55970f65639779f34115a9a8bfa6f7d87f0b \ LLVM_MINGW_LIBCLANG_VERSION=14.0.0 -ENV RUBY_TARGET="x86-mingw32" \ +ENV RUBY_CC_VERSION="3.3.0:3.2.0:3.1.0:3.0.0:2.7.0:2.6.0" \ + RUBY_TARGET="x86-mingw32" \ RUST_TARGET="i686-pc-windows-gnu" \ RUSTUP_DEFAULT_TOOLCHAIN="stable" \ PKG_CONFIG_ALLOW_CROSS="1" \ diff --git a/docker/Dockerfile.x86_64-darwin b/docker/Dockerfile.x86_64-darwin index 6509daaa..0df8218f 100644 --- a/docker/Dockerfile.x86_64-darwin +++ b/docker/Dockerfile.x86_64-darwin @@ -1,6 +1,7 @@ FROM ghcr.io/rake-compiler/rake-compiler-dock-image:1.5.0-mri-x86_64-darwin -ENV RUBY_TARGET="x86_64-darwin" \ +ENV RUBY_CC_VERSION="3.3.0:3.2.0:3.1.0:3.0.0:2.7.0:2.6.0" \ + RUBY_TARGET="x86_64-darwin" \ RUST_TARGET="x86_64-apple-darwin" \ RUSTUP_DEFAULT_TOOLCHAIN="stable" \ PKG_CONFIG_ALLOW_CROSS="1" \ diff --git a/docker/Dockerfile.x86_64-linux b/docker/Dockerfile.x86_64-linux index 818b9113..218f1664 100644 --- a/docker/Dockerfile.x86_64-linux +++ b/docker/Dockerfile.x86_64-linux @@ -1,6 +1,7 @@ FROM ghcr.io/rake-compiler/rake-compiler-dock-image:1.5.0-mri-x86_64-linux -ENV RUBY_TARGET="x86_64-linux" \ +ENV RUBY_CC_VERSION="3.3.0:3.2.0:3.1.0:3.0.0:2.7.0:2.6.0" \ + RUBY_TARGET="x86_64-linux" \ RUST_TARGET="x86_64-unknown-linux-gnu" \ RUSTUP_DEFAULT_TOOLCHAIN="stable" \ PKG_CONFIG_ALLOW_CROSS="1" \ diff --git a/docker/Dockerfile.x86_64-linux-musl b/docker/Dockerfile.x86_64-linux-musl index af3c6886..f0305e73 100644 --- a/docker/Dockerfile.x86_64-linux-musl +++ b/docker/Dockerfile.x86_64-linux-musl @@ -1,6 +1,7 @@ FROM ghcr.io/rake-compiler/rake-compiler-dock-image:1.5.0-mri-x86_64-linux-musl -ENV RUBY_TARGET="x86_64-linux-musl" \ +ENV RUBY_CC_VERSION="3.3.0:3.2.0:3.1.0:3.0.0:2.7.0:2.6.0" \ + RUBY_TARGET="x86_64-linux-musl" \ RUST_TARGET="x86_64-unknown-linux-musl" \ RUSTUP_DEFAULT_TOOLCHAIN="stable" \ RUSTUP_HOME="/usr/local/rustup" \ From 49ef7288a6b2e3bc9f34249a6e3cba737cc3811f Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Mon, 1 Jul 2024 14:15:05 -0400 Subject: [PATCH 3/3] Remove negation in conditional --- crates/rb-sys-build/src/cc.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/rb-sys-build/src/cc.rs b/crates/rb-sys-build/src/cc.rs index c0cc59f5..d2e95d9b 100644 --- a/crates/rb-sys-build/src/cc.rs +++ b/crates/rb-sys-build/src/cc.rs @@ -273,11 +273,11 @@ fn get_tool(env_var: &str, default: &str) -> Command { let mut tool_args = shellsplit(tool_args).into_iter(); let tool = tool_args.next().unwrap_or_else(|| default.to_string()); - let mut cmd = if !Path::new(&tool).is_file() { + let mut cmd = if Path::new(&tool).is_file() { + new_command(&tool) + } else { debug_log!("[WARN] {tool} tool not found, falling back to {default}"); new_command(default) - } else { - new_command(&tool) }; cmd.args(tool_args.clone());