-
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
Showing
5 changed files
with
139 additions
and
192 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# This is a function that returns a derivation for the compiled Rust project. | ||
{ craneLib | ||
, lib | ||
, hostPlatform | ||
, openssl | ||
, libiconv | ||
, pkg-config | ||
, protobuf | ||
, darwin | ||
}: | ||
let | ||
buildArgs = { | ||
pname = "ndc-bigquery"; | ||
version = "0.1.0"; | ||
|
||
src = | ||
let | ||
isJsonFile = path: _type: builtins.match ".*json" path != null; | ||
isSqlFile = path: _type: builtins.match ".*sql" path != null; | ||
isSourceFile = path: type: | ||
isJsonFile path type | ||
|| isSqlFile path type | ||
|| craneLib.filterCargoSources path type; | ||
in | ||
lib.cleanSourceWith { src = craneLib.path ./..; filter = isSourceFile; }; | ||
|
||
strictDeps = true; | ||
|
||
# build-time inputs | ||
nativeBuildInputs = [ | ||
openssl.dev # required to build Rust crates that can conduct TLS connections | ||
pkg-config # required to find OpenSSL | ||
]; | ||
|
||
# runtime inputs | ||
buildInputs = [ | ||
openssl # required for TLS connections | ||
protobuf # required by opentelemetry-proto, a dependency of axum-tracing-opentelemetry | ||
] ++ lib.optionals hostPlatform.isDarwin [ | ||
# macOS-specific dependencies | ||
libiconv | ||
darwin.apple_sdk.frameworks.CoreFoundation | ||
darwin.apple_sdk.frameworks.Security | ||
darwin.apple_sdk.frameworks.SystemConfiguration | ||
]; | ||
}; | ||
|
||
# Build the dependencies first. | ||
cargoArtifacts = craneLib.buildDepsOnly buildArgs; | ||
in | ||
# Then build the crate. | ||
craneLib.buildPackage | ||
(buildArgs // { | ||
inherit cargoArtifacts; | ||
doCheck = false; | ||
}) |
This file was deleted.
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Sets up our Rust toolchain and Crane for cross-compilation. | ||
# This is mostly a copy of the example provided at: | ||
# https://crane.dev/examples/cross-rust-overlay.html | ||
{ nixpkgs | ||
, rust-overlay | ||
, crane | ||
, localSystem | ||
, crossSystem ? localSystem | ||
}: | ||
let | ||
pkgs = import nixpkgs { | ||
inherit crossSystem localSystem; | ||
overlays = [ rust-overlay.overlays.default ]; | ||
}; | ||
|
||
lib = pkgs.pkgsBuildHost.lib; | ||
|
||
# Converts host system string for use in environment variable names | ||
envCase = triple: lib.strings.toUpper (builtins.replaceStrings [ "-" ] [ "_" ] triple); | ||
|
||
# `hostPlatform` is the cross-compilation output platform; | ||
# `buildPlatform` is the platform we are compiling on | ||
buildPlatform = pkgs.stdenv.buildPlatform; | ||
hostPlatform = pkgs.stdenv.hostPlatform; | ||
|
||
# When possibly cross-compiling we get several versions of nixpkgs of the | ||
# form, `pkgs.pkgs<where it runs><platform it produces outputs for>`. We use | ||
# `pkgs.pkgsBuildHost` to get packages that run at build time (so run on the | ||
# build platform), and that produce outputs for the host platform which is the | ||
# cross-compilation target. | ||
rustBin = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ../rust-toolchain.toml; | ||
rustToolchain = rustBin.override { targets = [ hostPlatform.config ]; }; | ||
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain; | ||
|
||
buildEnv = { | ||
CARGO_BUILD_TARGET = hostPlatform.config; | ||
"CARGO_TARGET_${envCase hostPlatform.config}_LINKER" = "${pkgs.stdenv.cc.targetPrefix}cc"; | ||
|
||
# This environment variable 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 = "${pkgs.stdenv.cc.nativePrefix}cc"; | ||
}; | ||
in | ||
{ | ||
inherit rustToolchain; | ||
|
||
callPackage = (package: args: | ||
# Call the package, providing `craneLib` as an extra. | ||
let crate = pkgs.callPackage package (args // { inherit craneLib; }); | ||
in | ||
# Override the derivation to add cross-compilation environment variables. | ||
crate.overrideAttrs (previous: buildEnv // { | ||
# We also have to override the `cargoArtifacts` derivation with the same changes. | ||
cargoArtifacts = previous.cargoArtifacts.overrideAttrs (previous: buildEnv); | ||
})); | ||
} |