crystal: make Crystal default target match Nix target platform #223901
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of changes
When building the Crystal compiler, it picks a default LLVM target triple by either looking at the env var CRYSTAL_CONFIG_TARGET if set, or by calling LLVMGetDefaultTargetTriple on the linked LLVM. https://github.com/crystal-lang/crystal/blob/master/src/compiler/crystal/config.cr#L47
On nix linux builds of Crystal using the LLVM function seems to be fine. However on MacOS, it can cause a mismatch with nix's MacOS stdenv.
stdenv.targetPlatform.darwinMinVersion defaults to "11.0" and this makes it's way into all the clang and ld wrapper scripts. However, the default LLVM target can be something such as "aarch64-apple-darwin22.3.0" which would translate to kernel version 13. Then Crystal would build .o files targeting 13, and the wrapped clang/ld would try and link them to be compatible with 11 and generate hundreds of warning messages such as " was built for newer macOS version (13.0) than being linked (11.0)".
By setting the CRYSTAL_CONFIG_TARGET to match the nix targetPlatform, the default target for the compiler becomes just "aarch64-apple-darwin", and everything works as expected.
On linux setting this env var has no effect, since the LLVM detected triple matches that of the nix targetPlatform.
Things done
sandbox = true
set innix.conf
? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)fixes: #219512
ref: #164648 (comment)