-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failing to compile with locally vendored (patched) package #400
Comments
Deps only derivation stripped this package out of the source code thinking it's the local one (because it is?). Look into how the deps only mkDummySrc works and issues before. Quick fix to unblock would be probably to put it into a git repo, and patch it from there, until you have a better workaround. |
Thanks for the pointers! Unfortunately it would be a much larger change for us to push our vendored deps into a separate repo, so I'm trying to see if I can use It's not immediately obvious to me though how a packages.my-pkg =
let
baseArgs = {
pname = "my-pkg";
version = "${revision}";
cargoExtraArgs = "-p my-pkg";
doCheck = false;
};
in
craneLib.buildPackage (baseArgs // {
cargoArtifacts = craneLib.buildDepsOnly (baseArgs // {
installCargoArtifactsMode = "use-zstd";
installPhase = "prepareAndInstallCargoArtifactsDir";
dummySrc = craneLib.mkDummySrc {
src = craneLib.cleanCargoSource (craneLib.path ./.);
extraDummyScript = ''
set -exuo pipefail
cp -rf ${./.vendor} $out/.vendor
'';
};
});
}); This fails in the same way as before, and looking at the log output, I'm seeing the message: Am I going in the right direction with the Thanks for any help you can provide. |
It's probably best to split |
Thanks for your continued help! I managed to get the files included with something like this (the let
commonInputs = [ pkgs.openssl ];
commonArgs = {
src = dummySrc;
nativeBuildInputs = [
pkgs.lld
pkgs.pkg-config
] ++ commonInputs;
pname = "my-pkg";
version = "${revision}";
preInstall = "echo 'hello'";
SQLX_OFFLINE = "true";
OPENSSL_DIR = "${pkgs.openssl.dev.outPath}";
OPENSSL_LIB_DIR = "${pkgs.openssl.out.outPath}/lib";
};
dummySrc = craneLib.mkDummySrc {
src = craneLib.path ./.;
extraDummyScript = ''
set -exuo pipefail
cp -rf --no-target-directory ${./.vendor} $out/.vendor
ls $out/.vendor/actix-http/src
'';
};
cargoArtifacts = craneLib.buildDepsOnly (commonArgs // {
inherit dummySrc;
});
in
craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts;
cargoExtraArgs = "-p my-pkg";
doCheck = false;
buildInputs = commonInputs;
}); This is maybe a separate issue, but I'm now running into an error after the check phase:
My actual |
It might be due to that |
Oh, good catch! |
Okay, this has gotten me pretty close. Now I get a bunch of warnings about what seems to be an unrelated duplicate local crate, and a permissions error related to an rlib:
Do you think this is related to my I don't get the same error if I invoke This isn't one of the packages that's in the |
The warnings are ... warnings. So it's only the
Put some debug code in the bash hooks before this step and verify the permissions and why it's not writable. |
Hmmm.. You need
in all args (or use some common args pattern to merge them into everything). |
Ah, that did it! Finally got a build to complete. Thanks so much for all your help 🎉 Very excited to be able to do much better caching of our dependency tree in CI |
Just for the sake of anyone else who finds this issue, the working version is: packages.my-pkg =
let
revision = self.rev or "dev";
commonInputs = [ pkgs.openssl ];
dummySrc = craneLib.mkDummySrc {
src = craneLib.path ./.;
extraDummyScript = ''
set -exuo pipefail
cp -rf --no-target-directory ${./.vendor} $out/.vendor
'';
};
commonArgs = {
src = dummySrc;
installCargoArtifactsMode = "use-zstd";
nativeBuildInputs = [
pkgs.lld
pkgs.pkg-config
] ++ commonInputs;
buildInputs = commonInputs;
cargoExtraArgs = "-p my-pkg";
version = "${revision}";
doCheck = false;
SQLX_OFFLINE = "true";
OPENSSL_DIR = "${pkgs.openssl.dev.outPath}";
OPENSSL_LIB_DIR = "${pkgs.openssl.out.outPath}/lib";
};
cargoArtifacts = craneLib.buildDepsOnly (commonArgs // {
inherit dummySrc;
pname = "my-pkg-deps";
});
in
craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts;
src = craneLib.cleanCargoSource (craneLib.path ./.);
pname = "my-pkg";
}); |
If you're interested in ultra-optimized CI, let's stay in touch . I recommend keeping your eye on Flakebox, try the upcoming incremental zstd change and some discussion about it. There's are so many rarely employed ways to optimize Rust building both in the dev shell and in the CI, and I'd love for them to become more common place. |
I am absolutely interested, yes. We've got a few fairly large Rust projects, local tools written in Rust, and Rust WASM builds incorporated into our FE stack, so we do a lot of building, both locally and in CI. We've also got cross-compilation needs, since a lot of our devs are on M-series macs and still need to be able to build linux binaries and images. We've so far mostly used nix just for consistent dev environments and docker image builds, but I'm just switching us over from niv to flakes, largely to be able to use projects like crane so that we can build more quickly and avoid spurious rebuilds. Thanks for all the links! We're using |
At Fedimint we solved all of these and some: https://github.com/fedimint/fedimint/actions/runs/6341294780 |
1.5 years on and I had totally forgotten about this, was just bitten by it again with a locally vendored package. I'm gong to reopen, b/c even though there is a workaround, it would be nice if crane handled patches more cleanly in this case. |
Hello,
We have a situation where we've had to apply a patch to some upstream code, so we have vendored the code locally using
cargo clone
, and we are patching it in ourCargo.toml
like so:We don't depend on
actix-http
directly: instead it's required byactix-web
, which we do depend on.However, when building a workspace package that depends on
actix-web
(by setting-p <package_name>
incargoExtraArgs
), we get errors like:Essentially, everywhere
actix_web
tries to useactix_http
, it seems to think it's an empty package with no symbols defined.I have verified that the vendored code is making it into the source directory in the nix store.
I have also verified that the patch directive is making it into the
Cargo.toml
at the root of the source directory.I have tried explicitly requiring
actix-http = { path: "../../.vendor/actix-http" }
in the project'sCargo.toml
, but this doesn't seem to help.Building the same package using
buildRustPackage
works without issues.I'm continuing to debug, but if I'm missing something obvious or if you've got any suggestions for figuring out what's going on, please let me know.
The text was updated successfully, but these errors were encountered: