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

Building requires Xcode Command Line Tools to be selected #2287

Open
hisaac opened this issue Oct 27, 2023 · 6 comments
Open

Building requires Xcode Command Line Tools to be selected #2287

hisaac opened this issue Oct 27, 2023 · 6 comments
Labels

Comments

@hisaac
Copy link

hisaac commented Oct 27, 2023

Ever since updating to macOS Sonoma, I've been unable to build Ruby using ruby-build as normal. After much troubleshooting, I determined that I needed to explicitly select the Xcode Command Line Tools as the active developer directory prior to running the command, it doesn't seem to work if a copy of Xcode is selected.

(I also have to explicitly point to the homebrew-installed version of openssl, but I believe this is likely a separate issue.)

Here are some various permutations I've tested with the same or similar results:

  • macOS: versions 14.0 and 14.1
  • Xcode.app: versions 14.3.1, 15.0, and 15.0.1
  • ruby-build: versions 20230919, 20231012, 20231014, 20231025 (every version since macOS Sonoma's release on September 26)

Steps to reproduce the behavior

  1. Select a version of Xcode as the active developer directory using xcode-select
    sudo xcode-select -s /Applications/Xcode-15.0.1.app/Contents/Developer/
  2. Attempt to install Ruby as normal
    RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@3)" ruby-build 3.2.2 ~/local/ruby-3.2.2
  3. Note the build failed (see logs below for more details)
  4. Now select the Xcode Command Line Tools as the active developer directory
    sudo xcode-select -s /Library/Developer/CommandLineTools
  5. Attempt to install Ruby once again using the same command as in step #​2.
  6. Note the build succeeds (see logs below for more details)

Expected vs. actual behavior

  • Expected: I am able to successfully install Ruby on my computer running macOS Sonoma, regardless of if Xcode or the Xcode Command Line Tools are selected as the active developer directory.
  • Actual: I am unable to successfully install Ruby on my computer running macOS Sonoma if a copy of Xcode.app is selected as the active developer directory. I must explicitly select the Xcode Command Line Tools as the active developer directory in order to successfully install Ruby.

Logs

I got an error when I tried to include the verbose logs pasted here into this Issue, so I'll attach them here as txt files instead:

Failing Build

These are the logs from a failing build, after selecting /Applications/Xcode-15.0.1.app/Contents/Developer/ as the active developer directory:

❯ RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@3)" ruby-build 3.2.2 ~/local/ruby-3.2.2
To follow progress, use 'tail -f /var/folders/vk/39v82gb50yjbxxj_j5gtzkknf8d7d0/T/ruby-build.20231027132223.49795.log' or pass --verbose
Downloading ruby-3.2.2.tar.gz...
-> https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.2.tar.gz
Installing ruby-3.2.2...
ruby-build: using readline from homebrew
ruby-build: using libyaml from homebrew
ruby-build: using gmp from homebrew

BUILD FAILED (macOS 14.1 using ruby-build 20231025)

Inspect or clean up the working tree at /var/folders/vk/39v82gb50yjbxxj_j5gtzkknf8d7d0/T/ruby-build.20231027132223.49795.6lJmlP
Results logged to /var/folders/vk/39v82gb50yjbxxj_j5gtzkknf8d7d0/T/ruby-build.20231027132223.49795.log

Last 10 log lines:
In file included from ./fiddle.h:46:
/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/ffi/ffi.h:483:5: warning: 'FFI_GO_CLOSURES' is not defined, evaluates to 0 [-Wundef]
#if FFI_GO_CLOSURES
    ^
ld: warning: ignoring duplicate libraries: '-lruby.3.2'
installing default fiddle libraries
1 warning generated.
linking shared-object fiddle.bundle
ld: warning: ignoring duplicate libraries: '-lffi', '-lruby.3.2'
make: *** [build-ext] Error 2

Successful Build

These are the logs from a successful build, after selecting /Library/Developer/CommandLineTools as the active developer directory:

❯ RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@3)" ruby-build 3.2.2 ~/local/ruby-3.2.2
To follow progress, use 'tail -f /var/folders/vk/39v82gb50yjbxxj_j5gtzkknf8d7d0/T/ruby-build.20231027131830.14178.log' or pass --verbose
Downloading ruby-3.2.2.tar.gz...
-> https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.2.tar.gz
Installing ruby-3.2.2...
ruby-build: using readline from homebrew
ruby-build: using libyaml from homebrew
ruby-build: using gmp from homebrew
Installed ruby-3.2.2 to /Users/ihalvorson/local/ruby-3.2.2
@hisaac hisaac added the bug label Oct 27, 2023
@monfresh
Copy link

I am unable to reproduce this issue with ruby-build 20231025 and the following combinations on macOS Sonoma on an M1 Mini:

  • Xcode 15.0 and CLT 15.0 on macOS 14.0
  • Xcode 15.0.1 and CLT 15.0 on macOS 14.1

Also, the minimum Xcode/CLT version you can use on Sonoma is 15.0, so I think it was a mistake when you included 14.3.1 in the list.

Have you tried opening a new terminal tab after switching to Xcode, and what does brew doctor say after you do that? Also, what is the output of brew config?

And when you updated Xcode from 15.0 to 15.0.1, did you launch Xcode and then click "Install" when prompted to choose the platforms you want to develop for?

Another thing to check is that when you launch the Xcode app and go to its Preferences, and then the Locations tab, what is listed in the Command Line Tools dropdown?

Are you setting any environment variables in your shell startup files that could affect Ruby installation? This is a common cause of failures, although I would expect this to fail with the CLT as well.

Another thing I would try is to completely uninstall all Xcode apps and reinstall just 15.0.1, then launch it, and click Install when prompted.

@mislav
Copy link
Member

mislav commented Oct 28, 2023

  1. Select a version of Xcode as the active developer directory using xcode-select
    sudo xcode-select -s /Applications/Xcode-15.0.1.app/Contents/Developer/

I have never use Xcode for anything other than having it install its Command Line Tools, and I'm wondering, what is the use-case for selecting a version of Xcode using xcode-select --switch? Do developers using Xcode run this all the time? If so and if it consistently fails in combination with ruby-build (something that is still to be determined, since I haven't seen your particular build failure before), we could potentially print a warning to macOS users that their Ruby build might have failed because they need to run sudo xcode-select --reset.

@monfresh
Copy link

Yes, certain projects that require the use of the Xcode app also require that xcode-select -p points to the Xcode app. This build failure is definitely not a 100% reproducible issue, and I don't think it's related to ruby-build. I recently had a Ruby on Mac customer whose Xcode setup was in a bad state, and running sudo xcode-select -s /Library/Developer/CommandLineTools fixed the issue. And they were on macOS Monterey. Out of 1800 customers, this was the first time this issue came up. Granted, not all of them use the Xcode app, but there's a decent amount that do.

One way to check whether or not this is specific to ruby-build is to try the same thing with a different Ruby installation tool, or compiling from source.

@hisaac
Copy link
Author

hisaac commented Oct 30, 2023

Thank you both for the detailed questions/comments/ideas!


Also, the minimum Xcode/CLT version you can use on Sonoma is 15.0, so I think it was a mistake when you included 14.3.1 in the list.

According to Apple, yes, but you can still install it and use it from the command-line. I only tried it because I was trying to figure this issue out.


Have you tried opening a new terminal tab after switching to Xcode, and what does brew doctor say after you do that? Also, what is the output of brew config?

❯ sudo xcode-select -s /Applications/Xcode-15.0.1.app/Contents/Developer/

❯ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: Some installed formulae are deprecated or disabled.
You should find replacements for the following formulae:
  [email protected]

❯ brew config
HOMEBREW_VERSION: 4.1.17-25-g93ec808
ORIGIN: https://github.com/Homebrew/brew
HEAD: 93ec808d98cf62ef8916428ac25a58b6cbf2cb2e
Last commit: 3 days ago
Core tap JSON: 27 Oct 14:26 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 10
HOMEBREW_SORBET_RUNTIME: set
Homebrew Ruby: 2.6.10 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: 10-core 64-bit arm_firestorm_icestorm
Clang: 15.0.0 build 1500
Git: 2.42.0 => /opt/homebrew/bin/git
Curl: 8.1.2 => /usr/bin/curl
macOS: 14.1-arm64
CLT: 15.0.0.0.1.1694021235
Xcode: 15.0.1 => /Applications/Xcode-15.0.1.app/Contents/Developer
Rosetta 2: false

And when you updated Xcode from 15.0 to 15.0.1, did you launch Xcode and then click "Install" when prompted to choose the platforms you want to develop for?

Yes.


Another thing to check is that when you launch the Xcode app and go to its Preferences, and then the Locations tab, what is listed in the Command Line Tools dropdown?

CleanShot 2023-10-30 at 08 53 21@2x


Are you setting any environment variables in your shell startup files that could affect Ruby installation?

Nothing sticks out to me as ruby-related in my list of env vars. 🤔 Anything specific I should look for?


Another thing I would try is to completely uninstall all Xcode apps and reinstall just 15.0.1, then launch it, and click Install when prompted.

Haven't tried this one yet, but I can soon and update on if it changed anything.


One way to check whether or not this is specific to ruby-build is to try the same thing with a different Ruby installation tool, or compiling from source.

I'd be willing to try that. I've only ever tried building with ruby-build though. Any advice on other builders to try? Or a guide on how to build from source?


One question I have: Does the error message I get about FFI_GO_CLOSURES tip you off to anything? That's what always prints out last when the install fails, but I don't know what it relates to.

/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/ffi/ffi.h:483:5: warning: 'FFI_GO_CLOSURES' is not defined, evaluates to 0 [-Wundef]
#if FFI_GO_CLOSURES
    ^

@mislav
Copy link
Member

mislav commented Nov 10, 2023

Another report of a person needing to do sudo xcode-select --reset before they could compile anything with ruby-build, although they got different error messages than in this thread: #2305

I suggest that within BUILD FAILED reports ruby-build prints a suggestion for macOS users that they could try sudo xcode-select --reset (but only if it's not already at the default location).

@hisaac
Copy link
Author

hisaac commented Nov 10, 2023

Seems reasonable to me!

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

No branches or pull requests

3 participants