Skip to content

Commit

Permalink
extconf: respect AR and RANLIB in recipes on darwin (#3338)
Browse files Browse the repository at this point in the history
**What problem is this PR intended to solve?**

When using Nix on Darwin, we ideally should be latching onto the
Nix-provided AR and RANLIB. Without this, when blocking Xcode via
`sandbox-exec`, I see errors like this while attempting to install the
gem, since we end up using the default `ar` and `runlib`

```
xcode-select: note: No developer tools were found, requesting install.
If developer tools are located at a non-default location on disk, use `sudo xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools, and cancel the installation dialog.
See `man xcode-select` for more details.
```


**Have you included adequate test coverage?**

Yes

**Does this change affect the behavior of either the C or the Java
implementations?**

No
  • Loading branch information
joshheinrichs-shopify authored Nov 28, 2024
1 parent 7ec98d4 commit 6af2385
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
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?
!(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

0 comments on commit 6af2385

Please sign in to comment.