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

extconf: respect AR and RANLIB in recipes on darwin #3338

Merged
merged 3 commits into from
Nov 28, 2024
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
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,36 @@ jobs:
- run: bundle exec rake compile -- --${{matrix.sys}}-system-libraries
- run: bundle exec rake test

darwin-nix:
needs: ["basic"]
strategy:
fail-fast: false
matrix:
sys: ["enable", "disable"]
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: cachix/install-nix-action@v30
with:
nix_path: nixpkgs=channel:nixos-24.11
- run: nix-shell --packages ruby bundler --run 'bundle install'
- if: matrix.sys == 'disable'
run: nix-shell --packages ruby bundler --run 'bundle exec rake compile -- --disable-system-libraries --disable-xml2-legacy'
- if: matrix.sys == 'disable'
run: nix-shell --packages ruby bundler --run 'bundle exec rake test'
# libxml2 headers are in a subdirectory for some reason so we need to add it to NIX_CFLAGS_COMPILE manually.
# there are a bunch of examples of other packages doing this in nixpkgs so this seems to be expected.
- if: matrix.sys == 'enable'
run: |
nix-shell \
--expr 'with import <nixpkgs> {}; mkShell { buildInputs = [ ruby bundler libxml2 libxslt ]; env.NIX_CFLAGS_COMPILE = "-I ${libxml2.dev}/include/libxml2"; }' \
--run 'bundle exec rake compile -- --enable-system-libraries --disable-xml2-legacy'
- if: matrix.sys == 'enable'
run: |
nix-shell --packages ruby bundler libxml2 libxslt --run 'bundle exec rake test'

windows:
needs: ["basic"]
strategy:
Expand Down
16 changes: 11 additions & 5 deletions ext/nokogiri/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,14 @@ def aix?
RbConfig::CONFIG["target_os"].include?("aix")
end

def nix?
def unix?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL, naming things is hard

!(windows? || solaris? || darwin?)
end

def nix?
ENV.key?("NIX_CC")
end

def truffle?
RUBY_ENGINE == "truffleruby"
end
Expand Down Expand Up @@ -705,7 +709,7 @@ def needs_darwin_linker_hack

# Add SDK-specific include path for macOS and brew versions before v2.2.12 (2020-04-08) [#1851, #1801]
macos_mojave_sdk_include_path = "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2"
if config_system_libraries? && darwin? && Dir.exist?(macos_mojave_sdk_include_path)
if config_system_libraries? && darwin? && Dir.exist?(macos_mojave_sdk_include_path) && !nix?
append_cppflags("-I#{macos_mojave_sdk_include_path}")
end

Expand Down Expand Up @@ -828,7 +832,7 @@ def configure
end
end

unless nix?
unless unix?
libiconv_recipe = process_recipe(
"libiconv",
dependencies["libiconv"]["version"],
Expand Down Expand Up @@ -928,7 +932,8 @@ def configure
end

if darwin? && !cross_build_p
recipe.configure_options += ["RANLIB=/usr/bin/ranlib", "AR=/usr/bin/ar"]
recipe.configure_options << "RANLIB=/usr/bin/ranlib" unless ENV.key?("RANLIB")
recipe.configure_options << "AR=/usr/bin/ar" unless ENV.key?("AR")
end

if windows?
Expand Down Expand Up @@ -969,7 +974,8 @@ def configure
cflags = concat_flags(ENV["CFLAGS"], "-O2", "-U_FORTIFY_SOURCE", "-g")

if darwin? && !cross_build_p
recipe.configure_options += ["RANLIB=/usr/bin/ranlib", "AR=/usr/bin/ar"]
recipe.configure_options << "RANLIB=/usr/bin/ranlib" unless ENV.key?("RANLIB")
recipe.configure_options << "AR=/usr/bin/ar" unless ENV.key?("AR")
end

if windows?
Expand Down