Skip to content

Commit

Permalink
zigcc: betterC on Darwin
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Dec 31, 2023
1 parent eca3dd5 commit 13c8310
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 18 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ docs/
*.lst

# Zig build
zig-*/
zig-*/

#VScode
.vscode/
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,23 @@ zig build debugtext_print -Doptimize=ReleaseFast # run, but no anims (fixme)
zig build sgl_context -Doptimize=ReleaseFast # run, but no anims (fixme)
zig build cube -Doptimize=ReleaseFast # (fixme)

# custom options:
# -DZigCC (use zig cc as compiler and linker),
# -DBetterC (disable D runtime on ldc2)
zig build --help
# Project-Specific Options:
# -Dgl=[bool] Force GL backend
# -Dwayland=[bool] Compile with wayland-support (default: false)
# -Dx11=[bool] Compile with x11-support (default: true)
# -Degl=[bool] Use EGL instead of GLX if possible (default: false)
# -Dtarget=[string] The CPU architecture, OS, and ABI to build for
# -Dcpu=[string] Target CPU features to add or subtract
# -Doptimize=[enum] Prioritize performance, safety, or binary size (-O flag)
# Supported Values:
# Debug
# ReleaseSafe
# ReleaseFast
# ReleaseSmall
# -DShared=[bool] Build sokol dynamic library [default: static]
# -DBetterC=[bool] Omit generating some runtime information and helper functions. [default: false]
# -DZigCC=[bool] Use zig cc as compiler and linker. [default: false]
```

## Shaders
Expand Down
17 changes: 5 additions & 12 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ pub fn buildSokol(b: *Builder, target: CrossTarget, optimize: OptimizeMode, conf
.optimize = optimize,
});
lib.disable_sanitize_c = true;
switch (optimize) {
// zig have custom compiler-rt and another toolchains not include it (fix: unknown ref zig_stack_protector)
.Debug, .ReleaseSafe => lib.bundle_compiler_rt = true,
else => lib.strip = true,
}
if (!sharedlib)
lib.pie = true;
lib.linkLibC();
const sokol_path = prefix_path ++ "src/sokol/c/";
const csources = [_][]const u8{
Expand Down Expand Up @@ -248,8 +241,8 @@ pub fn build(b: *Builder) !void {
"--vgc", // list all gc alloc
"--preview=dip1000",
},
// fixme: https://github.com/kassane/sokol-d/issues/1
.zig_cc = if (target.isDarwin()) false else enable_zigcc,
// fixme: https://github.com/kassane/sokol-d/issues/1 - betterC works on darwin
.zig_cc = if (target.isDarwin() and !enable_betterC) false else enable_zigcc,
});
ldc.setName("ldc2");
ldc.step.dependOn(b.getInstallStep());
Expand Down Expand Up @@ -304,7 +297,7 @@ fn buildShaders(b: *Builder) void {
}

// Use LDC2 (https://github.com/ldc-developers/ldc) to compile the D examples
fn buildLDC(b: *Builder, lib: *Builder.CompileStep, config: ldcConfig) !*Builder.RunStep {
fn buildLDC(b: *Builder, lib: *CompileStep, config: ldcConfig) !*Builder.RunStep {
const ldc = try b.findProgram(&.{"ldc2"}, &.{});

var cmds = std.ArrayList([]const u8).init(b.allocator);
Expand Down Expand Up @@ -500,8 +493,8 @@ fn buildZigCC(b: *Builder) void {
}

const ldcConfig = struct {
kind: Builder.CompileStep.Kind = .exe,
linkage: Builder.CompileStep.Linkage = .static,
kind: CompileStep.Kind = .exe,
linkage: CompileStep.Linkage = .static,
betterC: bool = false,
sources: []const []const u8 = std.mem.zeroes([]const []const u8),
dflags: []const []const u8 = std.mem.zeroes([]const []const u8),
Expand Down
2 changes: 1 addition & 1 deletion src/examples/sgl_context.d
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void frame()
sg.commit();
}

static void cleanup()
void cleanup()
{
sgl.shutdown();
sg.shutdown();
Expand Down
2 changes: 1 addition & 1 deletion tools/zigcc.zig
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn main() !void {
try cmds.append("-target");
try cmds.append("native-native-msvc"); // msvc only
},
.macos, .ios => {},
.ios, .macos, .watchos, .tvos => {},
else => {
try cmds.append("-target");
try cmds.append("native-native");
Expand Down

0 comments on commit 13c8310

Please sign in to comment.