feat(lang): support assembly sources and shader bundles
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 9s
VoidBuildSystem CI / sanitizers-gcc16 (push) Failing after 8s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 12s
VoidBuildSystem CI / fuzz-clang (push) Failing after 5s
VoidBuildSystem CI / wine-windows-gcc16 (push) Failing after 49s

This commit is contained in:
faumaray committed 2026-12-05 14:14:25 +03:00
1 parent ce041ace07
commit 0c1bf7e5b2
11 files changed
+519 -21

No files matched your search

+134
View File
@@ -2562,6 +2562,140 @@ VOID_TEST(FullV1Tests, pkgconfig_dependency_resolves_flags_requires_and_versions
}
}
// === Assembly sources (.S through the C preprocessor) ===
VOID_TEST(FullV1Tests, asm_preprocessed_source_compiles_and_links) {
if (Toolchain::host_architecture_name() != "x86_64") {
return; // The fixture is x86-64 assembly.
}
const auto vbs_bin = locate_vbs_binary();
Void::Testing::expect(!vbs_bin.empty() && std::filesystem::exists(vbs_bin));
if (vbs_bin.empty() || !std::filesystem::exists(vbs_bin)) {
return;
}
Void::FileSystem::TempDir tmp{"vbs_asm_"};
const auto proj = tmp / "proj";
const auto bdir = tmp / "build";
write_file(proj / "build.cpp", R"cpp(#include <Void/Build.hpp>
void build(Void::Build::Project &p) {
p.executable("asm_app")
.cxx_standard(Void::Build::CxxStandard::Cxx26)
.sources({"src/main.cpp", "src/answer.S", "src/twice.s"});
}
)cpp");
write_file(proj / "src" / "main.cpp", R"cpp(#include <cstdio>
extern "C" int asm_answer();
extern "C" int asm_twice(int);
int main() {
if (asm_answer() != 42 || asm_twice(21) != 42) {
std::fprintf(stderr, "asm mismatch: %d %d\n", asm_answer(), asm_twice(21));
return 1;
}
return 0;
}
)cpp");
// `.S` is preprocessed: the answer comes from a #define.
write_file(proj / "src" / "answer.S", R"asm(#define ASM_ANSWER 42
.text
.globl asm_answer
.type asm_answer, @function
asm_answer:
mov $ASM_ANSWER, %eax
ret
)asm");
// `.s` is assembled verbatim.
write_file(proj / "src" / "twice.s", R"asm( .text
.globl asm_twice
.type asm_twice, @function
asm_twice:
lea (%rdi,%rdi), %eax
ret
)asm");
Platform::ProcessRequest req;
req.executable = vbs_bin;
req.arguments = {"build", "--project", proj.string(), "--build-dir", bdir.string()};
req.timeout = std::chrono::seconds{300};
auto res = Platform::run_supervised(req);
Void::Testing::expect(res.has_value() && res->succeeded());
if (res && !res->succeeded()) {
std::fprintf(stderr, "%s\n", (res->stdout_data + res->stderr_data).c_str());
}
const auto app = bdir / "profiles" / "debug" / "out" / "bin" / "asm_app";
Void::Testing::expect(std::filesystem::exists(app));
if (std::filesystem::exists(app)) {
Platform::ProcessRequest run;
run.executable = app;
run.timeout = std::chrono::seconds{60};
auto ran = Platform::run_supervised(run);
Void::Testing::expect(ran.has_value() && ran->succeeded());
}
}
// === Shader sources compile to SPIR-V ===
VOID_TEST(FullV1Tests, shader_bundle_compiles_sources_to_spirv) {
if (!Platform::resolve_executable("glslangValidator")) {
return; // No shader compiler in this environment.
}
const auto vbs_bin = locate_vbs_binary();
Void::Testing::expect(!vbs_bin.empty() && std::filesystem::exists(vbs_bin));
if (vbs_bin.empty() || !std::filesystem::exists(vbs_bin)) {
return;
}
Void::FileSystem::TempDir tmp{"vbs_shader_"};
const auto proj = tmp / "proj";
const auto bdir = tmp / "build";
write_file(proj / "build.cpp", R"cpp(#include <Void/Build.hpp>
void build(Void::Build::Project &p) {
p.shader_bundle("shaders")
.shader("shaders/tri.vert")
.shader("shaders/tri.frag");
}
)cpp");
write_file(proj / "shaders" / "tri.vert", "#version 450\nlayout(location = 0) in vec3 pos;\n"
"void main() { gl_Position = vec4(pos, 1.0); }\n");
write_file(proj / "shaders" / "tri.frag", "#version 450\nlayout(location = 0) out vec4 color;\n"
"void main() { color = vec4(1.0); }\n");
Platform::ProcessRequest req;
req.executable = vbs_bin;
req.arguments = {"build", "--project", proj.string(), "--build-dir", bdir.string()};
req.timeout = std::chrono::seconds{300};
auto res = Platform::run_supervised(req);
Void::Testing::expect(res.has_value() && res->succeeded());
if (res && !res->succeeded()) {
std::fprintf(stderr, "%s\n", (res->stdout_data + res->stderr_data).c_str());
}
// Each shader produced a SPIR-V module (magic 0x07230203, little-endian on disk).
std::size_t modules = 0;
for (const auto &entry : std::filesystem::recursive_directory_iterator(
bdir / "profiles" / "debug" / "shaders",
std::filesystem::directory_options::skip_permission_denied)) {
if (!entry.is_regular_file() || entry.path().extension() != ".spv") {
continue;
}
auto bytes = Void::FileSystem::read_file(entry.path());
Void::Testing::require(bytes.has_value() && bytes->size() >= 20);
Void::Testing::expect(std::string_view{*bytes}.substr(0, 4) ==
std::string_view{"\x03\x02\x23\x07", 4});
++modules;
}
Void::Testing::expect_eq(modules, std::size_t{2});
// A shader with an unknown stage and no compiler hint is rejected with a clear error.
write_file(proj / "shaders" / "mystery.glsl", "#version 450\nvoid main() {}\n");
write_file(proj / "build.cpp", R"cpp(#include <Void/Build.hpp>
void build(Void::Build::Project &p) {
p.shader_bundle("shaders").shader("shaders/mystery.glsl");
}
)cpp");
auto bad = Platform::run_supervised(req);
Void::Testing::expect(bad.has_value() && !bad->succeeded());
if (bad) {
Void::Testing::expect(bad->stderr_data.find("cannot infer the stage") != std::string::npos);
}
}
// === Track A1: Native VBS subproject dependency (builder == "native", zero CMake!) ===
VOID_TEST(FullV1Tests, native_vbs_subproject_dependency_builds_without_cmake) {
const auto vbs_bin = locate_vbs_binary();