nix-vcpkg-cross-experiment/nix/packages/test/package.nix

139 lines
2.8 KiB
Nix
Raw Normal View History

2024-06-22 16:38:19 +02:00
{
lib
, src
, stdenv
, cmake
, vcpkg
, vcpkg-tool
, git
, curl
, cacert
, ninja
, pkg-config
, zip
}:
let
deps = stdenv.mkDerivation {
pname = "test-deps";
version = "0.0.1";
inherit src;
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = {
"x86_64-linux" = "sha256-nFIbhVp32y+TlFLhuLc0XhlGJZmADgKBo4pd78H3mg8=";
# "x86_64-linux" = "";
"aarch64-linux" = "";
"armv7l-linux" = null;
}.${stdenv.hostPlatform.system};
dontConfigure = true;
env = {
VCPKG_ROOT = "${vcpkg}/share/vcpkg";
};
nativeBuildInputs = [
# TODO: is this a direct $PATH dependency of `vcpkg install`?
cmake
# TODO: fix overriding the envvars in build script
# vcpkg
# TODO: wrap these in the $PATH of vcpkg-tool
vcpkg-tool
git
curl
cacert
ninja
zip
# Only for fmt?
pkg-config
];
buildPhase = ''
runHook preBuild
mkdir -p "$out"
vcpkg install \
--x-buildtrees-root="$TMP/vcpkg_buildtrees" \
--x-packages-root="$TMP/vcpkg_packages" \
--only-downloads \
--downloads-root="$out/vcpkg_downloads"
runHook postBuild
'';
# --triplet="$VCPKG_DEFAULT_TRIPLET" \
# --host-triplet="$VCPKG_DEFAULT_HOST_TRIPLET"
dontInstall = true;
};
in
stdenv.mkDerivation {
pname = "test";
version = "0.0.1";
inherit src;
nativeBuildInputs = [
cmake
vcpkg-tool
git
curl
cacert
ninja
zip
];
dontConfigure = true;
env = {
VCPKG_ROOT = "${vcpkg}/share/vcpkg";
};
buildPhase = let
vcpkg-install-opts = lib.concatStringsSep " " [
''--x-buildtrees-root=$TMP/vcpkg_buildtrees''
''--x-packages-root=$TMP/vcpkg_packages''
''--downloads-root=${deps}''
''--x-manifest-root=.''
''--x-install-root=$TMP/vcpkg_installed''
];
cmake-opts = lib.concatStringsSep " " [
(lib.cmakeFeature "VCPKG_INSTALLED_DIR" "$TMP/vcpkg_installed")
(lib.cmakeFeature "VCPKG_TRACE_FIND_PACKAGE" "ON")
(lib.cmakeFeature "VCPKG_MANIFEST_INSTALL" "OFF")
(lib.cmakeFeature "CMAKE_BUILD_TYPE" "Release")
(lib.cmakeFeature "CMAKE_TOOLCHAIN_FILE" "${vcpkg}/share/vcpkg/scripts/buildsystems/vcpkg.cmake")
# (lib.cmakeFeature "CMAKE_CXX_COMPILER" "g++")
# (lib.cmakeFeature "CMAKE_C_COMPILER" "gcc")
# -DVCPKG_INSTALL_OPTIONS="${vcpkg-install-opts}"
];
in ''
runHook preBuild
vcpkg install ${vcpkg-install-opts}
cmake ${cmake-opts} -S . -B build -G Ninja
cmake --build ./build --config Release
runHook postBuild
'';
# dontInstall = true;
installPhase = ''
runHook preInstall
mkdir "$out"
cmake --install ./build --prefix "$out"
runHook postInstall
'';
passthru.deps = deps;
}