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

rake compile does not build with the "debug" profile #471

Open
nick96 opened this issue Dec 27, 2024 · 4 comments
Open

rake compile does not build with the "debug" profile #471

nick96 opened this issue Dec 27, 2024 · 4 comments

Comments

@nick96
Copy link

nick96 commented Dec 27, 2024

I've been really enjoying using this rb-sys alongside magnus to write an extension in Rust, thank you!

When developing, I want to build my extension using the "debug" profile for faster compilation times. I tried this from the docs:

create_rust_makefile("rust_reverse") do |r|
  r.profile = ENV.fetch("RB_SYS_CARGO_PROFILE", :dev).to_sym
end

However, the crate is still built in release mode. Looking at the generated Makefile, RB_SYS_CARGO_PROFILE is still always "release". From poking around in the code I think this is because RbSys::Mkmf::Config#rubygems_invoked? returns true due to SOURCE_DATE_EPOCH being set. I'm not 100% but I guess this is being set by rake. I'm using RbSys::ExtensionTask and doing the compilation by rake compile.

@ianks
Copy link
Collaborator

ianks commented Dec 27, 2024

Hmmm interesting, SOURCE_DATE_EPOCH being set must be new. Previously, that was the only way to detect if it's rubygems compiling the gem, in which case we don't want to risk accidentally compiling in dev mode.

Does rake compile:dev work?

@nick96
Copy link
Author

nick96 commented Dec 28, 2024

No, I get the same issue. I'll try to put together an MWE to share

@nick96
Copy link
Author

nick96 commented Dec 28, 2024

Ah, actually, I can repro this is oxi-test:

$ rake compile:dev
...
generating /Users/nds/Source/oxi-test/target/release/liboxi_test.dylib (release)
cargo rustc  --manifest-path /Users/nds/Source/oxi-test/ext/Cargo.toml --target-dir /Users/nds/Source/oxi-test/target --lib --profile release -- -C linker=clang -L native=/nix/store/sz5lwn6zcmsbg1wyi2vqm6mc4s877wbp-ruby-3.3.6/lib -C link-arg=-Wl,-multiply_defined,suppress -C link-arg=-Wl,-undefined,dynamic_lookup -l pthread
...

With this diff rake compile:dev works as expected (though I don't think this is a solution 😁):

diff --git a/Rakefile b/Rakefile
index da6fd4a..6d6c2c2 100644
--- a/Rakefile
+++ b/Rakefile
@@ -7,6 +7,7 @@ require "minitest/test_task"
 GEMSPEC = Gem::Specification.load('oxi-test.gemspec') || abort('Could not load oxi-test.gemspec')
 
 RbSys::ExtensionTask.new('oxi-test', GEMSPEC) do |ext|
+  ENV.delete('SOURCE_DATE_EPOCH')
   ext.lib_dir = 'lib/oxi/test'
 end

@ianks
Copy link
Collaborator

ianks commented Dec 28, 2024

What's your gem env?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants