rake-compiler / rake-compiler-dock

Easy to use and reliable cross compiler environment for building Windows, Linux, Mac and JRuby binary gems.
MIT License
77 stars 30 forks source link

Cannot use RUBY_CC_VERSION #73

Closed stackmystack closed 2 years ago

stackmystack commented 2 years ago

Hello,

I am not able to work with RUBY_CC_VERSION at all. Here's the branch I am working on: https://github.com/stackmystack/grenadier/tree/compile/include-tree-sitter.

When I run the following:

docker run --rm -v "$(pwd):/precompiled:Z" -w /precompiled larskanis/rake-compiler-dock-mri-aarch64-linux:1.2.2 /bin/bash -c "gem update --system --no-document && bundle && bundle exec rake native:aarch64-linux gem"

The compilation works, and goes through the list of RUBY_CC_VERSION predefined in the dockerfile.

However, my project only supports RUBY_VERSION >= 2.7, and I can't seem to be able to pass a custom RUBY_CC_VERSION to the docker image. I tried the following:

  1. Passing env var through docker:
docker run --rm -v "$(pwd):/precompiled:Z" -w /precompiled -e RUBY_CC_VERSION='3.1' larskanis/rake-compiler-dock-mri-aarch64-linux:1.2.2 /bin/bash -c "gem update --system --no-document && bundle && bundle exec rake native:aarch64-linux gem"
  1. Prepending env var in the command itself
docker run --rm -v "$(pwd):/precompiled:Z" -w /precompiled larskanis/rake-compiler-dock-mri-aarch64-linux:1.2.2 /bin/bash -c "RUBY_CC_VERSION=3.0; gem update --system --no-document && bundle && bundle exec rake native:aarch64-linux gem"
  1. Appending the env var to the rake command
docker run --rm -v "$(pwd):/precompiled:Z" -w /precompiled larskanis/rake-compiler-dock-mri-aarch64-linux:1.2.2 /bin/bash -c "gem update --system --no-document && bundle && bundle exec rake native:aarch64-linux gem RUBY_CC_VERSION=3.0"

And in all those cases, I get:

rake aborted!
Don't know how to build task 'native:aarch64-linux' (See the list of available tasks with `rake --tasks`)
Did you mean?  gem:aarch64-linux

Which is obviously not the correct rake task (I defined the gem:<arch> tasks for ease of testing.

Any help would be appreciated.

flavorjones commented 2 years ago

Hi! Sorry you're having problems, I'll try to help.

If you know what Ruby versions your code is supposed to support, my advice is to set it in your Rakefile, similar to what's being done in https://github.com/flavorjones/ruby-c-extensions-explained/blob/main/precompiled/Rakefile#L20

Worth noting, this repository is intended to be used primarily via the rake-compiler-dock commandline tool, which sets up user permissions, sudoer permissions, etc. While I'd be happy to dig into what specifically isn't working for you, it may be simpler and easier to set the environment variable directly as I described above.

stackmystack commented 2 years ago

Thank you. Compilation now works following the same Rakefile layout in the example.

It doesn't work by setting the env var in extconf.rb though.