-
Notifications
You must be signed in to change notification settings - Fork 88
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
two step builds fail if CMake is used in a build.rs
#285
Comments
Hi, I've tried to replicate it (even with the same dependency, Could you prepare a failing example? |
{
inputs = {
naersk.url = "github:nix-community/naersk";
};
outputs = { nixpkgs, ... } @ inputs: let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
naersk = pkgs.callPackage inputs.naersk { };
in {
packages."x86_64-linux".default = naersk.buildPackage {
nativeBuildInputs = with pkgs; [ rustPlatform.bindgenHook cmake pkg-config ];
buildInputs = with pkgs; [ openssl ];
src = ./.;
};
};
} [package]
name = "minimal"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
oqs-sys = "0.7.2" log of failing build
|
@Patryk27 Yes, sure, above you find everything needed for a minimal example 😄 |
Huh, that's interesting - it does fail when I build it with your expression, but this one seems to work: { ... }:
naersk.buildPackage {
src = ./.;
nativeBuildInputs = with pkgs; [ clang cmake ];
buildInputs = with pkgs; [ openssl ];
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
} Could you check it on your side as well? |
Ah, right, that's probably because |
When CMake builds a project, it generates a file called `CMakeCache.txt` that contains - among others - a dump of environmental variables. This file is generated both for the deps-only- and the main- derivation, and if env-vars happen to differ between both¹, CMake will refuse to compile the latter derivation, saying: ``` CMake Error: The current CMakeCache.txt directory ... is different than the directory ... where CMakeCache.txt was created. ``` Solving this problem is easy - one just has to remove `CMakeCache.txt` to let CMake regenerate it. Note that the original bug report (linked below) suggests to use `sed`, but that doesn't work on Darwin which uses a different convention for temporary paths - compare error messages for the failing derivations: ... on Linux: ``` CMake Error: The current CMakeCache.txt directory /build/source/target/release/build/oqs-sys-a19e222d9ef825d3/out/build/CMakeCache.txt is different than the directory /build/dummy-src/target/release/build/oqs-sys-a19e222d9ef825d3/out/build where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt ``` ... and on Darwin: ``` CMake Error: The current CMakeCache.txt directory /tmp/nix-build-app-0.1.0.drv-5/source/target/release/build/oqs-sys-4b5e25b1671aa1e5/out/build/CMakeCache.txt is different than the directory /tmp/nix-build-app-deps-0.1.0.drv-0/source/target/release/build/oqs-sys-4b5e25b1671aa1e5/out/build where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt ``` As for the implementation, since two-step builds are a Naersk-specific construct, I think solving this transparently on Naersk's side instead of just adding a tip into README.md is the better approach here, since it keeps Naersk plug-and-play'able. Closes #285. ¹ which is not that difficult, e.g. that's how `pkgs.rustPlatform.bindgenHook` behaves
When CMake builds a project, it generates a file called `CMakeCache.txt` that contains - among others - a dump of environmental variables. This file is generated both for the deps-only- and the main- derivation, and if env-vars happen to differ between both¹, CMake will refuse to compile the latter derivation, saying: ``` CMake Error: The current CMakeCache.txt directory ... is different than the directory ... where CMakeCache.txt was created. ``` Solving this problem is easy - one just has to remove `CMakeCache.txt` to let CMake regenerate it. Note that the original bug report (linked below) suggests to use `sed`, but that doesn't work on Darwin which uses a different convention for temporary paths - compare error messages for the failing derivations: ... on Linux: ``` CMake Error: The current CMakeCache.txt directory /build/source/target/release/build/oqs-sys-a19e222d9ef825d3/out/build/CMakeCache.txt is different than the directory /build/dummy-src/target/release/build/oqs-sys-a19e222d9ef825d3/out/build where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt ``` ... and on Darwin: ``` CMake Error: The current CMakeCache.txt directory /tmp/nix-build-app-0.1.0.drv-5/source/target/release/build/oqs-sys-4b5e25b1671aa1e5/out/build/CMakeCache.txt is different than the directory /tmp/nix-build-app-deps-0.1.0.drv-0/source/target/release/build/oqs-sys-4b5e25b1671aa1e5/out/build where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt ``` As for the implementation, since two-step builds are a Naersk-specific construct, I think solving this transparently on Naersk's side instead of just adding a tip into README.md is the better approach here, since it keeps Naersk plug-and-play'able. Closes #285. ¹ which is not that difficult, e.g. that's how `pkgs.rustPlatform.bindgenHook` behaves
When CMake builds a project, it generates a file called `CMakeCache.txt` that contains - among others - a dump of environmental variables. This file is generated both for the deps-only- and the main- derivation, and if env-vars happen to differ between both¹, CMake will refuse to compile the latter derivation, saying: ``` CMake Error: The current CMakeCache.txt directory ... is different than the directory ... where CMakeCache.txt was created. ``` Solving this problem is easy - one just has to remove `CMakeCache.txt` to let CMake regenerate it. Note that the original bug report (linked below) suggests to use `sed`, but that doesn't work on Darwin which uses a different convention for temporary paths - compare error messages for the failing derivations: ... on Linux: ``` CMake Error: The current CMakeCache.txt directory /build/source/target/release/build/oqs-sys-a19e222d9ef825d3/out/build/CMakeCache.txt is different than the directory /build/dummy-src/target/release/build/oqs-sys-a19e222d9ef825d3/out/build where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt ``` ... and on Darwin: ``` CMake Error: The current CMakeCache.txt directory /tmp/nix-build-app-0.1.0.drv-5/source/target/release/build/oqs-sys-4b5e25b1671aa1e5/out/build/CMakeCache.txt is different than the directory /tmp/nix-build-app-deps-0.1.0.drv-0/source/target/release/build/oqs-sys-4b5e25b1671aa1e5/out/build where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt ``` As for the implementation, since two-step builds are a Naersk-specific construct, I think solving this transparently on Naersk's side instead of just adding a tip into README.md is the better approach here, since it keeps Naersk plug-and-play'able. Closes #285. ¹ which is not that difficult, e.g. that's how `pkgs.rustPlatform.bindgenHook` behaves
Some crates with C bindings use CMake to actually build the C library in question. This breaks with two step builds, the error could look like this:
Basically, CMake detects that the target folder was moved around, causing the build to fail. An easy hotfix would be:
Edit: Obviously its more elegant to use this as hotfix:
find -name CMakeCache.txt -exec sed s_/dummy-src/_/source/_g --in-place {} \;
Hiding the evidence that trips of CMake.
The text was updated successfully, but these errors were encountered: