-
Git repo reproducig issue: https://github.com/mkatychev/crane_build_rs Hello, I am currently trying to build a workspace package that depends on a [package]
name = "my-package"
version.workspace = true
edition.workspace = true
[[bin]]
path = "src/main.rs"
name = "my-app"
[dependencies]
git-package = { git = "https://github.com/mkatychev/crane_build_rs", rev = "02b264f" } Current problemSince crane creates derivations of vendored dependencies without triggering // git_crate/build.rs
fn main() -> std::io::Result<()> {
std::fs::create_dir("./src/gen")?;
Ok(())
}
Current workaroundMy current workaround involves a # my-workspace/flake.nix
{
description = "build.rs woo";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
crane = { url = "github:ipetkov/crane"; inputs.nixpkgs.follows = "nixpkgs"; };
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, crane, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
# libs
pkgs = import nixpkgs { inherit system; };
inherit (pkgs) lib;
craneLib = crane.lib.${system};
myPackage = craneLib.buildPackage {
inherit src cargoArtifacts;
pname = "my-package";
{
description = "my-package";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
crane = { url = "github:ipetkov/crane"; inputs.nixpkgs.follows = "nixpkgs"; };
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, crane, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
# libs
pkgs = import nixpkgs { inherit system; };
inherit (pkgs) lib;
craneLib = crane.lib.${system};
myPackage = craneLib.buildPackage {
src = ./.;
pname = "my-package";
buildInputs = [ pkgs.protobuf ];
doCheck = true;
# workaround
preBuild = ''
cargo add git-package --git https://github.com/mkatychev/crane_build_rs \
--package my-package --rev cfc475c
'';
cargoExtraArgs = "--package my-package";
};
in
{
# $ nix flake check
checks = {
inherit myPackage ;
};
packages = { default = myPackage; };
});
} Is there a better way to handle this issue? I've seen several other workarounds that deal with permissions and |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
Having # dependency caching
cargoArtifacts = craneLib.buildDepsOnly {
inherit src;
pname = "my-workspace";
buildInputs = [ pkgs.protobuf ];
doCheck = true;
preBuild = ''
export HOME=$(mktemp -d)
'';
# 3. disable `cargo test` in the checkPhase
checkPhaseCargoCommand = "cargoWithProfile check";
};
myPackage = craneLib.buildPackage {
inherit src cargoArtifacts;
pname = "my-package";
buildInputs = [ pkgs.protobuf ];
doCheck = true;
preBuild = ''
export HOME=$(mktemp -d)
'';
cargoExtraArgs = "--package my-package";
checkPhaseCargoCommand = "cargoWithProfile check";
}; |
Beta Was this translation helpful? Give feedback.
-
@ipetkov one of my main issues currently is that derivations are vendored/symlinked then crane/lib/vendorMultipleCargoDeps.nix Lines 63 to 67 in 4bdf559 Is there any way to do the reverse: |
Beta Was this translation helpful? Give feedback.
-
Following the pattern in tikv/client-rust worked excellently. I did write an additional macro that made it easier to deal with codegen that would add suffixes: // src/gen.rs
// crate::gen;
macro_rules! gen_mod {
($package: ident) => {
#[allow(clippy::all)]
pub mod $package {
include!(concat!(
env!("OUT_DIR"),
concat!("/", stringify!($package), ".rs")
));
}
};
($package: ident, $suffix: literal) => {
#[allow(clippy::all)]
pub mod $package {
include!(concat!(
env!("OUT_DIR"),
concat!("/", stringify!($package), $suffix)
));
}
};
}
// crate::gen::generated_pkg;
gen_mod!(generated_pkg);
// crate::gen::generated_pkg_with_suffix;
gen_mod!(generated_pkg_with_suffix, "_api.v1.rs"); |
Beta Was this translation helpful? Give feedback.
Following the pattern in tikv/client-rust worked excellently.
I did write an additional macro that made it easier to deal with codegen that would add suffixes: