Skip to content

Commit

Permalink
MacOS enable flake nix builds (#529)
Browse files Browse the repository at this point in the history
Use built in darwin iconv library
Make auto elf optional and not included on darwin
On darwin use llvm linker and non-llvm use mold linker
  • Loading branch information
adam-singer committed Dec 20, 2023
1 parent 933963f commit e1d35d6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
9 changes: 4 additions & 5 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@

maybeDarwinDeps = pkgs.lib.optionals isDarwin [
pkgs.darwin.apple_sdk.frameworks.Security
pkgs.libiconv
pkgs.darwin.libiconv
];

customStdenv = import ./tools/llvmStdenv.nix { inherit pkgs; };
customStdenv = import ./tools/llvmStdenv.nix { inherit pkgs isDarwin; };

# TODO(aaronmondal): This doesn't work with rules_rust yet.
# Tracked in https://github.com/TraceMachina/nativelink/issues/477.
Expand All @@ -54,11 +54,10 @@
commonArgs = {
inherit src;
strictDeps = true;
buildInputs = [ ];
buildInputs = maybeDarwinDeps;
nativeBuildInputs = [
pkgs.autoPatchelfHook
pkgs.cacert
] ++ maybeDarwinDeps;
] ++ maybeDarwinDeps ++ pkgs.lib.optionals (!isDarwin) [ pkgs.autoPatchelfHook ];
stdenv = customStdenv;
};

Expand Down
28 changes: 19 additions & 9 deletions tools/llvmStdenv.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
{ pkgs, ... }:
{ pkgs, isDarwin ? false, ... }:

let
llvmPackages = pkgs.llvmPackages_16;

toolchain = if isDarwin then (
pkgs.overrideCC (
llvmPackages.libcxxStdenv.override {
targetPlatform.useLLVM = true;
}
)
llvmPackages.clangUseLLVM
) else (pkgs.useMoldLinker (
pkgs.overrideCC (
llvmPackages.libcxxStdenv.override {
targetPlatform.useLLVM = true;
}
)
llvmPackages.clangUseLLVM
));

in

# This toolchain uses Clang as compiler, Mold as linker, libc++ as C++ standard
Expand Down Expand Up @@ -31,11 +48,4 @@ in
# compatibility, reduced closure size, and static-linking-friendly licensing.
# This requires building the llvm project with the correct multistage
# bootstrapping process.
pkgs.useMoldLinker (
pkgs.overrideCC (
llvmPackages.libcxxStdenv.override {
targetPlatform.useLLVM = true;
}
)
llvmPackages.clangUseLLVM
)
toolchain

0 comments on commit e1d35d6

Please sign in to comment.