Replies: 2 comments 5 replies
-
I was finally able to build let
craneLib = inputs.crane.lib.${system};
crane = craneLib.overrideToolchain rust;
project = crane.crateNameFromCargoToml {cargoToml = ./Cargo.toml;};
target = "x86_64-pc-windows-msvc";
envTarget = builtins.replaceStrings ["-"] ["_"] target;
wlibs = pkgs.stdenvNoCC.mkDerivation {
name = "windows-libs-17";
src = ./windows-libs-17.tar.xz;
sourceRoot = ".";
installPhase = "mkdir $out && cp -R ./* $out";
phases = ["unpackPhase" "installPhase"];
};
libs = [
"${pkgs.libclang.lib}/lib/clang/17/include" # PLACE IT FIRST!
"${wlibs}"
"${wlibs}/sdk/lib"
"${wlibs}/sdk/include"
"${wlibs}/sdk/include/um"
"${wlibs}/sdk/include/ucrt"
"${wlibs}/sdk/include/shared"
"${wlibs}/crt/lib"
"${wlibs}/crt/include"
"${wlibs}/crt/lib/x86_64"
"${wlibs}/sdk/lib/um/x86_64"
"${wlibs}/sdk/lib/ucrt/x86_64"
];
common =
project
// rec {
src = fileset.toSource {
root = ./.;
fileset = fileset.unions [
./src/script.js
./src/dev.js
./resources.res
./resources.rc
./ic.ico
(fileset.fromSource (cleanSourceWith {
src = ./.;
filter = craneLib.filterCargoSources;
}))
];
};
doCheck = false;
buildInputs = with pkgs; [clang libclang libclang.lib libllvm lld openssl openssl.dev wlibs];
nativeBuildInputs = with pkgs; [pkg-config] ++ buildInputs;
depsBuildBuild = nativeBuildInputs;
"CARGO_BUILD_RUSTFLAGS" = concatStringsSep " " ([
"-Clinker-flavor=lld-link"
]
++ map (l: "-Lnative=${l}") libs);
"CARGO_BUILD_TARGET" = target;
"CARGO_TARGET_${toUpper envTarget}_LINKER" = "lld-link";
"CARGO_TARGET_${toUpper envTarget}_RUNNER" = toUpper envTarget;
"TARGET_CC" = "clang-cl";
"TARGET_CXX" = TARGET_CC;
"CC_${envTarget}" = TARGET_CC;
"CCX_${envTarget}" = TARGET_CC;
"TARGET_AR" = "llvm-lib";
"AR_${envTarget}" = TARGET_AR;
"CL_FLAGS" = concatStringsSep " " ([
"--target=${target}"
"-Wno-unused-command-line-argument"
"-fuse-ld=lld-link"
]
++ map (str: "/imsvc${str}") libs);
"CFLAGS_${envTarget}" = CL_FLAGS;
"CXXFLAGS_${envTarget}" = CL_FLAGS;
"RC_FLAGS" = concatStringsSep " " ([] ++ map (str: "-I${str}") libs);
"BINDGEN_EXTRA_CLANG_ARGS_${envTarget}" = RC_FLAGS;
dontFixup = true;
dontStrip = true;
};
cargoArtifacts = crane.buildDepsOnly common;
in
crane.buildPackage (common // {inherit cargoArtifacts;}); |
Beta Was this translation helpful? Give feedback.
0 replies
-
btw seems like there is a problem now: dependencies are always rebuilding |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
With cargo-xwin I can successfully build my project to MSVC target. But I’m unable to write Nix derivation to do it using crane.
I tried to replicate cargo-xwin behaviour using source code
output of sucessful build via cargo-xwin
https://0x0.st/Xrck.txt
output of failed build in Nix
https://0x0.st/XrcD.txt
Most notable:
Could you please suggest ideas for fixing this?
Beta Was this translation helpful? Give feedback.
All reactions