diff options
| author | Robin Voetter <robin@voetter.nl> | 2023-04-08 19:02:31 +0200 |
|---|---|---|
| committer | Robin Voetter <robin@voetter.nl> | 2023-04-09 01:51:55 +0200 |
| commit | a7563e453dce0cc256a0c40af434731f2cf7dcaf (patch) | |
| tree | a0483d968b31c6d5a90bb32312bf13af62c0b79d /lib/std/start.zig | |
| parent | 45b5f467709e3df01aafc37c25070bbbebd43e1e (diff) | |
| download | zig-a7563e453dce0cc256a0c40af434731f2cf7dcaf.tar.gz zig-a7563e453dce0cc256a0c40af434731f2cf7dcaf.zip | |
spirv: minimal start code
For SPIR-V, only export the main function if it is actually declared. Kernel
entry points will often have parameters and more than one kernel declared.
In general, SPIR-V binaries should mostly be compiled as libraries and not as
executables. However, this start code is required so that we can build test
executables.
Note that a call to isSpirV() would emit the code for that function, even though
the call is at comptime. To save that function from being emitted the checks
are just inlined manually.
Diffstat (limited to 'lib/std/start.zig')
| -rw-r--r-- | lib/std/start.zig | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/std/start.zig b/lib/std/start.zig index 1b686e43f5..377a317df2 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -24,7 +24,9 @@ pub const simplified_logic = builtin.zig_backend == .stage2_aarch64 or builtin.zig_backend == .stage2_arm or builtin.zig_backend == .stage2_riscv64 or - builtin.zig_backend == .stage2_sparc64; + builtin.zig_backend == .stage2_sparc64 or + builtin.cpu.arch == .spirv32 or + builtin.cpu.arch == .spirv64; comptime { // No matter what, we import the root file, so that any export, test, comptime @@ -43,6 +45,9 @@ comptime { } } else if (builtin.os.tag == .wasi and @hasDecl(root, "main")) { @export(wasiMain2, .{ .name = "_start" }); + } else if (builtin.os.tag == .opencl) { + if (@hasDecl(root, "main")) + @export(spirvMain2, .{ .name = "main" }); } else { if (!@hasDecl(root, "_start")) { @export(_start2, .{ .name = "_start" }); @@ -127,6 +132,10 @@ fn wasiMain2() callconv(.C) noreturn { } } +fn spirvMain2() callconv(.Kernel) void { + root.main(); +} + fn wWinMainCRTStartup2() callconv(.C) noreturn { root.main(); exit2(0); |
