44 lines
1.4 KiB
C++
44 lines
1.4 KiB
C++
|
|
import std;
|
||
|
|
import Crafter.Build;
|
||
|
|
#include "../_shared/TestUtil.h"
|
||
|
|
namespace fs = std::filesystem;
|
||
|
|
using namespace TestUtil;
|
||
|
|
using namespace Crafter;
|
||
|
|
|
||
|
|
int main() {
|
||
|
|
try {
|
||
|
|
if (!fs::exists("/usr/share/wasi-sysroot/share/libc++/v1/std.cppm")) {
|
||
|
|
Skip("WASI sysroot/libc++ missing — install wasi-libc, wasi-libc++, wasi-libc++abi");
|
||
|
|
}
|
||
|
|
|
||
|
|
fs::path src = fs::current_path() / "tests" / "Wasi" / "inner";
|
||
|
|
Configuration cfg = LoadFixture("Wasi", src);
|
||
|
|
fs::path work = fs::current_path();
|
||
|
|
|
||
|
|
auto br = BuildOnce(cfg);
|
||
|
|
if (!br.result.empty()) {
|
||
|
|
std::println(std::cerr, "build failed:\n{}", br.result);
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
fs::path artifact = work / "bin" / "wasi-hello-wasm32-wasip1-native" / "wasi-hello.wasm";
|
||
|
|
if (!fs::exists(artifact)) {
|
||
|
|
std::println(std::cerr, "expected artifact missing at {}", artifact.string());
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Verify WASM magic bytes: \0asm
|
||
|
|
std::ifstream f(artifact, std::ios::binary);
|
||
|
|
char magic[4] = {};
|
||
|
|
f.read(magic, 4);
|
||
|
|
if (magic[0] != '\0' || magic[1] != 'a' || magic[2] != 's' || magic[3] != 'm') {
|
||
|
|
std::println(std::cerr, "artifact is not a valid WASM file (bad magic bytes)");
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
} catch (const std::exception& e) {
|
||
|
|
std::println(std::cerr, "test exception: {}", e.what());
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
}
|