-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
238e7b7
commit 3505a15
Showing
7 changed files
with
301 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
{ | ||
# Flake inputs | ||
inputs | ||
# The system that we are compiling on | ||
, localSystem | ||
# The target system that we are cross-compiling for | ||
, crossSystem | ||
# The target that Rust should be configured to use | ||
, rustTargetTriple | ||
, ... | ||
}: | ||
let | ||
inherit (inputs) nixpkgs crane rust-overlay; | ||
|
||
common = import ./common.nix { }; | ||
|
||
pkgs = import nixpkgs { | ||
inherit crossSystem localSystem; | ||
overlays = [ (import rust-overlay) ]; | ||
}; | ||
|
||
rustToolchain = pkgs.pkgsBuildHost.rust-bin.stable.latest.default.override { | ||
targets = [ rustTargetTriple ]; | ||
}; | ||
|
||
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain; | ||
|
||
# Note: we have to use the `callPackage` approach here so that Nix | ||
# can "splice" the packages in such a way that dependencies are | ||
# compiled for the appropriate targets. If we did not do this, we | ||
# would have to manually specify things like | ||
# `nativeBuildInputs = with pkgs.pkgsBuildHost; [ someDep ];` or | ||
# `buildInputs = with pkgs.pkgsHostHost; [ anotherDep ];`. | ||
# | ||
# Normally you can stick this function into its own file and pass | ||
# its path to `callPackage`. | ||
crateExpression = | ||
{ lib | ||
, pkg-config | ||
, go | ||
, perl | ||
, stdenv | ||
}: | ||
let | ||
lairKeystoreCommon = common.lair-keystore { inherit lib craneLib; lair-keystore = inputs.lair-keystore; }; | ||
|
||
commonArgs = { | ||
# Just used for building the workspace, will be replaced when building a specific crate | ||
pname = "default"; | ||
version = "0.0.0"; | ||
|
||
# Load source with a custom filter so we can include non-cargo files that get used during the build | ||
src = lairKeystoreCommon.src; | ||
|
||
# We don't want to run tests | ||
doCheck = false; | ||
|
||
strictDeps = true; | ||
|
||
# Dependencies which need to be built for the current platform | ||
# on which we are doing the cross compilation. In this case, | ||
# pkg-config needs to run on the build platform so that the build | ||
# script can find the location of openssl. Note that we don't | ||
# need to specify the rustToolchain here since it was already | ||
# overridden above. | ||
nativeBuildInputs = [ | ||
pkg-config | ||
stdenv.cc | ||
perl | ||
]; | ||
|
||
# Tell cargo about the linker and an optional emulater. So they can be used in `cargo build` | ||
# and `cargo run`. | ||
# Environment variables are in format `CARGO_TARGET_<UPPERCASE_UNDERSCORE_RUST_TRIPLE>_LINKER`. | ||
# They are also be set in `.cargo/config.toml` instead. | ||
# See: https://doc.rust-lang.org/cargo/reference/config.html#target | ||
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER = "${stdenv.cc.targetPrefix}cc"; | ||
CARGO_TARGET_x86_64_UNKNOWN_LINUX_GNU_LINKER = "${stdenv.cc.targetPrefix}cc"; | ||
CARGO_TARGET_AARCH64_UNKNOWN_APPLE_LINKER = "${stdenv.cc.targetPrefix}cc"; | ||
|
||
# Tell cargo which target we want to build (so it doesn't default to the build system). | ||
cargoExtraArgs = "--target ${rustTargetTriple}"; | ||
|
||
# These environment variables may be necessary if any of your dependencies use a | ||
# build-script which invokes the `cc` crate to build some other code. The `cc` crate | ||
# should automatically pick up on our target-specific linker above, but this may be | ||
# necessary if the build script needs to compile and run some extra code on the build | ||
# system. | ||
HOST_CC = "${stdenv.cc.nativePrefix}cc"; | ||
TARGET_CC = "${stdenv.cc.targetPrefix}cc"; | ||
}; | ||
|
||
# Build *just* the Cargo dependencies (of the entire workspace), | ||
# so we can reuse all of that work (e.g. via cachix) when running in CI | ||
# It is *highly* recommended to use something like cargo-hakari to avoid | ||
# cache misses when building individual top-level-crates | ||
cargoArtifacts = craneLib.buildDepsOnly commonArgs; | ||
in | ||
craneLib.buildPackage (commonArgs // { | ||
pname = "lair-keystore"; | ||
version = lairKeystoreCommon.crateInfo.version; | ||
|
||
inherit cargoArtifacts; | ||
|
||
cargoExtraArgs = "${commonArgs.cargoExtraArgs} --package lair_keystore"; | ||
}); | ||
in | ||
# Dispatch the crate expression to run the cross compile | ||
pkgs.callPackage crateExpression { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{ | ||
# Flake inputs | ||
inputs | ||
# The system that we are compiling on | ||
, localSystem | ||
}: | ||
let | ||
inherit (inputs) nixpkgs crane fenix; | ||
|
||
common = import ./common.nix { }; | ||
|
||
pkgs = nixpkgs.legacyPackages.${localSystem}; | ||
|
||
toolchain = with fenix.packages.${localSystem}; | ||
combine [ | ||
minimal.rustc | ||
minimal.cargo | ||
targets.x86_64-pc-windows-gnu.latest.rust-std | ||
]; | ||
|
||
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; | ||
|
||
lairKeystoreCommon = common.lair-keystore { inherit craneLib; lib = pkgs.lib; lair-keystore = inputs.lair-keystore; }; | ||
|
||
libsodium = common.mkLibSodium pkgs; | ||
|
||
commonArgs = { | ||
# Just used for building the workspace, will be replaced when building a specific crate | ||
pname = "default"; | ||
version = "0.0.0"; | ||
|
||
# Load source with a custom filter so we can include non-cargo files that get used during the build | ||
src = lairKeystoreCommon.src; | ||
|
||
strictDeps = true; | ||
doCheck = false; | ||
|
||
CARGO_BUILD_TARGET = "x86_64-pc-windows-gnu"; | ||
|
||
# fixes issues related to libring | ||
TARGET_CC = "${pkgs.pkgsCross.mingwW64.stdenv.cc}/bin/${pkgs.pkgsCross.mingwW64.stdenv.cc.targetPrefix}cc"; | ||
|
||
# Otherwise tx5-go-pion-sys picks up the host linker instead of the cross linker | ||
RUSTC_LINKER = "${pkgs.pkgsCross.mingwW64.stdenv.cc}/bin/${pkgs.pkgsCross.mingwW64.stdenv.cc.targetPrefix}cc"; | ||
|
||
SODIUM_LIB_DIR = "${libsodium}/lib"; | ||
|
||
nativeBuildInputs = with pkgs; [ | ||
perl | ||
]; | ||
|
||
depsBuildBuild = with pkgs; [ | ||
pkgsCross.mingwW64.stdenv.cc | ||
pkgsCross.mingwW64.windows.pthreads | ||
]; | ||
}; | ||
|
||
# Build *just* the Cargo dependencies (of the entire workspace), | ||
# so we can reuse all of that work (e.g. via cachix) when running in CI | ||
# It is *highly* recommended to use something like cargo-hakari to avoid | ||
# cache misses when building individual top-level-crates | ||
cargoArtifacts = craneLib.buildDepsOnly commonArgs; | ||
in | ||
craneLib.buildPackage (commonArgs // { | ||
pname = "lair_keystore"; | ||
version = lairKeystoreCommon.crateInfo.version; | ||
|
||
inherit cargoArtifacts; | ||
|
||
cargoExtraArgs = "--package lair_keystore"; | ||
}) |