initial commit

This commit is contained in:
Oystein Kristoffer Tveit 2024-06-22 16:38:19 +02:00
commit be8e7ecd69
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
10 changed files with 382 additions and 0 deletions

8
.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Nix
result
result-*
# CMAKE/vcpkg
build
vcpkg_*

17
CMakeLists.txt Normal file
View File

@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.16)
project(TestProject LANGUAGES CXX)
find_package(fmt CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
# find_package(fmt REQUIRED)
# find_package(nlohmann_json REQUIRED)
add_executable(test main.cpp)
target_link_libraries(
test
PRIVATE
fmt::fmt
nlohmann_json::nlohmann_json
)

27
flake.lock Normal file
View File

@ -0,0 +1,27 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1718895438,
"narHash": "sha256-k3JqJrkdoYwE3fHE6xGDY676AYmyh4U2Zw+0Bwe5DLU=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "d603719ec6e294f034936c0d0dc06f689d91b6c3",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

59
flake.nix Normal file
View File

@ -0,0 +1,59 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }: let
systems = [
"x86_64-linux"
"x86_64-darwin"
"aarch64-linux"
"aarch64-darwin"
"armv7l-linux"
];
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: let
pkgs = import nixpkgs {
inherit system;
overlays = [
(prev: final: {
vcpkg-tool = final.callPackage ./nix/packages/vcpkg-tool/package.nix { };
})
];
};
in f system pkgs);
inherit (nixpkgs) lib;
in {
packages = forAllSystems (system: pkgs: {
default = self.packages.${system}.test;
test = pkgs.callPackage ./nix/packages/test/package.nix {
src = ./.;
};
});
devShells = forAllSystems (system: pkgs: {
default = self.devShells.${system}.vcpkgVendoredLibs;
vcpkgVendoredLibs = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
vcpkg
cmake
];
env = {
VCPKG_ROOT = "${pkgs.vcpkg}/share/vcpkg";
};
};
nixVendoredLibs = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
cmake
];
buildInputs = with pkgs; [
nlohmann_json
fmt
];
};
});
};
}

23
main.cpp Normal file
View File

@ -0,0 +1,23 @@
#include <fmt/format.h>
#include <nlohmann/json.hpp>
#include <iostream>
int main()
{
nlohmann::json j;
j["pi"] = 3.141;
j["happy"] = true;
j["name"] = "Niels";
j["nothing"] = nullptr;
j["answer"]["everything"] = 42;
j["list"] = {1, 0, 2};
j["object"] = {{"currency", "USD"}, {"value", 42.99}};
std::string s = j.dump();
std::cout << s << std::endl;
nlohmann::json j2 = nlohmann::json::parse(s);
std::cout << j2.dump(4) << std::endl;
return 0;
}

View File

@ -0,0 +1,138 @@
{
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;
}

View File

@ -0,0 +1,14 @@
diff --git a/src/vcpkg/vcpkgpaths.cpp b/src/vcpkg/vcpkgpaths.cpp
index 3f588c21..e6f2bbed 100644
--- a/src/vcpkg/vcpkgpaths.cpp
+++ b/src/vcpkg/vcpkgpaths.cpp
@@ -579,7 +579,8 @@ namespace vcpkg
if (!args.do_not_take_lock)
{
std::error_code ec;
- const auto vcpkg_root_file = root / ".vcpkg-root";
+ fs.create_directories(Path{"/tmp/vcpkg"}, VCPKG_LINE_INFO);
+ const auto vcpkg_root_file = Path{"/tmp/vcpkg"} / Hash::get_string_sha256(root.c_str());
if (args.wait_for_lock.value_or(false))
{
file_lock_handle = fs.take_exclusive_file_lock(vcpkg_root_file, ec);

View File

@ -0,0 +1,77 @@
{ lib
, stdenv
, fetchFromGitHub
, cacert
, cmake
, cmakerc
, fmt
, git
, gzip
, makeWrapper
, meson
, ninja
, openssh
, python3
, zip
, zstd
, extraRuntimeDeps ? []
}:
stdenv.mkDerivation (finalAttrs: {
pname = "vcpkg-tool";
version = "2024-06-10";
src = fetchFromGitHub {
owner = "microsoft";
repo = "vcpkg-tool";
rev = finalAttrs.version;
hash = "sha256-TGRTzUd1FtErD+h/ksUsUm1Rhank9/yVy06JbAgEEw0=";
};
nativeBuildInputs = [
cmake
ninja
makeWrapper
];
buildInputs = [
fmt
cmakerc
];
patches = [
./change-lock-location.patch
];
cmakeFlags = [
"-DVCPKG_DEPENDENCY_EXTERNAL_FMT=ON"
"-DVCPKG_DEPENDENCY_CMAKERC=ON"
];
postFixup = let
# These are the most common binaries used by vcpkg
# Extra binaries can be added via overlay when needed
runtimeDeps = [
cacert
cmake
git
gzip
meson
ninja
openssh
python3
zip
zstd
] ++ extraRuntimeDeps;
in ''
wrapProgram $out/bin/vcpkg --prefix PATH ${lib.makeBinPath runtimeDeps}
'';
meta = {
description = "Components of microsoft/vcpkg's binary";
mainProgram = "vcpkg";
homepage = "https://github.com/microsoft/vcpkg-tool";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ guekka gracicot ];
platforms = lib.platforms.all;
};
})

9
vcpkg-configuration.json Normal file
View File

@ -0,0 +1,9 @@
{
"registries": [
{
"kind": "artifact",
"location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip",
"name": "microsoft"
}
]
}

10
vcpkg.json Normal file
View File

@ -0,0 +1,10 @@
{
"name": "nix-vcpkg-cross-experiment",
"version": "0.0.1",
"description": "Example of (cross) compiling vcpkg-dependant software with nix",
"license": "MIT",
"dependencies": [
"fmt",
"nlohmann-json"
]
}