[M8] reusable libraries: install layout + cargoxx-path deps

This commit is contained in:
2026-05-17 18:13:15 +00:00
parent fdf97861a4
commit e6c39914b3
25 changed files with 932 additions and 21 deletions

View File

@@ -0,0 +1,8 @@
#include <nlohmann/json.hpp>
import std;
int main() {
nlohmann::json j;
j["from"] = "extra";
std::println("{}", j["from"].get<std::string>());
return 0;
}

View File

@@ -0,0 +1,7 @@
[package]
name = "consumer"
version = "0.1.0"
edition = "cpp23"
[dependencies]
greeter = { path = "./greeter" }

View File

@@ -0,0 +1,10 @@
{
description = "e2e cargoxx path-dep smoke";
inputs.cargoxx.url = "path:../../..";
outputs = { self, cargoxx }: {
packages.x86_64-linux.default =
cargoxx.lib.x86_64-linux.buildCppPackage { src = ./.; };
};
}

View File

@@ -0,0 +1,4 @@
[package]
name = "greeter"
version = "0.1.0"
edition = "cpp23"

View File

@@ -0,0 +1,8 @@
export module greeter;
import std;
export namespace greeter {
auto hello(std::string_view who) -> std::string {
return std::format("Hello from greeter, {}!", who);
}
} // namespace greeter

48
tests/e2e/pathDep/run.sh Executable file
View File

@@ -0,0 +1,48 @@
#!/usr/bin/env bash
set -euo pipefail
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
repo="$(cd "${here}/../../.." && pwd)"
cargoxx_bin="${CARGOXX_BIN:-${repo}/build/debug/cargoxx}"
if [[ ! -x "${cargoxx_bin}" ]]; then
echo "error: cargoxx binary not found at ${cargoxx_bin}" >&2
echo "build it first: nix develop --command cmake --build build/debug" >&2
exit 1
fi
work="$(mktemp -d -t cargoxx-e2e-pathdep-XXXXXX)"
trap 'rm -rf "${work}"' EXIT
cp -r "${here}/." "${work}/"
sed -i "s|path:\\.\\./\\.\\./\\.\\.|path:${repo}|" "${work}/flake.nix"
cd "${work}"
echo "=== cargoxx build --no-build in greeter (path dep generates its own lock)"
(cd greeter && "${cargoxx_bin}" build --no-build)
echo "=== cargoxx build --no-build in consumer"
"${cargoxx_bin}" build --no-build
[[ -f Cargoxx.lock ]] || { echo "Cargoxx.lock missing"; exit 1; }
grep -q "source_kind = 'cargoxx-path'" Cargoxx.lock || \
{ echo "Cargoxx.lock missing source_kind = cargoxx-path"; exit 1; }
# nix build needs the source tree to be a git tree so 'path:' input copies
# Cargoxx.lock into the store. Init a throwaway git here.
git init -q
git add -A
git -c user.email=e2e@cargoxx -c user.name=e2e commit -q -m fixture
echo "=== nix build .#default"
out="$(nix build .#default --no-link --print-out-paths \
--extra-experimental-features 'nix-command flakes')"
[[ -n "${out}" ]] || { echo "nix build produced no output path"; exit 1; }
[[ -x "${out}/bin/consumer" ]] || { echo "missing ${out}/bin/consumer"; exit 1; }
echo "=== execute"
"${out}/bin/consumer"
echo "ok"

View File

@@ -0,0 +1,7 @@
import std;
import greeter;
int main() {
std::println("{}", greeter::hello("world"));
return 0;
}