Skip to content

Commit 840ac9f

Browse files
committed
Add Nix CI
1 parent 3204bb0 commit 840ac9f

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,12 @@ jobs:
3838
run: |
3939
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
4040
make test -j$(nproc)
41+
build-with-nix:
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/checkout@v1
45+
- uses: cachix/install-nix-action@v13
46+
with:
47+
nix_path: nixpkgs=channel:nixos-stable
48+
- name: Build the CI package set
49+
run: nix-build default.nix -A ciPackages

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,31 @@ String dump of section '.comment':
122122

123123
If `mold` is in `.comment`, the file is created by mold.
124124

125+
### Use with Nix
126+
127+
The `default.nix` of this repository provides an easy method to build
128+
packages with mold as linker. General usage is `nix-build -A $attribute`,
129+
the following attributes are provided:
130+
131+
- `pkgs`: A baseline package set for comparison. Sometimes packages are simply
132+
broken and mold has nothing to do with it. Use `pkgs.packageName` to build specific
133+
packages, and `nix search` or https://search.nixos.org/packages to find the
134+
attribute name.
135+
- `pkgsMold`: Equivalent to `pkgs`, except that `bfd` is replaced by mold as linker.
136+
This has a few implications that are important to know:
137+
- This will bootstrap the entire toolchain and build all transitive dependencies every
138+
time mold changes.
139+
- Packages that require a custom linker (like lld or some special GCC) won't be built with
140+
mold.
141+
- `pkgsMoldCI`: Equivalent to `pkgsMold`, except that mold is disabled for known failing
142+
packages until they are resolved.
143+
- `ciPackages`: A set of working packages that are built as part of the CI in order to catch
144+
regressions.
145+
146+
After a successful build, `./result` will be a symlink to the output.
147+
You can install Nix alongside your usual package manager, see https://nixos.org/download.html.
148+
There are also Docker images providing a local Nix installation.
149+
125150
# Design and implementation of mold
126151

127152
For the rest of this documentation, I'll explain the design and the

default.nix

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
let
2+
# Pin some fairly new nixpkgs
3+
sources = builtins.fetchTarball {
4+
name = "nixpkgs-unstable-2021-07-06";
5+
url = "https://github.com/nixos/nixpkgs/archive/291b3ff5af268eb7a656bb11c73f2fe535ea2170.tar.gz";
6+
sha256 = "1z2l7q4cmiaqb99cd8yfisdr1n6xbwcczr9020ss47y2z1cn1x7x";
7+
};
8+
9+
# For bootstrapping
10+
pkgs = import sources {
11+
overlays = [
12+
(pkgs: super: {
13+
# TODO replace with proper packaging once https://github.com/NixOS/nixpkgs/pull/128889 is merged
14+
mold = pkgs.stdenv.mkDerivation {
15+
pname = "mold";
16+
version = "0.9.1";
17+
src = ./.;
18+
nativeBuildInputs = with pkgs; [ clang_12 cmake lld_12 tbb xxHash zlib openssl git ];
19+
dontUseCmakeConfigure = "true";
20+
buildPhase = "make -j $NIX_BUILD_CORES";
21+
installPhase = "mkdir -p $out $out/bin $out/share/man/man1 && PREFIX=$out make install";
22+
};
23+
24+
binutils_mold = pkgs.wrapBintoolsWith {
25+
bintools = pkgs.binutils-unwrapped.overrideAttrs (old: {
26+
postInstall = ''
27+
rm $out/bin/ld.gold
28+
rm $out/bin/ld.bfd
29+
ln -sf ${pkgs.mold}/bin/mold $out/bin/ld.bfd
30+
'';
31+
});
32+
};
33+
34+
stdenv_mold = super.overrideCC super.stdenv (super.wrapCCWith rec {
35+
cc = super.gcc-unwrapped;
36+
bintools = pkgs.binutils_mold;
37+
});
38+
})
39+
];
40+
};
41+
42+
# Actual nixpkgs with patched linker in all packages
43+
pkgsMold = import sources {
44+
overlays = [
45+
(self: super: {
46+
stdenv = pkgs.stdenv_mold;
47+
mold = pkgs.mold;
48+
})
49+
];
50+
};
51+
52+
# Like pkgsMold, but we disable mold individually for known failing packages until their issues are resolved
53+
pkgsMoldCI = pkgsMold.appendOverlays [
54+
(self: super: {
55+
inherit (pkgs)
56+
valgrind # https://github.com/rui314/mold/issues/81#issuecomment-876425070
57+
;
58+
})
59+
];
60+
in {
61+
inherit pkgs pkgsMold pkgsMoldCI;
62+
63+
# Packages we already know that work in order to catch regressions
64+
ciPackages = with pkgsMoldCI; linkFarmFromDrvs "packages-with-mold" [
65+
binutils
66+
stdenv
67+
# TODO
68+
];
69+
}

0 commit comments

Comments
 (0)