chore(tvix): avoid unnesscary rebuilds of protos and tvix
For the build of tvix we can safely ignore all the files in src/protos as well as all the nix files in the root of the repository. By passing the input sources through builtins.filterSource we can make a per-file decision whether or not we want to copy it into the store (in other words: if we consider it relevant for the build). This enables much faster development on the actual build expression. Change-Id: Ib4c01dbe9cbfa9770922f6257af2a7259814ce0d Reviewed-on: https://cl.tvl.fyi/c/depot/+/2159 Tested-by: BuildkiteCI Reviewed-by: glittershark <grfn@gws.fyi> Reviewed-by: lukegb <lukegb@tvl.fyi>
This commit is contained in:
parent
e772f38a5e
commit
9bf6eb7f82
1 changed files with 26 additions and 2 deletions
28
third_party/nix/default.nix
vendored
28
third_party/nix/default.nix
vendored
|
@ -12,12 +12,36 @@ let
|
|||
customMemoryManagement = false;
|
||||
};
|
||||
|
||||
src = ./.;
|
||||
src = let
|
||||
srcDir = ./.;
|
||||
# create relative paths for all the sources we are filtering
|
||||
asRelative = path:
|
||||
let
|
||||
srcS = toString srcDir;
|
||||
pathS = toString path;
|
||||
in
|
||||
if ! lib.hasPrefix srcS pathS then
|
||||
throw "Path is outside of the working directory."
|
||||
else
|
||||
lib.removePrefix srcS pathS;
|
||||
|
||||
in builtins.filterSource (path: type:
|
||||
# Strip out .nix files that are in the root of the repository. Changing
|
||||
# the expression of tvix shouldn't cause a rebuild of tvix unless really
|
||||
# required.
|
||||
!(dirOf (asRelative path) == "/" && lib.hasSuffix ".nix" path) &&
|
||||
|
||||
# remove the proto files from the repo as those are compiled separately
|
||||
!(lib.hasPrefix "src/proto" (asRelative path)) &&
|
||||
|
||||
# ignore result symlinks
|
||||
!(type == "symlink" && lib.hasPrefix "result" (baseNameOf path))
|
||||
) srcDir;
|
||||
|
||||
# Proto generation in CMake is theoretically possible, but that is
|
||||
# very theoretical - this does it in Nix instead.
|
||||
protoSrcs = pkgs.runCommand "nix-proto-srcs" {} ''
|
||||
export PROTO_SRCS=${src + "/src/proto"}
|
||||
export PROTO_SRCS=${./src/proto}
|
||||
mkdir -p $out/libproto
|
||||
${pkgs.protobuf}/bin/protoc -I=$PROTO_SRCS \
|
||||
--cpp_out=$out/libproto \
|
||||
|
|
Loading…
Reference in a new issue