Skip to content

Commit

Permalink
Build nix-util with Meson
Browse files Browse the repository at this point in the history
The idea is two-fold:

- Replace autotools with Meson

- Build each library in its own derivation

The interaction of these two features is that Meson's "subprojects"
feature (https://mesonbuild.com/Subprojects) allows us to have single
dev shell for building all libraries still, while also building things
separately. This allows us to break up the build without a huge
productivity lost.

I tested the Linux native build, and NetBSD and Windows cross builds.

Also do some clean ups of the Flake in the process of supporting new
jobs.

Special thanks to everyone that has worked on a Meson port so far,
@p01arst0rm and @Qyriad in particular.

Co-Authored-By: p01arst0rm <[email protected]>

Co-Authored-By: Artemis Tosini <[email protected]>
Co-Authored-By: Artemis Tosini <[email protected]>
Co-Authored-By: Felix Uhl <[email protected]>
Co-Authored-By: Jade Lovelace <[email protected]>
Co-Authored-By: Lunaphied <[email protected]>
Co-Authored-By: Maximilian Bosch <[email protected]>
Co-Authored-By: Pierre Bourdon <[email protected]>
Co-Authored-By: Qyriad <[email protected]>
Co-Authored-By: Rebecca Turner <[email protected]>
Co-Authored-By: Winter <[email protected]>
Co-Authored-By: eldritch horrors <[email protected]>
Co-Authored-By: jade <[email protected]>
Co-Authored-By: julia <[email protected]>
Co-Authored-By: rebecca “wiggles” turner <[email protected]>
Co-Authored-By: wiggles dog <[email protected]>

Co-Authored-By: fricklerhandwerk <[email protected]>
  • Loading branch information
Ericson2314 and fricklerhandwerk committed Jun 4, 2024
1 parent d6e0ccd commit d6bad59
Show file tree
Hide file tree
Showing 8 changed files with 522 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ perl/Makefile.config
/svn-revision
/libtool
/config/config.*
# Default meson build dir
/build

# /doc/manual/
/doc/manual/*.1
Expand Down
67 changes: 42 additions & 25 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,23 @@

changelog-d-nix = final.buildPackages.callPackage ./misc/changelog-d.nix { };

nix-util = final.callPackage ./subprojects/libutil/package.nix {
inherit
fileset
stdenv
officialRelease
versionSuffix
;
};

nix =
let
officialRelease = false;
versionSuffix =
if officialRelease
then ""
else "pre${builtins.substring 0 8 (self.lastModifiedDate or self.lastModified or "19700101")}_${self.shortRev or "dirty"}";

in final.callPackage ./package.nix {
final.callPackage ./package.nix {
inherit
fileset
stdenv
officialRelease
versionSuffix
;
officialRelease = false;
boehmgc = final.boehmgc-nix;
libgit2 = final.libgit2-nix;
libseccomp = final.libseccomp-nix;
Expand Down Expand Up @@ -210,7 +212,7 @@
# 'nix.perl-bindings' packages.
overlays.default = overlayFor (p: p.stdenv);

hydraJobs = import ./build/hydra.nix {
hydraJobs = import ./maintainers/hydra.nix {
inherit
inputs
binaryTarball
Expand Down Expand Up @@ -243,11 +245,12 @@
} // devFlake.checks.${system} or {}
);

packages = forAllSystems (system: rec {
inherit (nixpkgsFor.${system}.native) nix changelog-d-nix;
packages = forAllSystems (system: let
forAllPackagesList = lib.flip map [ "nix" "nix-util" ];
in rec {
inherit (nixpkgsFor.${system}.native) nix nix-util changelog-d-nix;
default = nix;
} // (lib.optionalAttrs (builtins.elem system linux64BitSystems) {
nix-static = nixpkgsFor.${system}.static.nix;
} // lib.optionalAttrs (builtins.elem system linux64BitSystems) {
dockerImage =
let
pkgs = nixpkgsFor.${system}.native;
Expand All @@ -262,18 +265,25 @@
ln -s ${image} $image
echo "file binary-dist $image" >> $out/nix-support/hydra-build-products
'';
} // builtins.listToAttrs (map
(crossSystem: {
name = "nix-${crossSystem}";
value = nixpkgsFor.${system}.cross.${crossSystem}.nix;
})
} // builtins.listToAttrs (forAllPackagesList
(pkgName: {
name = "${pkgName}-static";
value = nixpkgsFor.${system}.static.${pkgName};
}))
// builtins.listToAttrs (lib.concatMap
(crossSystem: forAllPackagesList
(pkgName: {
name = "${pkgName}-${crossSystem}";
value = nixpkgsFor.${system}.cross.${crossSystem}.${pkgName};
}))
crossSystems)
// builtins.listToAttrs (map
(stdenvName: {
name = "nix-${stdenvName}";
value = nixpkgsFor.${system}.stdenvs."${stdenvName}Packages".nix;
})
stdenvs)));
// builtins.listToAttrs (lib.concatMap
(stdenvName: forAllPackagesList
(pkgName: {
name = "${pkgName}-${stdenvName}";
value = nixpkgsFor.${system}.stdenvs."${stdenvName}Packages".${pkgName};
}))
stdenvs));

devShells = let
makeShell = pkgs: stdenv: (pkgs.nix.override { inherit stdenv; forDevShell = true; }).overrideAttrs (attrs:
Expand All @@ -295,12 +305,19 @@
src = null;

env = {
# Needed for Meson to find Boost.
# https://github.com/NixOS/nixpkgs/issues/86131.
BOOST_INCLUDEDIR = "${lib.getDev pkgs.boost}/include";
BOOST_LIBRARYDIR = "${lib.getLib pkgs.boost}/lib";
# For `make format`, to work without installing pre-commit
_NIX_PRE_COMMIT_HOOKS_CONFIG =
"${(pkgs.formats.yaml { }).generate "pre-commit-config.yaml" modular.pre-commit.settings.rawConfig}";
};

inherit (pkgs.nix-util) mesonFlags;

nativeBuildInputs = attrs.nativeBuildInputs or []
++ pkgs.nix-util.nativeBuildInputs
++ [
modular.pre-commit.settings.package
(pkgs.writeScriptBin "pre-commit-hooks-install"
Expand Down
12 changes: 8 additions & 4 deletions build/hydra.nix → maintainers/hydra.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,21 @@ let

doBuild = false;
};

forAllPackages = lib.genAttrs [ "nix" "nix-util" ];
in
{
# Binary package for various platforms.
build = forAllSystems (system: self.packages.${system}.nix);

shellInputs = forAllSystems (system: self.devShells.${system}.default.inputDerivation);

buildStatic = lib.genAttrs linux64BitSystems (system: self.packages.${system}.nix-static);
buildStatic = forAllPackages (pkgName:
lib.genAttrs linux64BitSystems (system: nixpkgsFor.${system}.static.${pkgName}));

buildCross = forAllCrossSystems (crossSystem:
lib.genAttrs [ "x86_64-linux" ] (system: self.packages.${system}."nix-${crossSystem}"));
buildCross = forAllPackages (pkgName:
forAllCrossSystems (crossSystem:
lib.genAttrs [ "x86_64-linux" ] (system: nixpkgsFor.${system}.cross.${crossSystem}.${pkgName})));

buildNoGc = forAllSystems (system:
self.packages.${system}.nix.override { enableGC = false; }
Expand Down Expand Up @@ -76,7 +80,7 @@ in
binaryTarballCross = lib.genAttrs [ "x86_64-linux" ] (system:
forAllCrossSystems (crossSystem:
binaryTarball
self.packages.${system}."nix-${crossSystem}"
nixpkgsFor.${system}.cross.${crossSystem}.nix
nixpkgsFor.${system}.cross.${crossSystem}));

# The first half of the installation script. This is uploaded
Expand Down
8 changes: 8 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This is just a stub project to include all the others as subprojects
# for development shell purposes

project('nix-dev-shell', 'cpp',
version : run_command('cat', './.version', check : true).stdout().strip(),
)

subproject('libutil')
1 change: 1 addition & 0 deletions subprojects/libutil/.version
Loading

0 comments on commit d6bad59

Please sign in to comment.