From a25b0a1ded5963e37c7f96ab787199744f2a7e81 Mon Sep 17 00:00:00 2001 From: Jorijn van der Graaf Date: Wed, 22 Jul 2026 18:25:39 +0200 Subject: [PATCH] wasm flags update --- implementations/Crafter.Build-Clang.cpp | 21 ++------------ implementations/Crafter.Build-Platform.cpp | 33 +++++++++++----------- implementations/Crafter.Build-Test.cpp | 30 ++++++++------------ interfaces/Crafter.Build-Clang.cppm | 28 ++++-------------- tests/StandardArgs/main.cpp | 16 +++++++++++ 5 files changed, 52 insertions(+), 76 deletions(-) diff --git a/implementations/Crafter.Build-Clang.cpp b/implementations/Crafter.Build-Clang.cpp index e2d89ef..0648fbf 100644 --- a/implementations/Crafter.Build-Clang.cpp +++ b/implementations/Crafter.Build-Clang.cpp @@ -1,21 +1,5 @@ -/* -Crafter® Build -Copyright (C) 2026 Catcrafts® -Catcrafts.net - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License version 3.0 as published by the Free Software Foundation; - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ +//SPDX-License-Identifier: LGPL-3.0-only +//SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts® module; #if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32) @@ -1441,6 +1425,7 @@ ArgQuery Crafter::ApplyStandardArgs(Configuration& cfg, std::span/../include/c++/v1) above --sysroot, so + // the PCM would mix host libc++ with the foreign libc — force the + // sysroot's copy (same trick as the Windows LIBCXX_DIR path) + if (!isWasm && !config.sysroot.empty()) { + archFlags += std::format(" -nostdinc++ -isystem {}/usr/include/c++/v1", config.sysroot); + } if(!fs::exists(stdPcm) || fs::last_write_time(stdPcm) < fs::last_write_time(stdCppm)) { return RunCommand(std::format("clang++ --target={} -std=c++26 -stdlib=libc++{}{} -O3 -Wno-reserved-identifier -Wno-reserved-module-identifier --precompile {} -o {}", config.target, sysrootFlag, archFlags, stdCppm, stdPcm.string())); } else { diff --git a/implementations/Crafter.Build-Test.cpp b/implementations/Crafter.Build-Test.cpp index f7d7cbb..5183af8 100644 --- a/implementations/Crafter.Build-Test.cpp +++ b/implementations/Crafter.Build-Test.cpp @@ -1,21 +1,5 @@ -/* -Crafter® Build -Copyright (C) 2026 Catcrafts® -Catcrafts.net - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License version 3.0 as published by the Free Software Foundation; - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ +//SPDX-License-Identifier: LGPL-3.0-only +//SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts® module; export module Crafter.Build:Test_impl; @@ -298,7 +282,13 @@ TestRunner TestRunner::ForTarget(const Configuration& cfg) { // which execvp's its argument list directly without going through a // shell. A bare VAR=value would be exec'd as a command path and // fail with "No such file or directory". - r.exec = std::format("env QEMU_LD_PREFIX={} {}", cfg.sysroot, r.exec); + // QEMU_LD_PREFIX only redirects the ELF interpreter lookup; the + // emulated loader then searches ITS default paths against the + // host filesystem, picking up host-arch libraries from /lib — + // LD_LIBRARY_PATH steers it back into the sysroot. + r.exec = std::format( + "env QEMU_LD_PREFIX={0} LD_LIBRARY_PATH={0}/lib:{0}/usr/lib {1}", + cfg.sysroot, r.exec); } return r; } @@ -474,6 +464,7 @@ TestBuilder Configuration::AddTest(std::string_view name, std::span in t.config.target = this->target; t.config.march = this->march; t.config.mtune = this->mtune; + t.config.sysroot = this->sysroot; t.config.debug = this->debug; t.config.type = ConfigurationType::Executable; @@ -499,6 +490,7 @@ void Configuration::AddMarchVariants(std::string_view name, t.config.target = this->target; t.config.march = tier.march; t.config.mtune = tier.mtune; + t.config.sysroot = this->sysroot; t.config.debug = this->debug; t.config.type = ConfigurationType::Executable; diff --git a/interfaces/Crafter.Build-Clang.cppm b/interfaces/Crafter.Build-Clang.cppm index 2b29e84..566508e 100644 --- a/interfaces/Crafter.Build-Clang.cppm +++ b/interfaces/Crafter.Build-Clang.cppm @@ -1,21 +1,5 @@ -/* -Crafter® Build -Copyright (C) 2026 Catcrafts® -Catcrafts.net - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License version 3.0 as published by the Free Software Foundation; - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ +//SPDX-License-Identifier: LGPL-3.0-only +//SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts® module; #include "Crafter.Build-Api.h" @@ -190,10 +174,10 @@ export namespace Crafter { std::vector tests; CRAFTER_API void GetInterfacesAndImplementations(std::span interfaces, std::span implementations); // Declare a test. Sources default to `tests//main.cpp` resolved - // against this Configuration's path; target/march/mtune/debug are - // inherited from this Configuration so cross-arch projects don't have - // to re-specify. Returns a builder for chaining defines, deps, etc. - // Defined in Crafter.Build:Test. + // against this Configuration's path; target/march/mtune/sysroot/debug + // are inherited from this Configuration so cross-arch projects don't + // have to re-specify. Returns a builder for chaining defines, deps, + // etc. Defined in Crafter.Build:Test. CRAFTER_API struct TestBuilder AddTest(std::string_view name); // Same as AddTest, but compiles the parent's `interfaces` directly // into this test's Configuration (rather than going through a dep). diff --git a/tests/StandardArgs/main.cpp b/tests/StandardArgs/main.cpp index 200c196..dfea9bd 100644 --- a/tests/StandardArgs/main.cpp +++ b/tests/StandardArgs/main.cpp @@ -1,3 +1,6 @@ +//SPDX-License-Identifier: LGPL-3.0-only +//SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts® + import std; import Crafter.Build; using namespace Crafter; @@ -30,6 +33,19 @@ int main() { Check(cfg.mtune == "cortex-a72", "--mtune= should overwrite cfg.mtune"); } + // --sysroot= sets cfg.sysroot (cross-compiles against a foreign root, + // e.g. an Alpine aarch64 tree; also picked up by the std.cppm lookup + // and the qemu test-runner's QEMU_LD_PREFIX). + { + Configuration cfg; + std::array raw = { + "--target=aarch64-alpine-linux-musl", "--sysroot=/opt/alpine-aarch64", + }; + ApplyStandardArgs(cfg, raw); + Check(cfg.sysroot == "/opt/alpine-aarch64", "--sysroot= should set cfg.sysroot"); + Check(cfg.target == "aarch64-alpine-linux-musl", "--target= combines with --sysroot="); + } + // --lib promotes Executable -> LibraryStatic; --shared then promotes to Dynamic. { Configuration cfg;