Merge branch 'claude/project-dependencies': project.cpp dependencies, AGENTS.md
Some checks failed
CI / build-test-release (push) Failing after 4m7s
CI / release-musl (push) Has been skipped

Brings in `#pragma crafter dependency`, the switch to Crafter.LintRules
for the house style, and the contributor guide in AGENTS.md.

The branch predates the musl host work on master, and both rewrote the
command that compiles project.so, so the merge reconciles them by hand:

- LoadProject compiles project.so for hostConfig.target (HostTarget(),
  from master) with the pre-dependency module path and archives from
  the branch. -fuse-ld=lld appears once, with both reasons in the
  comment.
- ForceHostTooling added -fPIC only for the literal x86_64-pc-linux-gnu
  triple. hostConfig now comes from HostTarget(), so on Alpine the host
  is x86_64-alpine-linux-musl and the dependency archive would not have
  been position-independent. It now matches any *-linux-gnu or
  *-linux-musl host, as project.cpp and the cmake flags do since the
  musl change, and its comment no longer argues against HostTarget().
- The ProjectDependency test compared the dependency's target against
  the glibc triple, which the musl CI job would fail; it compares
  against HostTarget().
- README keeps master's paragraph on the bootstrap triple. AGENTS.md
  describes the test block as `if (linuxTarget)`, which is what
  project.cpp has now.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Jorijn van der Graaf 2026-10-02 20:47:23 +02:00
commit c3d97be59e
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
18 changed files with 784 additions and 1635 deletions

View file

@ -265,6 +265,21 @@ fs::path Crafter::StdPcmDir(const Configuration& config) {
return GetCacheDir()/stdPcmKey;
}
fs::path Crafter::ExpectedOutput(const Configuration& config) {
const fs::path dir = config.BinDir();
const bool windowsTarget = config.target == "x86_64-w64-mingw32" || config.target == "x86_64-pc-windows-msvc";
if (config.type == ConfigurationType::Executable) {
if (config.target.starts_with("wasm32")) return dir / std::format("{}.wasm", config.outputName);
return config.target == "x86_64-w64-mingw32" ? dir / std::format("{}.exe", config.outputName) : dir / config.outputName;
}
if (config.type == ConfigurationType::LibraryStatic) {
return windowsTarget ? dir / std::format("{}.lib", config.outputName) : dir / std::format("lib{}.a", config.outputName);
}
// LibraryDynamic — the .dll on Windows targets so an mtime check sees the
// freshly linked library; on Unix the .so is that file.
return windowsTarget ? dir / std::format("{}.dll", config.outputName) : dir / std::format("lib{}.so", config.outputName);
}
CompileCommand Crafter::GetCompileCommand(const Configuration& config) {
CompileCommand out;
out.stdPcmDir = StdPcmDir(config);
@ -1042,34 +1057,13 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
// was rebuilt by an earlier run (so dep.repack is false this time around)
// but the consumer was never relinked against the new dep.
{
auto expectedOutputFor = [](const Configuration& c) -> fs::path {
fs::path dir = c.BinDir();
if (c.type == ConfigurationType::Executable) {
if (c.target.starts_with("wasm32")) return dir / (std::format("{}.wasm", c.outputName));
return c.target == "x86_64-w64-mingw32"
? dir / (std::format("{}.exe", c.outputName))
: dir / c.outputName;
}
if (c.type == ConfigurationType::LibraryStatic) {
return c.target == "x86_64-w64-mingw32" || c.target == "x86_64-pc-windows-msvc"
? dir / std::format("{}.lib", c.outputName)
: dir / std::format("lib{}.a", c.outputName);
}
// LibraryDynamic — point at the .dll on Windows targets so the
// mtime check sees the newly-built DLL; on Unix the .so suffices.
if (c.target == "x86_64-w64-mingw32" || c.target == "x86_64-pc-windows-msvc") {
return dir / std::format("{}.dll", c.outputName);
}
return dir / std::format("lib{}.so", c.outputName);
};
fs::path expected = expectedOutputFor(config);
fs::path expected = ExpectedOutput(config);
if (!fs::exists(expected)) {
buildResult.repack = true;
} else {
auto consumerMtime = fs::last_write_time(expected);
for (Configuration* dep : config.dependencies) {
fs::path depArtifact = expectedOutputFor(*dep);
fs::path depArtifact = ExpectedOutput(*dep);
if (fs::exists(depArtifact) && fs::last_write_time(depArtifact) > consumerMtime) {
buildResult.repack = true;
break;
@ -1786,13 +1780,7 @@ std::int32_t Crafter::Run(std::int32_t argc, char** argv) {
return 1;
}
fs::path dir = config.BinDir();
fs::path artifact = dir / config.outputName;
if (config.target.starts_with("wasm32")) {
artifact += ".wasm";
} else if (config.target == "x86_64-w64-mingw32" || config.target == "x86_64-pc-windows-msvc") {
artifact += ".exe";
}
artifact = fs::absolute(artifact);
fs::path artifact = fs::absolute(ExpectedOutput(config));
fs::path absDir = fs::absolute(dir);
// wasm targets need either a wasm runtime (wasi-cli) or an HTTP