build: move darwin install_name_tool fixup from vere to king haskell

As well as some variable naming consistency to appease the nixpkgs
gremlins and keep the git history lords on their toes.
This commit is contained in:
Brendan Hay 2020-11-06 09:47:11 +01:00
parent 86b59c67c2
commit 983261a3d8
No known key found for this signature in database
GPG Key ID: 80E915C54A7C457D
5 changed files with 56 additions and 49 deletions

29
ci.nix
View File

@ -18,7 +18,7 @@ let
# Local library import from derivation functions such as fetchGitHubLFS, etc. # Local library import from derivation functions such as fetchGitHubLFS, etc.
# upon which local package defintions are dependent. # upon which local package defintions are dependent.
localLib = callPackage ./nix/lib { }; libLocal = callPackage ./nix/lib { };
# The key with google storage bucket write permission, # The key with google storage bucket write permission,
# deployed to ci via nixops deployment.keys."service-account.json". # deployed to ci via nixops deployment.keys."service-account.json".
@ -31,31 +31,30 @@ let
darwin = "x86_64-darwin"; darwin = "x86_64-darwin";
}; };
# Build the ci matrix for each of the supported systems, see finalPackages # Build the ci matrix for each of the supported systems, see pkgsFinal
# for the total set of attributes that will be evaluated per system. # for the total set of attributes that will be evaluated per system.
in localLib.dimension "system" systems (systemName: system: in libLocal.dimension "system" systems (systemName: system:
let let
dynamicPackages = import ./default.nix { pkgsShared = import ./default.nix {
inherit system; inherit system;
enableStatic = false; enableStatic = false;
}; };
staticPackages = import ./default.nix { pkgsStatic = import ./default.nix {
inherit system; inherit system;
enableStatic = true; enableStatic = true;
}; };
# Filter the stack project to only our locally declared packages. # Filter the stack project to only our locally declared packages.
haskellPackages = pkgsHaskell = haskell-nix.haskellLib.selectProjectPackages pkgsStatic.hs;
haskell-nix.haskellLib.selectProjectPackages staticPackages.hs;
# The top-level set of attributes to build on ci. # The top-level set of attributes to build on ci.
finalPackages = { pkgsFinal = {
# Expose select packages to increase signal-to-noise of the ci dashboard. # Expose select packages to increase signal-to-noise of the ci dashboard.
inherit (staticPackages) urbit; inherit (pkgsStatic) urbit;
inherit (dynamicPackages) urbit-tests; inherit (pkgsShared) urbit-tests;
# Expose the nix-shell derivation as a sanity check + possible cache hit. # Expose the nix-shell derivation as a sanity check + possible cache hit.
shell = import ./shell.nix; shell = import ./shell.nix;
@ -70,11 +69,11 @@ in localLib.dimension "system" systems (systemName: system:
# ... # ...
# #
# Note that .checks are the actual _execution_ of the tests. # Note that .checks are the actual _execution_ of the tests.
hs = localLib.collectHaskellComponents haskellPackages; hs = libLocal.collectHaskellComponents pkgsHaskell;
# Push the tarball to the google storage bucket for the current platform. # Push the tarball to the google storage bucket for the current platform.
release = let inherit (staticPackages) tarball; release = let inherit (pkgsStatic) tarball;
in localLib.pushStorageObject { in libLocal.pushStorageObject {
inherit serviceAccountKey; inherit serviceAccountKey;
bucket = "bootstrap.urbit.org"; bucket = "bootstrap.urbit.org";
@ -87,6 +86,6 @@ in localLib.dimension "system" systems (systemName: system:
# Filter derivations that have meta.platform missing the current system, # Filter derivations that have meta.platform missing the current system,
# such as testFakeShip on darwin. # such as testFakeShip on darwin.
platformFilter = localLib.platformFilterGeneric system; platformFilter = libLocal.platformFilterGeneric system;
in localLib.filterAttrsOnlyRecursive (_: v: platformFilter v) finalPackages) in libLocal.filterAttrsOnlyRecursive (_: v: platformFilter v) pkgsFinal)

View File

@ -6,7 +6,7 @@
Static urbit and urbit-worker binaries: Static urbit and urbit-worker binaries:
$ nix-build -A urbit --arg enableSatic true $ nix-build -A urbit --arg enableStatic true
Note that on linux the previous command is equivalent to: Note that on linux the previous command is equivalent to:
@ -56,32 +56,35 @@
let let
pkgs = import ./nix/default.nix { pkgsNative = import ./nix/default.nix { inherit system; };
pkgsCross = import ./nix/default.nix {
inherit system sources config overlays crossOverlays; inherit system sources config overlays crossOverlays;
# If we're running on linux and crossSystem is unspecified but
# enableStatic = true - set the crossSystem to musl64.
crossSystem = crossSystem =
# If we're running on linux and crossSystem is unspecified but static
# builds are requested - set the crossSystem to musl64.
if system == "x86_64-linux" && crossSystem == null && enableStatic then if system == "x86_64-linux" && crossSystem == null && enableStatic then
"x86_64-unknown-linux-musl" "x86_64-unknown-linux-musl"
else else
crossSystem; crossSystem;
}; };
# Local library import from derivation functions such as fetchGitHubLFS, etc. # Use nixpkgs' top-level/static overlay if enableStatic = true.
# upon which local package defintions are dependent. pkgsStatic = if enableStatic then pkgsCross.pkgsStatic else pkgsCross;
localLib = pkgs.callPackage ./nix/lib { };
# Utilise nixpkgs's top-level/static.nix overlay if required.
hostPackages = if enableStatic then pkgs.pkgsStatic else pkgs;
# Enrich the global package set with our local functions and packages. # Enrich the global package set with our local functions and packages.
# Cross vs static build dependencies can be selectively overridden for
# inputs like python and haskell-nix
callPackage = callPackage =
pkgs.lib.callPackageWith (hostPackages // localLib // localPackages); pkgsNative.lib.callPackageWith (pkgsStatic // libLocal // pkgsLocal);
# Local library import-from-derivation functions such as fetchGitHubLFS, etc.
libLocal = pkgsNative.callPackage ./nix/lib { };
# Local vendored packages defined in ./pkg. # Local vendored packages defined in ./pkg.
# For non-vendored nixpkgs specific package overrides, see ./nix/overlays. # For non-vendored nixpkgs specific package overrides, see ./nix/overlays.
localPackages = { pkgsLocal = {
argon2u = callPackage ./nix/pkgs/argon2u { }; argon2u = callPackage ./nix/pkgs/argon2u { };
ca-bundle = callPackage ./nix/pkgs/ca-bundle { }; ca-bundle = callPackage ./nix/pkgs/ca-bundle { };
@ -100,7 +103,7 @@ let
softfloat3 = callPackage ./nix/pkgs/softfloat3 { }; softfloat3 = callPackage ./nix/pkgs/softfloat3 { };
herb = callPackage ./nix/pkgs/herb { inherit (pkgs) python; }; herb = callPackage ./nix/pkgs/herb { inherit (pkgsCross) python; };
arvo = callPackage ./nix/pkgs/arvo { }; arvo = callPackage ./nix/pkgs/arvo { };
@ -113,18 +116,18 @@ let
urbit = callPackage ./nix/pkgs/urbit { inherit enableStatic; }; urbit = callPackage ./nix/pkgs/urbit { inherit enableStatic; };
hs = callPackage ./nix/pkgs/hs { hs = callPackage ./nix/pkgs/hs {
inherit (pkgs) haskell-nix;
inherit enableStatic; inherit enableStatic;
inherit (pkgsCross) haskell-nix;
}; };
}; };
# Additional top-level packages and attributes exposed for convenience. # Additional top-level packages and attributes exposed for convenience.
extraPackages = with localPackages; rec { pkgsExtra = with pkgsLocal; rec {
# Expose packages we've local customisations for. # Expose packages we've local customisations (like patches) for easy access.
inherit (hostPackages) libsigsegv; inherit (pkgsCross) libsigsegv;
urbit-debug = urbit.override { enableDebug = true; }; urbit-debug = urbit.override { enableDebug = true; };
urbit-tests = localLib.testFakeShip { urbit-tests = libLocal.testFakeShip {
inherit herb; inherit herb;
urbit = urbit-debug; urbit = urbit-debug;
@ -140,7 +143,7 @@ let
tarball = let tarball = let
name = "urbit-v${urbit.version}-${urbit.system}"; name = "urbit-v${urbit.version}-${urbit.system}";
urbit-king = hs.urbit-king.components.exes.urbit-king; urbit-king = hs.urbit-king.components.exes.urbit-king;
in localLib.makeReleaseTarball { in libLocal.makeReleaseTarball {
inherit name; inherit name;
contents = { contents = {
@ -167,16 +170,16 @@ let
# #
shellFor = { name, packages, ... }@attrs: shellFor = { name, packages, ... }@attrs:
pkgs.mkShell ({ pkgs.mkShell ({
inputsFrom = packages localPackages; inputsFrom = packages pkgsLocal;
} // builtins.removeAttrs attrs [ "packages" ]); } // builtins.removeAttrs attrs [ "packages" ]);
}; };
# Ensure that in the case of cross-compilation we're not statically linking # Ensure that in the case of cross-compilation we're not statically linking
# against glibc. This is typically a sign that crossSystem is misconfigured. # against glibc. This is typically a sign that crossSystem is misconfigured.
checkPlatform = checkPlatform =
if enableStatic && hostPackages.stdenv.hostPlatform.libc == "glibc" then if enableStatic && pkgsCross.stdenv.hostPlatform.libc == "glibc" then
builtins.trace "warning: statically linking against glibc." builtins.trace "warning: statically linking against glibc."
else else
pkgs.lib.id; pkgsNative.lib.id;
in checkPlatform (localPackages // extraPackages) in checkPlatform (pkgsLocal // pkgsExtra)

View File

@ -1,3 +1,5 @@
# Functions that are expected run on the native (non-cross) system.
{ lib, recurseIntoAttrs, haskell-nix, callPackage }: { lib, recurseIntoAttrs, haskell-nix, callPackage }:
let let

View File

@ -58,17 +58,26 @@ haskell-nix.stackProject {
"xhtml" "xhtml"
]; ];
# Override various project-local flags and build configuration.
packages = { packages = {
urbit-king.components.exes.urbit-king.enableStatic = enableStatic; urbit-king.components.exes.urbit-king = {
urbit-king.components.exes.urbit-king.enableShared = !enableStatic; enableStatic = enableStatic;
enableShared = !enableStatic;
urbit-king.components.exes.urbit-king.configureFlags = configureFlags = lib.optionals enableStatic [
lib.optionals enableStatic [
"--ghc-option=-optl=-L${gmp}/lib" "--ghc-option=-optl=-L${gmp}/lib"
"--ghc-option=-optl=-L${libffi}/lib" "--ghc-option=-optl=-L${libffi}/lib"
"--ghc-option=-optl=-L${zlib}/lib" "--ghc-option=-optl=-L${zlib}/lib"
] ++ lib.optionals (enableStatic && stdenv.isDarwin) ] ++ lib.optionals (enableStatic && stdenv.isDarwin)
[ "--ghc-option=-optl=-L${darwin.libiconv}/lib" ]; [ "--ghc-option=-optl=-L${darwin.libiconv}/lib" ];
postInstall = lib.optionalString (enableStatic && stdenv.isDarwin) ''
find "$out/bin" -type f -exec \
install_name_tool -change \
${stdenv.cc.libc}/lib/libSystem.B.dylib \
/usr/lib/libSystem.B.dylib {} \;
'';
};
urbit-king.components.tests.urbit-king-tests.testFlags = urbit-king.components.tests.urbit-king-tests.testFlags =
[ "--brass-pill=${brass.lfs}" ]; [ "--brass-pill=${brass.lfs}" ];

View File

@ -54,12 +54,6 @@ in stdenv.mkDerivation {
mkdir -p $out/bin mkdir -p $out/bin
cp ./build/urbit $out/bin/urbit cp ./build/urbit $out/bin/urbit
cp ./build/urbit-worker $out/bin/urbit-worker cp ./build/urbit-worker $out/bin/urbit-worker
'' + lib.optionalString (stdenv.isDarwin && enableStatic) ''
# Hack stolen from //nixpkgs/pkgs/stdenv/darwin/portable-libsystem.sh
find "$out/bin" -exec \
install_name_tool -change \
${stdenv.cc.libc}/lib/libSystem.B.dylib \
/usr/lib/libSystem.B.dylib {} \;
''; '';
CFLAGS = [ (if enableDebug then "-O0" else "-O3") "-g" ] CFLAGS = [ (if enableDebug then "-O0" else "-O3") "-g" ]