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

+2
View File
@@ -373,6 +373,8 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B
- **Wave 140 (pkg-config Discovery)**: `p.dependency("zlib").pkgconfig("zlib >= 1.2")` resolves system libraries from `.pc` files (parsed directly - no `pkg-config` executable needed), honoring `PKG_CONFIG_PATH`/`PKG_CONFIG_LIBDIR` plus conventional prefixes. Variables (`${prefix}`, `${pcfiledir}`, nested) expand, `Requires` chains merge flags, and RPM-style version comparison enforces constraints at the root and in the chain. Cflags become include dirs/defines/compile options and Libs become link options or library paths. The dependency is recorded in `vbs.lock` as `pkgconfig` and never fetched. `FullV1Tests.pkgconfig_dependency_resolves_flags_requires_and_versions` builds and runs a real app against a generated `.pc` + archive, and asserts both version-mismatch errors.
- **Wave 141 (ASM & Shader Languages)**: assembly sources (`.s` plain, `.S` preprocessed) compile through the C compiler driver without C/C++ standard flags, LTO or sanitizers, and are excluded from unity/module scanning. Shader bundles are first-class: `p.shader_bundle("shaders").shader("tri.vert")` lowers one action per shader to SPIR-V via `glslangValidator` (GLSL/HLSL), `slangc` (Slang, stage inferred from `[shader]`) or `dxc` (HLSL), with toolchain discovery from PATH. `FullV1Tests.asm_preprocessed_source_compiles_and_links` and `shader_bundle_compiles_sources_to_spirv` cover both; GLSL, Slang and HLSL shaders were each compiled to valid SPIR-V (`0x07230203`).
## Remaining future scope
- **Superiority plan ([22-superiority-and-gaps.md](../roadmap/22-superiority-and-gaps.md), 2026-12-05)**: revised platform strategy - **macOS deferred**, **Windows via MinGW-w64 cross-compilation + Wine execution** (`dev cpp-gcc -p pkgsCross.mingwW64.stdenv.cc`, `dev cpp-gcc -p wine64`), native MSVC deferred; plus packaging parity (ZIP/DEB/RPM), IDE ecosystem, migration tooling, test-runner parity, benchmarks, CI runners, and remote execution in prioritized order.
+1
View File
@@ -141,4 +141,5 @@ Base HEAD: `fe0d1a6`
| Wave 138 (Full CMake File API) | `cmakeFiles-v1`, `toolchains-v1`, `cache-v2` replies | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; IDE E2E passes, full CTest 8/8) | `src/Editor/CompDb.cpp`, `tests/FullV1Tests.cpp`, docs |
| Wave 139 (VSIX packaging) | `vbs ide plugin --vsix FILE`; shared `Package::create_stored_zip` | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Python zipfile validates the VSIX, packaged harness passes under Node, C++ test checks CRCs, full CTest 8/8) | `src/Editor/CompDb.cpp`, `src/Package/Archive.cpp`, `src/Main.cpp`, `tests/FullV1Tests.cpp`, docs |
| Wave 140 (pkg-config discovery) | `.pkgconfig(spec)` dependency, `.pc` parser with variables/Requires/version compare, lock entries | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; E2E builds/runs and checks version errors, full CTest 8/8) | `include/Void/Build.hpp`, `sdk/Build.cpp`, `src/Provider/PkgConfig.cpp`, `src/Graph/Graph.cpp`, `src/Package/Resolver.cpp`, `src/Main.cpp`, `tests/FullV1Tests.cpp`, docs |
| Wave 141 (ASM + shader languages) | `.s`/`.S` assembly; `shader_bundle`/`.shader()` lowered to SPIR-V (glslang/slangc/dxc) | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; both E2Es pass, GLSL/Slang/HLSL produce SPIR-V, full CTest 8/8) | `src/Graph/Graph.cpp`, `src/Toolchain/Driver.cpp`, `include/Void/Build.hpp`, `sdk/Build.cpp`, `tests/FullV1Tests.cpp`, docs |
| Future (Plan 20 Slice 3 / Tracks C, E3 editor extensions) |"}] Live `conan` CLI verification; macOS/Windows/cross-compile; binary-variant signing and key distribution; daemon-side dependency materialization and editor plugins; `Void::Net`/`Void::Sqlite` alignment | PLANNED (unimplemented) | [21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md), [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md) |
+14
View File
@@ -1836,6 +1836,20 @@ VOID_INCLUDE_DIR=/tmp/opencode/vl-pin/include dev cpp -c bash fuzz/run.sh 30
"is required, but version 1.2.3 is installed" and `child >= 0.8` fails through the chain.
- Full CTest: **8 / 8 passed** in 311.96 s.
## ASM & Shader Languages (GCC 16.2, pin `0002e74`)
- Assembly: `.s`/`.S` sources are lowered through the C compiler driver with no language
standard, LTO or sanitizer flags (`.S` is preprocessed by the driver).
`FullV1Tests.asm_preprocessed_source_compiles_and_links` **passed** (2.32 s): a `.S` file
using `#define ASM_ANSWER 42` and a verbatim `.s` file link into a running executable.
- Shaders: `p.shader_bundle("shaders").shader(...)` emits one action per source to SPIR-V.
`FullV1Tests.shader_bundle_compiles_sources_to_spirv` **passed** (3.99 s, run under
`dev cpp-gcc -p glslang`): two GLSL shaders produce modules starting with `0x07230203`, and
a stage-less `.glsl` is rejected with "cannot infer the stage".
- GLSL (glslang), Slang (`slangc`, stage from `[shader]`) and HLSL (`dxc`) were all compiled
manually to valid SPIR-V in this environment.
- Full CTest: **8 / 8 passed** in 314.56 s.
## Limits and Unrun Checks
1. **HTTPS git fetch**: the host shell is proxy-restricted, but the Docker container could clone `https://git.faumaray.com/Void/VoidLibrary.git`; the pinned commit `3e254055e081a104f08df68dde39711bc7813518` was fetched directly for the verification above. A separate configure against the local `/home/faumaray/Projects/Library` checkout via `VBS_VOID_SOURCE_DIR` also succeeded (development-only override, checkout unmodified).
+1 -1
View File
@@ -116,7 +116,7 @@ first, then what makes VBS *better* rather than merely equal.
pkg-config lookup, so most existing Linux projects cannot be built as-is. Add
`.pkgconfig("libfoo >= 1.2")` plus a `.pc` search path in profiles, resolved into an
imported target.
2. **Language breadth: ASM and shader languages.** VBS is C/C++ only. Add assembly (`.s`,
2. **Language breadth: ASM and shader languages - done (Wave 141).** VBS is C/C++ only. Add assembly (`.s`,
`.S` with the C preprocessor) and the shader languages used by Void projects (GLSL, HLSL,
Slang) through pluggable shader-compiler toolchains with capability probes.
3. **Platform breadth - deferred.** Native MSVC and Apple Clang/macOS stay deferred by
+14
View File
@@ -36,6 +36,14 @@ enum class CStandard { Default, C11, C17, C23 };
enum class CxxStandard { Default, Cxx17, Cxx20, Cxx23, Cxx26 };
enum class LtoMode { None, Full, Thin };
enum class Sanitizer { Address, Undefined, Thread, Memory, Leak };
enum class ShaderLanguage { Auto, Glsl, Hlsl, Slang };
enum class ShaderStage { Auto, Vertex, Fragment, Compute, Geometry, TessControl, TessEval };
struct ShaderSource {
std::string path;
ShaderLanguage language{ShaderLanguage::Auto};
ShaderStage stage{ShaderStage::Auto};
};
[[nodiscard]] std::string_view compiler_name(CompilerFamily compiler);
[[nodiscard]] CompilerFamily parse_compiler(std::string_view name);
@@ -203,6 +211,7 @@ struct TargetRecord {
std::map<std::string, std::string, std::less<>> environment;
std::vector<std::string> labels; // Test labels for filtering (`vbs test --label`).
std::vector<std::string> resources; // Exclusive resources held while the test runs.
std::vector<ShaderSource> shaders; // Shader sources compiled to SPIR-V.
std::vector<std::string> fixture_setup; // Fixtures this test sets up.
std::vector<std::string> fixture_required; // Fixtures this test requires.
std::vector<std::string> fixture_cleanup; // Fixtures this test tears down.
@@ -291,6 +300,9 @@ class Target {
Target &env(std::string key, std::string value);
Target &label(std::string label);
Target &resource(std::string name);
// Declares a shader source on a shader bundle (compiled to SPIR-V on build).
Target &shader(std::string source_path, ShaderLanguage language = ShaderLanguage::Auto,
ShaderStage stage = ShaderStage::Auto);
Target &fixture_setup(std::string name);
Target &fixture_required(std::string name);
Target &fixture_cleanup(std::string name);
@@ -352,6 +364,8 @@ class Project {
[[nodiscard]] Target header_only_library(std::string name);
[[nodiscard]] Target object_library(std::string name);
[[nodiscard]] Target custom_action(std::string name);
// A target that compiles declared shader sources to SPIR-V (`.shader(...)`).
[[nodiscard]] Target shader_bundle(std::string name);
[[nodiscard]] Target test(std::string name);
[[nodiscard]] Dependency dependency(std::string name);
// Links to another member of the enclosing workspace. The member path is supplied by the
+7
View File
@@ -50,6 +50,11 @@ struct ToolchainCapabilities {
bool supports_tsan{false};
bool is_cross_toolchain{false};
// Shader compilers discovered from PATH (not part of the toolchain identity).
std::filesystem::path glslang_validator; // GLSL + HLSL -> SPIR-V
std::filesystem::path slangc; // Slang (and GLSL/HLSL) -> SPIR-V
std::filesystem::path dxc; // HLSL -> SPIR-V / DXIL
std::string identity_hash;
};
@@ -67,6 +72,8 @@ struct CompileRequest {
std::vector<std::string> defines;
std::vector<std::string> compile_options;
bool is_c_source{false};
// Assembly source (`.s` plain, `.S` preprocessed): compiled with the C compiler driver.
bool is_asm_source{false};
CStandard c_standard{CStandard::Default};
CxxStandard cxx_standard{CxxStandard::Default};
LtoMode lto{LtoMode::None};
+49 -1
View File
@@ -866,6 +866,13 @@ Target &Target::resource(std::string name) {
return *this;
}
Target &Target::shader(std::string source_path, ShaderLanguage language, ShaderStage stage) {
require_text(source_path, "shader source path");
owner(owner_)->targets.at(index_).shaders.push_back(
ShaderSource{std::move(source_path), language, stage});
return *this;
}
Target &Target::fixture_setup(std::string name) {
require_text(name, "fixture name");
owner(owner_)->targets.at(index_).fixture_setup.push_back(std::move(name));
@@ -1113,6 +1120,9 @@ Target Project::object_library(std::string name) {
Target Project::custom_action(std::string name) {
return add_target(std::move(name), TargetKind::CustomAction);
}
Target Project::shader_bundle(std::string name) {
return add_target(std::move(name), TargetKind::CustomAction);
}
Target Project::test(std::string name) { return add_target(std::move(name), TargetKind::Test); }
Dependency Project::dependency(std::string name) {
@@ -1267,7 +1277,45 @@ std::string Project::to_json() const {
",\"working_directory\":" + json_quote(target.working_directory) +
",\"environment\":" + env_json(target.environment) +
",\"labels\":" + json_array(target.labels, json_quote) +
",\"resources\":" + json_array(target.resources, json_quote) +
",\"resources\":" + json_array(target.resources, json_quote) + ",\"shaders\":" +
json_array(target.shaders,
[](const ShaderSource &shader) {
const auto language = [&] {
switch (shader.language) {
case ShaderLanguage::Glsl:
return std::string{"glsl"};
case ShaderLanguage::Hlsl:
return std::string{"hlsl"};
case ShaderLanguage::Slang:
return std::string{"slang"};
case ShaderLanguage::Auto:
return std::string{"auto"};
}
return std::string{"auto"};
}();
const auto stage = [&] {
switch (shader.stage) {
case ShaderStage::Vertex:
return std::string{"vertex"};
case ShaderStage::Fragment:
return std::string{"fragment"};
case ShaderStage::Compute:
return std::string{"compute"};
case ShaderStage::Geometry:
return std::string{"geometry"};
case ShaderStage::TessControl:
return std::string{"tess_control"};
case ShaderStage::TessEval:
return std::string{"tess_eval"};
case ShaderStage::Auto:
return std::string{"auto"};
}
return std::string{"auto"};
}();
return "{\"path\":" + json_quote(shader.path) +
",\"language\":" + json_quote(language) +
",\"stage\":" + json_quote(stage) + '}';
}) +
",\"fixture_setup\":" + json_array(target.fixture_setup, json_quote) +
",\"fixture_required\":" + json_array(target.fixture_required, json_quote) +
",\"fixture_cleanup\":" + json_array(target.fixture_cleanup, json_quote) +
+267 -12
View File
@@ -115,6 +115,11 @@ bool is_c_source_extension(const std::filesystem::path &p) {
return p.extension().string() == ".c";
}
bool is_asm_source_extension(const std::filesystem::path &p) {
const auto ext = p.extension().string();
return ext == ".s" || ext == ".S"; // `.S` is preprocessed by the compiler driver
}
bool is_cpp_source_extension(const std::filesystem::path &p) {
const auto ext = p.extension().string();
return ext == ".cpp" || ext == ".cc" || ext == ".cxx" || ext == ".c" ||
@@ -333,6 +338,35 @@ ProjectDescription::from_json(std::string_view json_text) {
t.nondeterministic = get_bool(*to, "nondeterministic", false);
t.labels = get_str_array(*to, "labels");
t.resources = get_str_array(*to, "resources");
if (const auto *shv = find_key(*to, "shaders")) {
if (const auto *sharr = std::get_if<JsonVal::Array>(&shv->value)) {
for (const auto &item : *sharr) {
const auto *sho = std::get_if<JsonVal::Object>(&item.value);
if (sho == nullptr) {
continue;
}
ShaderSource shader;
shader.path = get_str(*sho, "path");
if (shader.path.empty()) {
continue;
}
const auto language = get_str(*sho, "language");
shader.language = language == "glsl" ? ShaderLanguage::Glsl
: language == "hlsl" ? ShaderLanguage::Hlsl
: language == "slang" ? ShaderLanguage::Slang
: ShaderLanguage::Auto;
const auto stage = get_str(*sho, "stage");
shader.stage = stage == "vertex" ? ShaderStage::Vertex
: stage == "fragment" ? ShaderStage::Fragment
: stage == "compute" ? ShaderStage::Compute
: stage == "geometry" ? ShaderStage::Geometry
: stage == "tess_control" ? ShaderStage::TessControl
: stage == "tess_eval" ? ShaderStage::TessEval
: ShaderStage::Auto;
t.shaders.push_back(std::move(shader));
}
}
}
t.fixture_setup = get_str_array(*to, "fixture_setup");
t.fixture_required = get_str_array(*to, "fixture_required");
t.fixture_cleanup = get_str_array(*to, "fixture_cleanup");
@@ -773,6 +807,223 @@ lower_project_graph(const ProjectDescription &description,
}
}
// 2a. Shader bundle lowering: one compile action per declared shader source.
if (t.kind == TargetKind::CustomAction && !t.shaders.empty()) {
if (!t.command_argv.empty()) {
return std::unexpected{make_error(
std::format("shader bundle '{}' cannot also declare command()", t.name))};
}
const auto stage_name = [](ShaderStage stage) -> std::string {
switch (stage) {
case ShaderStage::Vertex:
return "vertex";
case ShaderStage::Fragment:
return "fragment";
case ShaderStage::Compute:
return "compute";
case ShaderStage::Geometry:
return "geometry";
case ShaderStage::TessControl:
return "tess_control";
case ShaderStage::TessEval:
return "tess_eval";
case ShaderStage::Auto:
return {};
}
return {};
};
const auto glslang_stage = [](ShaderStage stage) -> std::string {
switch (stage) {
case ShaderStage::Vertex:
return "vert";
case ShaderStage::Fragment:
return "frag";
case ShaderStage::Compute:
return "comp";
case ShaderStage::Geometry:
return "geom";
case ShaderStage::TessControl:
return "tesc";
case ShaderStage::TessEval:
return "tese";
default:
return {};
}
};
const auto slang_stage = [](ShaderStage stage) -> std::string {
switch (stage) {
case ShaderStage::Vertex:
return "vertex";
case ShaderStage::Fragment:
return "fragment";
case ShaderStage::Compute:
return "compute";
case ShaderStage::Geometry:
return "geometry";
case ShaderStage::TessControl:
return "hull";
case ShaderStage::TessEval:
return "domain";
default:
return {};
}
};
const auto hlsl_profile = [](ShaderStage stage) -> std::string {
switch (stage) {
case ShaderStage::Vertex:
return "vs_6_0";
case ShaderStage::Fragment:
return "ps_6_0";
case ShaderStage::Compute:
return "cs_6_0";
case ShaderStage::Geometry:
return "gs_6_0";
case ShaderStage::TessControl:
return "hs_6_0";
case ShaderStage::TessEval:
return "ds_6_0";
default:
return {};
}
};
const auto shader_out_root =
graph.profile_build_dir / "shaders" / sanitize_id_component(t.name);
for (const auto &shader : t.shaders) {
const auto abs_src = (canonical_root / shader.path).lexically_normal();
if (!std::filesystem::is_regular_file(abs_src)) {
return std::unexpected{make_error(std::format(
"shader bundle '{}': source '{}' does not exist", t.name, shader.path))};
}
const std::string ext = abs_src.extension().string();
ShaderLanguage language = shader.language;
if (language == ShaderLanguage::Auto) {
language = ext == ".hlsl" || ext == ".fx" ? ShaderLanguage::Hlsl
: ext == ".slang" ? ShaderLanguage::Slang
: ShaderLanguage::Glsl;
}
ShaderStage stage = shader.stage;
if (stage == ShaderStage::Auto) {
stage = ext == ".vert" || ext == ".vs" ? ShaderStage::Vertex
: ext == ".frag" || ext == ".fs" ? ShaderStage::Fragment
: ext == ".comp" || ext == ".cs" ? ShaderStage::Compute
: ext == ".geom" || ext == ".gs" ? ShaderStage::Geometry
: ext == ".tesc" || ext == ".hs" ? ShaderStage::TessControl
: ext == ".tese" || ext == ".ds" ? ShaderStage::TessEval
: ShaderStage::Auto;
}
// Slang can infer the stage from its [shader("...")] attribute.
const bool slang_infers_stage =
stage == ShaderStage::Auto && language == ShaderLanguage::Slang;
if (stage == ShaderStage::Auto && !slang_infers_stage) {
return std::unexpected{make_error(std::format(
"shader bundle '{}': cannot infer the stage of '{}' (use .vert/.frag/"
".comp or pass an explicit stage)",
t.name, shader.path))};
}
const std::string src_hash = Util::sha256_hex(abs_src.string()).substr(0, 12);
const auto out_path =
shader_out_root /
(abs_src.stem().string() + "_" + src_hash +
(stage == ShaderStage::Auto ? std::string{} : "." + stage_name(stage)) +
".spv");
std::vector<std::string> argv;
const auto &tools = graph.toolchain;
if (language == ShaderLanguage::Slang && !tools.slangc.empty()) {
argv = {tools.slangc.string(),
abs_src.string(),
"-target",
"spirv",
"-entry",
"main"};
if (!slang_infers_stage) {
argv.push_back("-stage");
argv.push_back(slang_stage(stage));
}
argv.push_back("-o");
argv.push_back(out_path.string());
} else if (language == ShaderLanguage::Hlsl && !tools.dxc.empty()) {
argv = {tools.dxc.string(),
abs_src.string(),
"-T",
hlsl_profile(stage),
"-E",
"main",
"-spirv",
"-Fo",
out_path.string()};
} else if (!tools.glslang_validator.empty() &&
(language == ShaderLanguage::Glsl || language == ShaderLanguage::Hlsl)) {
argv = {tools.glslang_validator.string(),
"-V",
"-S",
glslang_stage(stage),
"-o",
out_path.string()};
if (language == ShaderLanguage::Hlsl) {
argv.push_back("-D");
argv.push_back("-e");
argv.push_back("main");
}
argv.push_back(abs_src.string());
} else if (!tools.slangc.empty()) {
argv = {tools.slangc.string(),
abs_src.string(),
"-target",
"spirv",
"-entry",
"main",
"-stage",
slang_stage(stage),
"-o",
out_path.string()};
} else {
return std::unexpected{make_error(
std::format("shader bundle '{}': no shader compiler found for '{}' "
"(install glslangValidator, slangc or dxc)",
t.name, shader.path))};
}
ActionNode act;
act.id = "shader:" + sanitize_id_component(t.name) + ":" + src_hash + ":" +
stage_name(stage);
act.kind = ActionKind::Custom;
act.target_name = t.name;
act.executable = argv.front();
act.arguments.assign(argv.begin() + 1, argv.end());
act.working_directory = canonical_root;
if (!t.nondeterministic && !description.profile.nondeterministic) {
act.environment.emplace(
"SOURCE_DATE_EPOCH",
std::to_string(description.profile.reproducibility_epoch));
act.environment.emplace("TZ", "UTC");
act.environment.emplace("LC_ALL", "C");
}
act.dependencies = target_prereq_actions;
act.declared_inputs = {abs_src};
act.declared_outputs = {out_path};
act.logical_source_file = abs_src;
act.physical_source_file = abs_src;
act.logical_output_file = out_path;
act.physical_output_file = out_path;
act.nondeterministic = t.nondeterministic || description.profile.nondeterministic;
act.cacheable = !act.nondeterministic;
if (auto reg = register_output(out_path, act.id); !reg) {
return std::unexpected{reg.error()};
}
act.action_key = compute_action_key(act, graph);
tc.producer_action_ids.push_back(act.id);
tc.exported_prerequisite_actions.push_back(act.id);
summary.action_ids.push_back(act.id);
summary.primary_outputs.push_back(out_path);
graph.action_index_by_id[act.id] = graph.actions.size();
graph.actions.push_back(std::move(act));
}
computed[t.name] = std::move(tc);
graph.targets.push_back(std::move(summary));
continue;
}
// 2. CustomAction lowering.
if (t.kind == TargetKind::CustomAction) {
if (t.command_argv.empty()) {
@@ -1101,7 +1352,7 @@ lower_project_graph(const ProjectDescription &description,
return std::unexpected{found.error()};
}
for (const auto &f : *found) {
if (is_cpp_source_extension(f)) {
if (is_cpp_source_extension(f) || is_asm_source_extension(f)) {
add_source(f);
}
}
@@ -1320,6 +1571,7 @@ lower_project_graph(const ProjectDescription &description,
std::filesystem::path physical_src;
std::vector<std::string> tu_opts;
bool is_c{false};
bool is_asm{false};
bool is_explicit_module{false};
bool has_per_file_override{false};
};
@@ -1335,6 +1587,7 @@ lower_project_graph(const ProjectDescription &description,
cu.is_explicit_module =
explicit_module_sources.contains(src_path) || is_module_source_extension(src_path);
cu.is_c = !cu.is_explicit_module && is_c_source_extension(src_path);
cu.is_asm = !cu.is_explicit_module && is_asm_source_extension(src_path);
for (const auto &pfo : t.per_file_options) {
if (pfo.source_path == src_path.generic_string() ||
pfo.source_path == cu.logical_src.generic_string()) {
@@ -1354,7 +1607,7 @@ lower_project_graph(const ProjectDescription &description,
const auto norm_phys = cu.physical_src.lexically_normal();
all_phys.push_back(norm_phys);
raw_by_phys[norm_phys] = &cu;
if (cu.is_c || cu.is_explicit_module || cu.has_per_file_override) {
if (cu.is_c || cu.is_asm || cu.is_explicit_module || cu.has_per_file_override) {
excluded_phys.push_back(norm_phys);
}
}
@@ -1384,8 +1637,8 @@ lower_project_graph(const ProjectDescription &description,
std::vector<std::string> compile_action_ids;
const bool has_module_sources = std::ranges::any_of(
compile_units, [](const CompileUnitSpec &u) { return u.is_explicit_module; });
const bool has_cpp_sources =
std::ranges::any_of(compile_units, [](const CompileUnitSpec &u) { return !u.is_c; });
const bool has_cpp_sources = std::ranges::any_of(
compile_units, [](const CompileUnitSpec &u) { return !u.is_c && !u.is_asm; });
const bool run_module_pipeline =
has_module_sources || (has_cpp_sources && !external_module_bmis.empty());
@@ -1417,16 +1670,18 @@ lower_project_graph(const ProjectDescription &description,
req.defines = effective_defines;
req.compile_options = cu.tu_opts;
req.is_c_source = cu.is_c;
req.is_asm_source = cu.is_asm;
req.c_standard = cu.is_c ? eff_c_std : CStandard::Default;
req.cxx_standard =
cu.is_c ? CxxStandard::Default
: ((!header_unit_bmi_paths.empty() && eff_std == CxxStandard::Default)
? CxxStandard::Cxx20
: eff_std);
cu.is_c || cu.is_asm
? CxxStandard::Default
: ((!header_unit_bmi_paths.empty() && eff_std == CxxStandard::Default)
? CxxStandard::Cxx20
: eff_std);
req.lto = eff_lto;
req.sanitizers = eff_sans;
req.position_independent = pic;
req.precompiled_header = cu.is_c ? std::nullopt : pch_include_prefix;
req.precompiled_header = (cu.is_c || cu.is_asm) ? std::nullopt : pch_include_prefix;
req.prefix_maps = prefix_maps;
req.reproducibility_epoch = description.profile.reproducibility_epoch;
req.nondeterministic = t.nondeterministic || description.profile.nondeterministic;
@@ -1458,7 +1713,7 @@ lower_project_graph(const ProjectDescription &description,
act.response_file = lowered->response_file;
act.response_file_content = std::move(lowered->response_file_content);
act.declared_inputs = {cu.physical_src};
if (!cu.is_c) {
if (!cu.is_c && !cu.is_asm) {
for (const auto &hb : header_unit_bmi_paths) {
act.declared_inputs.push_back(hb);
}
@@ -1484,7 +1739,7 @@ lower_project_graph(const ProjectDescription &description,
act.position_independent = pic;
act.precompiled_header = req.precompiled_header;
act.dependencies = target_prereq_actions;
if (!cu.is_c) {
if (!cu.is_c && !cu.is_asm) {
if (pch_action_id) {
add_unique_str(act.dependencies, *pch_action_id);
}
@@ -1522,7 +1777,7 @@ lower_project_graph(const ProjectDescription &description,
scanned.reserve(compile_units.size());
std::map<std::filesystem::path, const CompileUnitSpec *> cu_by_phys;
for (const auto &cu : compile_units) {
if (cu.is_c) {
if (cu.is_c || cu.is_asm) {
if (auto r = emit_regular_compile_action(cu); !r) {
return std::unexpected{r.error()};
}
+2 -2
View File
@@ -434,8 +434,8 @@ generate_unity_batches(const std::string &target_name,
const auto ext = norm.extension().string();
// Exclude C sources, module interface/partition extensions and explicitly excluded files
// from unity!
if (excluded.contains(norm) || ext == ".c" || ext == ".cppm" || ext == ".ixx" ||
ext == ".ccm") {
if (excluded.contains(norm) || ext == ".c" || ext == ".s" || ext == ".S" ||
ext == ".cppm" || ext == ".ixx" || ext == ".ccm") {
result.standalone_files.push_back(norm);
} else {
batchable.push_back(norm);
+28 -5
View File
@@ -242,6 +242,21 @@ std::optional<ToolchainCapabilities> deserialize_capabilities(std::string_view t
}
}
// Shader compilers come from PATH and are intentionally not part of the toolchain identity:
// each shader action's key includes its exact command line.
void attach_shader_tools(ToolchainCapabilities &cap) {
const auto resolve = [](const char *name) { return Platform::resolve_executable(name); };
if (auto glslang = resolve("glslangValidator"); glslang) {
cap.glslang_validator = *glslang;
}
if (auto slangc = resolve("slangc"); slangc) {
cap.slangc = *slangc;
}
if (auto dxc = resolve("dxc"); dxc) {
cap.dxc = *dxc;
}
}
} // namespace
std::string host_os_name() {
@@ -386,6 +401,7 @@ discover_and_probe(const ProfileContext &context,
if (auto cached_text = Void::FileSystem::read_file(cache_file); cached_text) {
if (auto cached = deserialize_capabilities(*cached_text); cached) {
cached->relevant_env = relevant_env;
attach_shader_tools(*cached);
return *cached;
}
}
@@ -531,6 +547,7 @@ discover_and_probe(const ProfileContext &context,
(void)Platform::atomic_write_file(cache_file, serialize_capabilities(cap), false);
}
attach_shader_tools(cap);
return cap;
}
@@ -650,13 +667,19 @@ lower_compile_command(const ToolchainCapabilities &toolchain, const CompileReque
}
LoweredCommand cmd;
cmd.executable = request.is_c_source ? toolchain.c_compiler : toolchain.cxx_compiler;
cmd.executable =
request.is_asm_source
? (toolchain.c_compiler.empty() ? toolchain.cxx_compiler : toolchain.c_compiler)
: (request.is_c_source ? toolchain.c_compiler : toolchain.cxx_compiler);
std::vector<std::string> args;
if (!toolchain.sysroot.empty()) {
args.push_back("--sysroot=" + toolchain.sysroot);
}
if (request.is_c_source) {
if (request.is_asm_source) {
// Assembly takes no language standard; `.S` is run through the C preprocessor by the
// driver based on its extension.
} else if (request.is_c_source) {
if (const auto std_flag = c_standard_flag(request.c_standard); !std_flag.empty()) {
args.push_back(std_flag);
}
@@ -668,12 +691,12 @@ lower_compile_command(const ToolchainCapabilities &toolchain, const CompileReque
if (request.position_independent) {
args.push_back("-fPIC");
}
if (request.lto == LtoMode::Full) {
if (!request.is_asm_source && request.lto == LtoMode::Full) {
args.push_back("-flto");
} else if (request.lto == LtoMode::Thin) {
} else if (!request.is_asm_source && request.lto == LtoMode::Thin) {
args.push_back("-flto=thin");
}
if (!request.sanitizers.empty()) {
if (!request.is_asm_source && !request.sanitizers.empty()) {
std::string list;
for (std::size_t i = 0; i < request.sanitizers.size(); ++i) {
if (i > 0) {
+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();