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

crystal: make Crystal default target match Nix target platform #223901

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

will
Copy link
Contributor

@will will commented Mar 30, 2023

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
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.05 Release Notes (or backporting 22.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

fixes: #219512
ref: #164648 (comment)

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.

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
"<file> 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.
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/showing-first-time-contributors-some-love/29105/14

@straight-shoota
Copy link

This looks like a good quick solution.
I believe this could be fixed in the Crystal compiler in a generic way, see crystal-lang/crystal#13594

@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crystal package not building with configured MACOSX_DEPLOYMENT_TARGET
6 participants