Skip to content

Commit

Permalink
build: Use uv build instead of pypa/build
Browse files Browse the repository at this point in the history
When I started the new builders I couldn't make `uv build` work, but now it seems to work just fine and greatly simplifies bootstrapping.

This removes the need to have any bootstrapping set at all.
  • Loading branch information
adisbladis committed Nov 20, 2024
1 parent e5242b5 commit d8174ad
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 156 deletions.
65 changes: 28 additions & 37 deletions build/checks/build-systems.nix
Original file line number Diff line number Diff line change
@@ -1,46 +1,37 @@
{
lib,
pyproject-nix,
}:
let
overlay' =
final: _prev:
lib.mapAttrs
(
name: pkg:
if pyproject-nix.build.lib.isBootstrapPackage name then
final.callPackage pkg { pyprojectHook = final.pyprojectBootstrapHook; }
else
final.callPackage pkg { }
)
{
flit-core = ../pkgs/flit-core;
packaging = ../pkgs/packaging;
pyproject-hooks = ../pkgs/pyproject-hooks;
setuptools = ../pkgs/setuptools;
wheel = ../pkgs/wheel;
hatchling = ../pkgs/hatchling;
pdm-backend = ../pkgs/pdm-backend;
cython = ../pkgs/cython;
meson = ../pkgs/meson;
build = ../pkgs/build;
installer = ../pkgs/installer;
pathspec = ../pkgs/pathspec;
pluggy = ../pkgs/pluggy;
setuptools-scm = ../pkgs/setuptools-scm;
trove-classifiers = ../pkgs/trove-classifiers;
calver = ../pkgs/calver;
zipp = ../pkgs/zipp;
tomli-w = ../pkgs/tomli-w;
cffi = ../pkgs/cffi;
maturin = ../pkgs/maturin;
setuptools-rust = ../pkgs/setuptools-rust;
pycparser = ../pkgs/pycparser;
typing-extensions = ../pkgs/typing-extensions;
semantic-version = ../pkgs/semantic-version;
tomli = ../pkgs/tomli;
pip = ../pkgs/pip;
};
lib.mapAttrs (_name: pkg: final.callPackage pkg { }) {
flit-core = ../pkgs/flit-core;
packaging = ../pkgs/packaging;
pyproject-hooks = ../pkgs/pyproject-hooks;
setuptools = ../pkgs/setuptools;
wheel = ../pkgs/wheel;
hatchling = ../pkgs/hatchling;
pdm-backend = ../pkgs/pdm-backend;
cython = ../pkgs/cython;
meson = ../pkgs/meson;
build = ../pkgs/build;
installer = ../pkgs/installer;
pathspec = ../pkgs/pathspec;
pluggy = ../pkgs/pluggy;
setuptools-scm = ../pkgs/setuptools-scm;
trove-classifiers = ../pkgs/trove-classifiers;
calver = ../pkgs/calver;
zipp = ../pkgs/zipp;
tomli-w = ../pkgs/tomli-w;
cffi = ../pkgs/cffi;
maturin = ../pkgs/maturin;
setuptools-rust = ../pkgs/setuptools-rust;
pycparser = ../pkgs/pycparser;
typing-extensions = ../pkgs/typing-extensions;
semantic-version = ../pkgs/semantic-version;
tomli = ../pkgs/tomli;
pip = ../pkgs/pip;
};

crossOverlay = lib.composeExtensions (_final: prev: {
pythonPkgsBuildHost = prev.pythonPkgsBuildHost.overrideScope overlay';
Expand Down
39 changes: 2 additions & 37 deletions build/checks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
}:

let
inherit (pyproject-nix.build.lib) isBootstrapPackage renderers;
inherit (pyproject-nix.build.lib) renderers;
inherit (lib) filter attrValues isDerivation;

python = pkgs.python312;

buildSystems = import ./build-systems.nix {
inherit pyproject-nix lib;
inherit lib;
};

# Inject your own packages on top with overrideScope
Expand Down Expand Up @@ -78,41 +78,6 @@ in
}
) { };

# Bootstrap dependencies need to use pyprojectBootstrapHook
overriden-bootstrap-dep =
let
overlay = final: _prev: {
packaging = final.stdenv.mkDerivation {
pname = "packaging";
version = "24.1";

src = pkgs.fetchurl {
url = "https://files.pythonhosted.org/packages/51/65/50db4dda066951078f0a96cf12f4b9ada6e4b811516bf0262c0f4f7064d4/packaging-24.1.tar.gz";
hash = "sha256-Am7XLI7T/M5b+JUFciWGmJJ/0dvaEKXpgc3wrDf08AI=";
};

nativeBuildInputs =
assert isBootstrapPackage "packaging";
[
final.pyprojectBootstrapHook
]
++ final.resolveBuildSystem {
flit-core = [ ];
};
};
};

pythonSet' = pythonSet.overrideScope (
_final: prev: {
pythonPkgsBuildHost = prev.pythonPkgsBuildHost.overrideScope overlay;
}
);

in
pythonSet'.pythonPkgsHostHost.mkVirtualEnv "overriden-bootstrap-venv" {
build = [ ];
};

full-set =
let
pythonSetDrvs = filter isDerivation (attrValues pythonSet.pythonPkgsHostHost);
Expand Down
2 changes: 1 addition & 1 deletion build/hacks/checks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let
python = pkgs.python3;

buildSystems = import ../checks/build-systems.nix {
inherit pyproject-nix lib;
inherit lib;
};

pythonSet =
Expand Down
27 changes: 13 additions & 14 deletions build/hooks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
python,
pkgs,
lib,
resolveBuildSystem,
stdenv,
hooks,
pythonPkgsBuildHost,
}:
let
inherit (python) pythonOnBuildForHost isPy3k;
Expand Down Expand Up @@ -45,19 +43,20 @@ in
Used internally by `pyprojectHook`.
*/
pyprojectBuildHook = callPackage (
_:
makeSetupHook {
name = "pyproject-build-hook";
substitutions = {
inherit (pythonPkgsBuildHost) build;
inherit pythonInterpreter;
};
propagatedBuildInputs = resolveBuildSystem {
build = [ ];
pyprojectBuildHook =
callPackage
(
{ uv }:
makeSetupHook {
name = "pyproject-build-hook";
substitutions = {
inherit pythonInterpreter uv;
};
} ./pyproject-build-hook.sh
)
{
inherit (buildPackages) uv;
};
} ./pyproject-build-hook.sh
) { };

/*
Symlink prebuilt wheel sources.
Expand Down
2 changes: 1 addition & 1 deletion build/hooks/pyproject-build-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pyprojectBuildPhase() {
runHook preBuild

echo "Creating a wheel..."
env PYTHONPATH="${NIX_PYPROJECT_PYTHONPATH}:${PYTHONPATH}" @build@/bin/pyproject-build --no-isolation --outdir dist/ --wheel $pypaBuildFlags
env PYTHONPATH="${NIX_PYPROJECT_PYTHONPATH}:${PYTHONPATH}" @uv@/bin/uv build --no-cache --python=@pythonInterpreter@ --offline --no-build-isolation --out-dir dist/ --wheel $uvBuildFlags

runHook postBuild
echo "Finished executing pyprojectBuildPhase"
Expand Down
18 changes: 2 additions & 16 deletions build/lib/default.nix
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
{ lib, pyproject-nix }:
let
inherit (builtins) mapAttrs;
inherit (lib) fix elem flip;
inherit (lib) fix;
in

fix (
self:
{
/*
Check if a package is a bootstrap package by it's name.
This needs to be used by lockfile consumers to check if a package needs pyprojectBootstrapHook instead of pyprojectHook.
*/
isBootstrapPackage = flip elem [
"flit-core"
"pyproject-hooks"
"packaging"
"build"
"tomli"
];
}
// mapAttrs (_: path: import path ({ inherit pyproject-nix lib; } // self)) {
mapAttrs (_: path: import path ({ inherit pyproject-nix lib; } // self)) {
renderers = ./renderers.nix;
resolvers = ./resolvers.nix;
}
Expand Down
2 changes: 1 addition & 1 deletion build/lib/test_renderers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let
python = pkgs.python312;

buildSystems = import ../checks/build-systems.nix {
inherit pyproject-nix lib;
inherit lib;
};

pythonSet =
Expand Down
36 changes: 1 addition & 35 deletions build/packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ let
# Build-system package names to memoise
memoNames = lib.attrNames (mkPkgs' {
# Hack: We only need attrNames
pyprojectBootstrapHook = null;
callPackage = null;
});

Expand Down Expand Up @@ -40,26 +39,20 @@ let
pkgsFun =
final:
lib.mapAttrs (name: drv: builtins.trace (deprecatedBuild name) drv) (mkPkgs' {
inherit (final) callPackage pyprojectBootstrapHook;
inherit (final) callPackage;
});

mkPythonSet =
{
python,
stdenv,
pythonPkgsBuildHost,
bootstrapHooks,
pythonPkgsFun,
pkgsFinal,
}:
{
inherit python stdenv pythonPkgsBuildHost;

# Pyproject hook used for bootstrap packages
pyprojectBootstrapHook = pkgsFinal.pyprojectHook.override {
inherit (bootstrapHooks) pyprojectConfigureHook pyprojectBuildHook;
};

# Initialize dependency resolvers
resolveBuildSystem = mkResolveBuildSystem pythonPkgsBuildHost;
resolveVirtualEnv = mkResolveVirtualEnv pkgsFinal;
Expand Down Expand Up @@ -108,39 +101,13 @@ in
}:
makeScope newScope (
final:
let
bootstrapHooks = final.callPackage ./hooks {
python = final.python.pythonOnBuildForHost;
resolveBuildSystem = mkResolveBuildSystem final.pythonPkgsBootstrap;
hooks = bootstrapHooks;
};

in
(mkPythonSet {
inherit python stdenv;
pkgsFinal = final;
pythonPkgsBuildHost = final.pythonPkgsHostHost;
bootstrapHooks = final.pythonPkgsBootstrap.hooks;
pythonPkgsFun = pkgsFun;
})
// {
# Bootstrap packages used to bootstrap set
pythonPkgsBootstrap = makeScope buildPackages.newScope (
pkgsFinal:
mkPythonSet {
inherit (buildPackages) stdenv;
inherit bootstrapHooks pkgsFinal;
python = python.pythonOnBuildForHost;
pythonPkgsBuildHost = final.pythonPkgsBootstrap;
pythonPkgsFun =
_:
final.callPackage ./bootstrap.nix {
inherit (bootstrapHooks) pyprojectInstallHook pyprojectBytecodeHook pyprojectOutputSetupHook;
python = final.python.pythonOnBuildForHost;
};
}
);

# Python packages for the build host.
# In case of cross compilation this set is instantiated with host packages, otherwise
# it's aliasing pythonPkgsHostHost
Expand All @@ -152,7 +119,6 @@ makeScope newScope (
inherit (buildPackages) stdenv;
python = python.pythonOnBuildForHost;
inherit (final) pythonPkgsBuildHost;
bootstrapHooks = final.pythonPkgsBootstrap.hooks;
pythonPkgsFun = pkgsFun;
inherit pkgsFinal;
}
Expand Down
16 changes: 2 additions & 14 deletions build/pkgs/default.nix
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
{ lib, pyproject-nix }:

let
inherit (pyproject-nix.build.lib) isBootstrapPackage;
inherit (lib) mapAttrs filterAttrs;
inherit (builtins) readDir;

# List all packages in directory
paths = filterAttrs (_name: type: type == "directory") (readDir ./.);

in
{ callPackage, pyprojectBootstrapHook }:
{ callPackage }:
# Automatically call all packages
(mapAttrs (
name: _:
callPackage (./. + "/${name}") (
# Override bootstrap packages with bootstrap hook
if isBootstrapPackage name then
{
pyprojectHook = pyprojectBootstrapHook;
}
else
{ }
)
) paths)
(mapAttrs (name: _: callPackage (./. + "/${name}") { }) paths)

0 comments on commit d8174ad

Please sign in to comment.