2023-12-03 14:57:49 +00:00
|
|
|
{
|
|
|
|
buildSystem ? builtins.currentSystem,
|
|
|
|
targetSystem ? buildSystem,
|
|
|
|
gitVersion ? null,
|
|
|
|
release ? false,
|
|
|
|
features ? null,
|
|
|
|
}:
|
2021-10-04 16:27:57 +00:00
|
|
|
|
|
|
|
with import ./nix/common.nix;
|
|
|
|
|
2022-10-13 12:35:39 +00:00
|
|
|
let
|
2023-12-03 14:57:49 +00:00
|
|
|
newBuildTarget = {
|
|
|
|
nixPkgsSystem,
|
|
|
|
rustTarget ? nixPkgsSystem,
|
|
|
|
depsBuildBuild ? pkgsCross: [],
|
|
|
|
}: {
|
|
|
|
inherit nixPkgsSystem rustTarget depsBuildBuild;
|
|
|
|
};
|
2022-07-25 12:58:47 +00:00
|
|
|
|
2023-12-03 14:57:49 +00:00
|
|
|
# centralize per-target configuration in a single place.
|
|
|
|
buildTargets = {
|
|
|
|
"x86_64-linux" = newBuildTarget {
|
|
|
|
nixPkgsSystem = "x86_64-unknown-linux-musl";
|
|
|
|
};
|
|
|
|
|
|
|
|
"i686-linux" = newBuildTarget {
|
|
|
|
nixPkgsSystem = "i686-unknown-linux-musl";
|
|
|
|
};
|
|
|
|
|
|
|
|
"aarch64-linux" = newBuildTarget {
|
|
|
|
nixPkgsSystem = "aarch64-unknown-linux-musl";
|
|
|
|
};
|
|
|
|
|
|
|
|
# Old Raspberry Pi's
|
|
|
|
"armv6l-linux" = newBuildTarget {
|
|
|
|
nixPkgsSystem = "armv6l-unknown-linux-musleabihf";
|
|
|
|
rustTarget = "arm-unknown-linux-musleabihf";
|
|
|
|
};
|
|
|
|
|
|
|
|
"x86_64-windows" = newBuildTarget {
|
|
|
|
nixPkgsSystem = "x86_64-w64-mingw32";
|
|
|
|
rustTarget = "x86_64-pc-windows-gnu";
|
|
|
|
depsBuildBuild = pkgsCross: [
|
|
|
|
pkgsCross.stdenv.cc
|
|
|
|
pkgsCross.windows.pthreads
|
|
|
|
];
|
|
|
|
};
|
2022-02-03 17:04:43 +00:00
|
|
|
};
|
2023-12-03 14:57:49 +00:00
|
|
|
|
|
|
|
buildTarget = buildTargets.${targetSystem};
|
|
|
|
|
|
|
|
pkgs = import pkgsSrc { system = buildSystem; };
|
|
|
|
pkgsCross = import pkgsSrc {
|
|
|
|
system = buildSystem;
|
|
|
|
crossSystem.config = buildTarget.nixPkgsSystem;
|
|
|
|
};
|
|
|
|
|
|
|
|
rustTarget = buildTarget.rustTarget;
|
|
|
|
|
|
|
|
toolchain = let
|
|
|
|
fenix = import (pkgs.fetchFromGitHub {
|
|
|
|
owner = "nix-community";
|
|
|
|
repo = "fenix";
|
|
|
|
rev = "81ab0b4f7ae9ebb57daa0edf119c4891806e4d3a";
|
|
|
|
hash = "sha256-bZmI7ytPAYLpyFNgj5xirDkKuAniOkj1xHdv5aIJ5GM=";
|
|
|
|
}) {
|
|
|
|
system = buildSystem;
|
|
|
|
};
|
|
|
|
|
|
|
|
mkToolchain = fenixTarget: fenixTarget.toolchainOf {
|
|
|
|
channel = "1.68.2";
|
|
|
|
sha256 = "sha256-4vetmUhTUsew5FODnjlnQYInzyLNyDwocGa4IvMk3DM=";
|
|
|
|
};
|
|
|
|
in
|
|
|
|
fenix.combine [
|
|
|
|
(mkToolchain fenix).rustc
|
|
|
|
(mkToolchain fenix).cargo
|
|
|
|
(mkToolchain fenix.targets.${rustTarget}).rust-std
|
|
|
|
];
|
|
|
|
|
|
|
|
naersk = let
|
|
|
|
naerskSrc = pkgs.fetchFromGitHub {
|
|
|
|
owner = "nix-community";
|
|
|
|
repo = "naersk";
|
|
|
|
rev = "d9a33d69a9c421d64c8d925428864e93be895dcc";
|
|
|
|
hash = "sha256-e136hTT7LqQ2QjOTZQMW+jnsevWwBpMj78u6FRUsH9I=";
|
|
|
|
};
|
|
|
|
in
|
|
|
|
pkgs.callPackages naerskSrc {
|
|
|
|
cargo = toolchain;
|
|
|
|
rustc = toolchain;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
# TODO build all of these
|
|
|
|
#build_debug_and_release = (target: {
|
|
|
|
# debug = (compile {
|
|
|
|
# inherit system target gitVersion pkgsSrc cargo2nixOverlay;
|
|
|
|
# release = false;
|
|
|
|
# }).workspace.garage { compileMode = "build"; };
|
|
|
|
|
|
|
|
# release = (compile {
|
|
|
|
# inherit system target gitVersion pkgsSrc cargo2nixOverlay;
|
|
|
|
# release = true;
|
|
|
|
# }).workspace.garage { compileMode = "build"; };
|
|
|
|
#});
|
|
|
|
|
|
|
|
#test = (rustPkgs:
|
|
|
|
# pkgs.symlinkJoin {
|
|
|
|
# name = "garage-tests";
|
|
|
|
# paths =
|
|
|
|
# builtins.map (key: rustPkgs.workspace.${key} { compileMode = "test"; })
|
|
|
|
# (builtins.attrNames rustPkgs.workspace);
|
|
|
|
# });
|
|
|
|
|
|
|
|
builtFeatures = if features != null then
|
|
|
|
features
|
|
|
|
else (
|
|
|
|
[ "garage/bundled-libs" "garage/sled" "garage/lmdb" "garage/k2v" ] ++ (
|
|
|
|
if release then [
|
|
|
|
"garage/consul-discovery"
|
|
|
|
"garage/kubernetes-discovery"
|
|
|
|
"garage/metrics"
|
|
|
|
"garage/telemetry-otlp"
|
2022-10-13 12:35:39 +00:00
|
|
|
"garage/lmdb"
|
|
|
|
"garage/sqlite"
|
2023-12-03 14:57:49 +00:00
|
|
|
] else [ ]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
in {
|
|
|
|
|
|
|
|
inherit pkgs;
|
|
|
|
|
|
|
|
release = naersk.buildPackage rec {
|
|
|
|
inherit release;
|
|
|
|
|
|
|
|
src = ./.;
|
|
|
|
strictDeps = true;
|
|
|
|
doCheck = false;
|
|
|
|
|
|
|
|
depsBuildBuild = (buildTarget.depsBuildBuild pkgsCross) ++ [
|
|
|
|
pkgs.protobuf
|
|
|
|
];
|
|
|
|
|
|
|
|
cargoBuildOptions = prev: prev++[
|
|
|
|
"--features=${builtins.concatStringsSep "," builtFeatures}"
|
|
|
|
];
|
|
|
|
|
|
|
|
OPENSSL_STATIC = "1";
|
|
|
|
OPENSSL_LIB_DIR = "${pkgsCross.pkgsStatic.openssl.out}/lib";
|
|
|
|
OPENSSL_INCLUDE_DIR = "${pkgsCross.pkgsStatic.openssl.dev}/include";
|
|
|
|
|
|
|
|
# Required because ring crate is special. This also seems to have
|
|
|
|
# fixed some issues with the x86_64-windows cross-compile :shrug:
|
|
|
|
TARGET_CC = "${pkgsCross.stdenv.cc}/bin/${pkgsCross.stdenv.cc.targetPrefix}cc";
|
|
|
|
|
|
|
|
CARGO_BUILD_TARGET = rustTarget;
|
|
|
|
CARGO_BUILD_RUSTFLAGS = [
|
|
|
|
"-C" "target-feature=+crt-static"
|
|
|
|
|
|
|
|
# -latomic is required to build openssl-sys for armv6l-linux, but
|
|
|
|
# it doesn't seem to hurt any other builds.
|
|
|
|
"-C" "link-args=-static -latomic"
|
|
|
|
|
|
|
|
# https://github.com/rust-lang/cargo/issues/4133
|
|
|
|
"-C" "linker=${TARGET_CC}"
|
|
|
|
];
|
2022-02-23 10:38:52 +00:00
|
|
|
};
|
2023-12-03 14:57:49 +00:00
|
|
|
|
|
|
|
# TODO
|
|
|
|
#clippy = {
|
|
|
|
# amd64 = (compile {
|
|
|
|
# inherit system gitVersion pkgsSrc cargo2nixOverlay;
|
|
|
|
# target = "x86_64-unknown-linux-musl";
|
|
|
|
# compiler = "clippy";
|
|
|
|
# }).workspace.garage { compileMode = "build"; };
|
|
|
|
#};
|
2022-07-25 12:58:47 +00:00
|
|
|
}
|