2024-03-06 14:38:27 +03:00
|
|
|
# This is a function that returns a derivation for the compiled Rust project.
|
|
|
|
{ craneLib
|
|
|
|
, lib
|
2024-03-06 20:50:32 +03:00
|
|
|
, version
|
2024-03-06 14:38:27 +03:00
|
|
|
, stdenv
|
|
|
|
, openssl
|
|
|
|
, libiconv
|
|
|
|
, pkg-config
|
|
|
|
, protobuf
|
|
|
|
, darwin
|
2024-04-26 11:43:19 +03:00
|
|
|
, pname
|
2024-03-06 14:38:27 +03:00
|
|
|
}:
|
|
|
|
let
|
|
|
|
buildArgs = {
|
2024-04-26 11:43:19 +03:00
|
|
|
inherit pname;
|
2024-03-06 14:38:27 +03:00
|
|
|
|
|
|
|
src =
|
|
|
|
let
|
|
|
|
isGraphqlFile = path: _type: builtins.match ".*graphql" path != null;
|
2024-03-06 20:50:32 +03:00
|
|
|
isHtmlFile = path: _type: builtins.match ".*html" path != null;
|
|
|
|
isJsonFile = path: _type: builtins.match ".*json" path != null;
|
2024-03-06 14:38:27 +03:00
|
|
|
isSourceFile = path: type:
|
2024-03-06 20:50:32 +03:00
|
|
|
isGraphqlFile path type
|
|
|
|
|| isHtmlFile path type
|
|
|
|
|| isJsonFile path type
|
2024-03-06 14:38:27 +03:00
|
|
|
|| craneLib.filterCargoSources path type;
|
|
|
|
in
|
|
|
|
lib.cleanSourceWith { src = craneLib.path ./..; filter = isSourceFile; };
|
|
|
|
|
|
|
|
buildInputs = [
|
|
|
|
openssl
|
|
|
|
] ++ lib.optionals stdenv.hostPlatform.isDarwin [
|
|
|
|
libiconv
|
|
|
|
darwin.apple_sdk.frameworks.Security
|
|
|
|
darwin.apple_sdk.frameworks.SystemConfiguration
|
|
|
|
];
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
pkg-config # required for non-static builds
|
|
|
|
protobuf # required by opentelemetry-proto, a dependency of axum-tracing-opentelemetry
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2024-04-26 11:43:19 +03:00
|
|
|
# only build the binary we care about
|
2024-05-02 17:22:44 +03:00
|
|
|
cargoExtraArgs = "--package ${buildArgs.pname}";
|
2024-04-26 11:43:19 +03:00
|
|
|
|
2024-03-06 14:38:27 +03:00
|
|
|
# Build the dependencies first.
|
2024-05-02 17:22:44 +03:00
|
|
|
cargoArtifacts = craneLib.buildDepsOnly (buildArgs //
|
|
|
|
{
|
|
|
|
# without this we'll build deps for the entire workspace every time
|
|
|
|
buildPhaseCargoCommand = "cargo build --profile $CARGO_PROFILE --package ${buildArgs.pname}";
|
|
|
|
doCheck = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
2024-03-06 14:38:27 +03:00
|
|
|
in
|
|
|
|
# Then build the crate.
|
|
|
|
craneLib.buildPackage
|
|
|
|
(buildArgs // {
|
2024-04-26 11:43:19 +03:00
|
|
|
inherit cargoArtifacts cargoExtraArgs;
|
2024-03-06 14:38:27 +03:00
|
|
|
doCheck = false;
|
2024-03-06 20:50:32 +03:00
|
|
|
RELEASE_VERSION = version;
|
2024-03-06 14:38:27 +03:00
|
|
|
})
|