Closed mitchty closed 1 year ago
Hi @mitchty thanks for mentioning this! Yes those changes would be great as a PR and much appreciated 🙏 😄
Multiple times I had to add not only iconv
, but also darwin.apple_sdk.frameworks.Security
BTW.
Perhaps this is a bit simpler/less redundancy? Would make it pretty easy to add specific inputs such as the macos frameworks too though those tend to crop up when you need them.
I'm not sure if it makes sense to always specify a blank buildInputs to each of the functions but this seems to pass nix flake check which the above didn't. Not sure if the doc/fmt/audit checks need the build inputs too, least they don't seem to when I run it but haven't tried a more complex setup yet.
modified flake.nix
@@ -24,21 +24,25 @@
inherit system;
};
- inherit (pkgs) lib;
+ inherit (pkgs) lib stdenv;
craneLib = crane.lib.${system};
src = craneLib.cleanCargoSource ./.;
+ # If one needs to customize the build environment here is where to add
+ # to it, mostly only needed for macos
+ buildInputs = [] ++ lib.optionals stdenv.isDarwin [ pkgs.libiconv ];
+
# Build *just* the cargo dependencies, so we can reuse
# all of that work (e.g. via cachix) when running in CI
cargoArtifacts = craneLib.buildDepsOnly {
- inherit src;
+ inherit src buildInputs;
};
# Build the actual crate itself, reusing the dependency
# artifacts from above.
my-crate = craneLib.buildPackage {
- inherit cargoArtifacts src;
+ inherit cargoArtifacts src buildInputs;
};
in
{
@@ -53,7 +57,7 @@
# we can block the CI if there are issues here, but not
# prevent downstream consumers from building our crate by itself.
my-crate-clippy = craneLib.cargoClippy {
- inherit cargoArtifacts src;
+ inherit cargoArtifacts src buildInputs;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
};
@@ -75,7 +79,7 @@
# Consider setting `doCheck = false` on `my-crate` if you do not want
# the tests to run twice
my-crate-nextest = craneLib.cargoNextest {
- inherit cargoArtifacts src;
+ inherit cargoArtifacts src buildInputs;
partitions = 1;
partitionType = "count";
};
@@ -100,7 +104,7 @@
nativeBuildInputs = with pkgs; [
cargo
rustc
- ];
+ ] ++ buildInputs;
};
});
}
Not a huge deal but figured before I did the work to get a pr up anyone that might want to use crane with nix on darwin might want to know what needs to be changed/fixed.
After I ran nix flake init -t github:ipetkov/crane I had to do the following to get the default flake to build:
As far as I know this is a macos nix thing where due to it depending on libiconv implicitly, you have to add that as a dependency for both cargo and your native build inputs. Otherwise you end up with this barf of output:
Otherwise great utility just hit this snag when trying to use it on macos nix. Would this be ok to pr roughly as-is?