From 3e31aae7b92231ff084ad5dfb5241d09e02598cf Mon Sep 17 00:00:00 2001 From: Brendan Hay Date: Fri, 30 Oct 2020 13:02:27 +0100 Subject: [PATCH] build: default crossSystem to musl64 on linux if enableStatic --- ci.nix | 50 ++++++++++++++++++++------------------------------ default.nix | 17 +++++++++++++++-- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/ci.nix b/ci.nix index 4f2789173..038e57003 100644 --- a/ci.nix +++ b/ci.nix @@ -48,31 +48,21 @@ let extension = "pill"; }; - systems = lib.filterAttrs (_: v: builtins.elem v.system supportedSystems) { - linux = { - system = "x86_64-linux"; - crossSystem = lib.systems.examples.musl64; - }; - - darwin = { - system = "x86_64-darwin"; - crossSystem = null; - }; + systems = lib.filterAttrs (_: v: builtins.elem v supportedSystems) { + linux = "x86_64-linux"; + darwin = "x86_64-darwin"; }; -in localLib.dimension "system" systems (systemName: - { system, crossSystem }: +in localLib.dimension "system" systems (systemName: system: let - # Shared libraries/executables for the build (current) system. - localPackages = import ./default.nix { + dynamicPackages = import ./default.nix { inherit system; enableStatic = false; }; - # Static libraries/executables for the host (cross) system. staticPackages = import ./default.nix { - inherit system crossSystem; + inherit system; enableStatic = true; }; @@ -82,23 +72,23 @@ in localLib.dimension "system" systems (systemName: haskell-nix.haskellLib.selectProjectPackages staticPackages.hs; # The top-level set of attributes to build on ci. - finalPackages = localPackages // rec { + finalPackages = dynamicPackages // rec { + # Replace some top-level attributes with their static variant. + inherit (staticPackages) urbit tarball; + # Expose the nix-shell derivation as a sanity check. shell = import ./shell.nix; - # Replace the top-level urbit attribute with the static variant. - urbit = staticPackages.urbit; - - # Replace the top-level tarball attribute with the static variant. - tarball = staticPackages.tarball; - - # Replace the localPackages.hs attribute with the individual components + # Replace the .hs attribute with the individual collections of components # displayed as top-level attributes: # # .hs.library.[...] + # .hs.checks.[...] # .hs.tests.[...] - # .hs.bencharmks.[...] + # .hs.benchmarks.[...] # ... + # + # Note that .checks are the actual _execution_ of the tests. hs = localLib.collectHaskellComponents haskellPackages; # Push the tarball to the remote google storage bucket. @@ -111,12 +101,12 @@ in localLib.dimension "system" systems (systemName: # Replace top-level pill attributes with push to google storage variants. } // lib.optionalAttrs (system == "x86_64-linux") { - ivory = pushPill "ivory" localPackages.ivory; - brass = pushPill "brass" localPackages.brass; - solid = pushPill "solid" localPackages.solid; + ivory = pushPill "ivory" dynamicPackages.ivory; + brass = pushPill "brass" dynamicPackages.brass; + solid = pushPill "solid" dynamicPackages.solid; - ivory-ropsten = pushPill "ivory-ropsten" localPackages.ivory-ropsten; - brass-ropsten = pushPill "brass-ropsten" localPackages.brass-ropsten; + ivory-ropsten = pushPill "ivory-ropsten" dynamicPackages.ivory-ropsten; + brass-ropsten = pushPill "brass-ropsten" dynamicPackages.brass-ropsten; }; # Filter derivations that have meta.platform missing the current system, diff --git a/default.nix b/default.nix index 3d7fe82d2..dd3a61719 100644 --- a/default.nix +++ b/default.nix @@ -8,6 +8,11 @@ $ nix-build -A urbit --arg enableSatic true + Note that on linux the previous command is equivalent to: + + $ nix-build -A urbit --argstr crossSystem x86_64-unknown-linux-musl \ + --arg enableSatic true + Static urbit-king binary: $ nix-build -A hs.urbit-king.components.exes.urbit-king --arg enableStatic true @@ -47,12 +52,20 @@ , crossOverlays ? [ ] # Whether to use pkgs.pkgsStatic.* to obtain statically linked package # dependencies - ie. when building fully-static libraries or executables. -, enableStatic ? crossSystem != null }: +, enableStatic ? false }: let pkgs = import ./nix/default.nix { - inherit system crossSystem sources config overlays crossOverlays; + inherit system sources config overlays crossOverlays; + + 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.