alire icon indicating copy to clipboard operation
alire copied to clipboard

Detect bad macOS setups from Alire

Open Fabien-Chouteau opened this issue 2 years ago • 7 comments

There was multiple reports of issues because of setup on macOS like not having xcode command tools installed.

I am not sure what Alire can do here, maybe detect missing tools an issue a warning.

Help is required here as none of the Alire developers are familiar with macOS environment.

Fabien-Chouteau avatar Mar 01 '22 16:03 Fabien-Chouteau

The problem was/is that the compilers available via Alire are built against the CommandLineTools - they’re configured with

  --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

The compilers I’ve built (like the ones AdaCore used to produce for macOS) are built against Xcode, configured with

SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk

(I could have said SDKROOT=$(xcrun --show-sdk-path)) and then

  --with-build-sysroot="$SDKROOT"                       \
  --with-sysroot=                                       \
  --with-specs="%{!sysroot=*:--sysroot=$SDKROOT}"       \

(copied from AdaCore work) because, I think, at the time you couldn’t get the CommandLineTools without getting Xcode first, so why not just go with Xcode even if it adds 30 Gb to your system.

Anyway, I can’t properly test this because I don’t want to mess with my working machine, but I believe the position is

  • if you don’t have either Xcode or the CommandLineTools installed, you can probably say sudo xcode-select --install for just the CommandLineTools
    • if that didn’t work, install Xcode first from the App Store, and then ...
  • if you already have Xcode installed, use the same command to install the CommandLineTools as well.

simonjwright avatar Mar 01 '22 22:03 simonjwright

You can tell if the CommandLineTools are present by checking for /Library/Developer/CommandLineTools.

simonjwright avatar Mar 01 '22 22:03 simonjwright

I use macOS 10.15 and can write and test minor contributions. I have played around with macOS detection (sw_vers) and brew.

jquorning avatar Mar 18 '22 12:03 jquorning

Hi @Fabien-Chouteau

Not sure what information you are after, and what macOS hardware platform you are asking about?

As you may know, Apple is currently moving their computer hardware from Intel processors to their own aarch64 Apple Silicon processors, currently based on the Apple Silicon M1 family. Only one hardware model in the Apple computer range has not completed the move yet - so the majority of new Apple computers sold are now all Apple Silicon based models.

If this issue is for improving support for using macOS with Intel processors, then getting Ada installed and working should be ok. Ada development (compiler and tools) can run natively for Intel under macOS, but would require Rosetta translation to run on the Apple Silicon. Ideally native support would be great, but is still work in progress I believe, and has been for several years. I note that @simonjwright commented on Reddit recently that gcc12 GNAT complier is getting close to working for Apple Silicon now, which is great news!

Similar to Linux distribution package managers such as apt or pacman, many Apple computer users (both Apple M1 chip and Intel x86 chip) use Homebrew or MacPorts to install and manage packages from the command line on their macOS computers. This includes the ability to install gcc, gfortran, gnat, etc - but from an Ada perspective, Intel support only for Ada.

From an alr perspective — could it bootstrap a GNAT install using gcc from homebrew? The Homebrew install script (formula) for gcc is on Github and does have mention of Ada in the comments.

From a macOS native developer tools point of view, macOS is provided with two sets of compiler tools, one that provides command line support, and currently is:

% clang --version
Apple clang version 13.1.6 (clang-1316.0.21.2)
Target: arm64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

which can be installed in a Terminal window with the command:

xcode-select --install

If the tools are already installed the response to running the command is:

% xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates

otherwise it will install them. The path to the installed tools is outlined in the messages above.

Apple also provides its own full developer suite of tools and their own IDE option (also called XCode) that includes the above command lines tools, plus a very large amount of other Apple development libraries etc. This is a very large >20GB download, so unless needed, they don't really warrant installing in my view. The command line tools have enough to support building general open source software etc.

Not sure what other information I can share to help? It would be great to be able to program in Ada again from a personal perspective. Since I moved to Apple Silicon computer hardware wise, I have had no access to native Ada compiler support, so have moved to developing in other languages for now. I would be happy to help if this is being rectified soon :)

wiremoons avatar Mar 20 '22 12:03 wiremoons

The Homebrew GCC install script does indeed mention Ada - but,

    # We avoiding building:
    #  - Ada, which requires a pre-existing GCC Ada compiler to bootstrap

I am indeed close to a working suite with aarch64-apple-darwin21 & gcc-12.0.1, but note that it’s not clear when the changes involved will be ported back to the GCC source tree.

I will of course be raising PRs on AdaCore repos where appropriate. There will no doubt be some discussion, not least because AdaCore don’t have a lot of Mac expertise (@Fabien-Chouteau has been learning by doing!)

simonjwright avatar Mar 20 '22 15:03 simonjwright

The problem was/is that the compilers available via Alire are built against the CommandLineTools - they’re configured with

Thanks to you @simonjwright this should be solved in the next GNAT 11.2 update in Alire :+1:

Fabien-Chouteau avatar Mar 30 '22 12:03 Fabien-Chouteau

Thank you @wiremoons

Similar to Linux distribution package managers such as apt or pacman, many Apple computer users (both Apple M1 chip and Intel x86 chip) use Homebrew or MacPorts to install and manage packages from the command line on their macOS computers.

Since Alire is already able to interface with this kind of "system package manger" on Ubunut/Arch/Msys2, I really want to have similar support for Homebrew and/or MacPorts. It would be a nice addition for macOS users.

From an alr perspective — could it bootstrap a GNAT install using gcc from homebrew? The Homebrew install script (formula) for gcc is on Github and does have mention of Ada in the comments.

We already have GNAT compilers for macOS available in Alire, so this part is more or less covered. The switch to M1 will bring some extra work though.

Not sure what other information I can share to help?

If you can keep providing feedback on Alire for macOS that would be great :)

It would be great to be able to program in Ada again from a personal perspective. Since I moved to Apple Silicon computer hardware wise, I have had no access to native Ada compiler support, so have moved to developing in other languages for now. I would be happy to help if this is being rectified soon :)

One the main issue for us will how to test our builds since GitHub actions to not support macOS on the M1. Other than that I think anything can be achieved.

Fabien-Chouteau avatar Mar 30 '22 13:03 Fabien-Chouteau