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.
# upon which local package defintions are dependent.
localLib = callPackage ./nix/lib { };
libLocal = callPackage ./nix/lib { };
# The key with google storage bucket write permission,
# deployed to ci via nixops deployment.keys."service-account.json".
@ -31,31 +31,30 @@ let
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.
in localLib.dimension "system" systems (systemName: system:
in libLocal.dimension "system" systems (systemName: system:
let
dynamicPackages = import ./default.nix {
pkgsShared = import ./default.nix {
inherit system;
enableStatic = false;
};
staticPackages = import ./default.nix {
pkgsStatic = import ./default.nix {
inherit system;
enableStatic = true;
};
# Filter the stack project to only our locally declared packages.
haskellPackages =
haskell-nix.haskellLib.selectProjectPackages staticPackages.hs;
pkgsHaskell = haskell-nix.haskellLib.selectProjectPackages pkgsStatic.hs;
# The top-level set of attributes to build on ci.
finalPackages = {
pkgsFinal = {
# Expose select packages to increase signal-to-noise of the ci dashboard.
inherit (staticPackages) urbit;
inherit (dynamicPackages) urbit-tests;
inherit (pkgsStatic) urbit;
inherit (pkgsShared) urbit-tests;
# Expose the nix-shell derivation as a sanity check + possible cache hit.
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.
hs = localLib.collectHaskellComponents haskellPackages;
hs = libLocal.collectHaskellComponents pkgsHaskell;
# Push the tarball to the google storage bucket for the current platform.
release = let inherit (staticPackages) tarball;
in localLib.pushStorageObject {
release = let inherit (pkgsStatic) tarball;
in libLocal.pushStorageObject {
inherit serviceAccountKey;
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,
# 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:
$ nix-build -A urbit --arg enableSatic true
$ nix-build -A urbit --arg enableStatic true
Note that on linux the previous command is equivalent to:
@ -56,32 +56,35 @@
let
pkgs = import ./nix/default.nix {
pkgsNative = import ./nix/default.nix { inherit system; };
pkgsCross = import ./nix/default.nix {
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 =
# 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
"x86_64-unknown-linux-musl"
else
crossSystem;
};
# Local library import from derivation functions such as fetchGitHubLFS, etc.
# upon which local package defintions are dependent.
localLib = pkgs.callPackage ./nix/lib { };
# Utilise nixpkgs's top-level/static.nix overlay if required.
hostPackages = if enableStatic then pkgs.pkgsStatic else pkgs;
# Use nixpkgs' top-level/static overlay if enableStatic = true.
pkgsStatic = if enableStatic then pkgsCross.pkgsStatic else pkgsCross;
# 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 =
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.
# For non-vendored nixpkgs specific package overrides, see ./nix/overlays.
localPackages = {
pkgsLocal = {
argon2u = callPackage ./nix/pkgs/argon2u { };
ca-bundle = callPackage ./nix/pkgs/ca-bundle { };
@ -100,7 +103,7 @@ let
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 { };
@ -113,18 +116,18 @@ let
urbit = callPackage ./nix/pkgs/urbit { inherit enableStatic; };
hs = callPackage ./nix/pkgs/hs {
inherit (pkgs) haskell-nix;
inherit enableStatic;
inherit (pkgsCross) haskell-nix;
};
};
# Additional top-level packages and attributes exposed for convenience.
extraPackages = with localPackages; rec {
# Expose packages we've local customisations for.
inherit (hostPackages) libsigsegv;
pkgsExtra = with pkgsLocal; rec {
# Expose packages we've local customisations (like patches) for easy access.
inherit (pkgsCross) libsigsegv;
urbit-debug = urbit.override { enableDebug = true; };
urbit-tests = localLib.testFakeShip {
urbit-tests = libLocal.testFakeShip {
inherit herb;
urbit = urbit-debug;
@ -140,7 +143,7 @@ let
tarball = let
name = "urbit-v${urbit.version}-${urbit.system}";
urbit-king = hs.urbit-king.components.exes.urbit-king;
in localLib.makeReleaseTarball {
in libLocal.makeReleaseTarball {
inherit name;
contents = {
@ -167,16 +170,16 @@ let
#
shellFor = { name, packages, ... }@attrs:
pkgs.mkShell ({
inputsFrom = packages localPackages;
inputsFrom = packages pkgsLocal;
} // builtins.removeAttrs attrs [ "packages" ]);
};
# Ensure that in the case of cross-compilation we're not statically linking
# against glibc. This is typically a sign that crossSystem is misconfigured.
checkPlatform =
if enableStatic && hostPackages.stdenv.hostPlatform.libc == "glibc" then
if enableStatic && pkgsCross.stdenv.hostPlatform.libc == "glibc" then
builtins.trace "warning: statically linking against glibc."
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 }:
let

View File

@ -58,18 +58,27 @@ haskell-nix.stackProject {
"xhtml"
];
# Override various project-local flags and build configuration.
packages = {
urbit-king.components.exes.urbit-king.enableStatic = enableStatic;
urbit-king.components.exes.urbit-king.enableShared = !enableStatic;
urbit-king.components.exes.urbit-king = {
enableStatic = enableStatic;
enableShared = !enableStatic;
urbit-king.components.exes.urbit-king.configureFlags =
lib.optionals enableStatic [
configureFlags = lib.optionals enableStatic [
"--ghc-option=-optl=-L${gmp}/lib"
"--ghc-option=-optl=-L${libffi}/lib"
"--ghc-option=-optl=-L${zlib}/lib"
] ++ lib.optionals (enableStatic && stdenv.isDarwin)
[ "--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 =
[ "--brass-pill=${brass.lfs}" ];
};

View File

@ -54,12 +54,6 @@ in stdenv.mkDerivation {
mkdir -p $out/bin
cp ./build/urbit $out/bin/urbit
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" ]