Skip to content

Commit 42284c7

Browse files
committed
Add CI
1 parent a28a3c7 commit 42284c7

File tree

2 files changed

+92
-7
lines changed

2 files changed

+92
-7
lines changed

.github/workflows/main.yml

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: build
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build-linux:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
- uses: goto-bus-stop/setup-zig@v2
11+
with:
12+
version: 0.13.0
13+
- name: prepare-linux
14+
if: runner.os == 'Linux'
15+
run: |
16+
sudo apt-get update
17+
sudo apt-get install libglu1-mesa-dev mesa-common-dev xorg-dev libasound-dev libsdl2-dev
18+
- name: build-native
19+
run: zig build --summary all
20+
- name: build-web
21+
run: zig build --summary all -Dtarget=wasm32-emscripten
22+
23+
build-macos:
24+
runs-on: macos-12
25+
steps:
26+
- uses: actions/checkout@v4
27+
- uses: goto-bus-stop/setup-zig@v2
28+
with:
29+
version: 0.13.0
30+
- name: prepare-macOS
31+
if: runner.os == 'macOS'
32+
run: |
33+
brew install sdl2
34+
- name: build-native
35+
run: zig build --summary all
36+
- name: build-web
37+
run: zig build --summary all -Dtarget=wasm32-emscripten
38+
39+
build-windows:
40+
runs-on: windows-latest
41+
strategy:
42+
matrix:
43+
target: [
44+
x86_64-windows-msvc,
45+
]
46+
steps:
47+
- uses: actions/checkout@v4
48+
- uses: goto-bus-stop/setup-zig@v2
49+
with:
50+
version: 0.13.0
51+
- name: Install VisualStudio (x64)
52+
uses: ilammy/msvc-dev-cmd@v1
53+
with:
54+
uwp: false
55+
arch: x64
56+
- name: Download SDL2 (Visual Studio)
57+
uses: carlosperate/download-file-action@v1.0.3
58+
with:
59+
file-url: https://www.libsdl.org/release/SDL2-devel-2.0.18-VC.zip
60+
file-name: SDL2.tar.gz
61+
location: .
62+
63+
- name: Extract SDL2
64+
uses: brunoborges/justextract@v1
65+
with:
66+
file: SDL2.tar.gz
67+
68+
- name: Create SDK file
69+
uses: DamianReeves/write-file-action@v1.2
70+
with:
71+
path: .build_config/sdl.json
72+
contents: |
73+
{
74+
"x86_64-windows-msvc": {
75+
"include": "SDL2-2.0.18/include",
76+
"libs": "SDL2-2.0.18/lib/x64",
77+
"bin": "SDL2-2.0.18/lib/x64"
78+
}
79+
}
80+
write-mode: overwrite
81+
- name: build-native
82+
run: zig build -Dtarget=${{matrix.target}} --summary all
83+
- name: build-web
84+
run: zig build --summary all -Dtarget=wasm32-emscripten

build.zig

+8-7
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ pub fn build(b: *std.Build) !void {
7979
const target = b.standardTargetOptions(.{});
8080
const optimize = b.standardOptimizeOption(.{});
8181
const platform = b.option([]const u8, "platform", "Plaftorm to use: sdl or sokol") orelse "sdl";
82-
const is_sdl_platform = !std.mem.eql(u8, platform, "sokol");
83-
const sdl_sdk = sdl.init(b, "");
82+
const is_sdl_platform = !target.result.isWasm() and !std.mem.eql(u8, platform, "sokol");
83+
const sdl_sdk = sdl.init(b, null);
8484

8585
_ = getZimpactModule(b, .{
8686
.optimize = optimize,
@@ -113,7 +113,6 @@ pub fn build(b: *std.Build) !void {
113113
// build Z Drop sample
114114
const sample: []const u8 = "zdrop";
115115
if (!target.result.isWasm()) {
116-
const run_step = b.step(b.fmt("run", .{}), b.fmt("Run {s}.zig example", .{sample}));
117116
// for native platforms, build into a regular executable
118117
const exe = b.addExecutable(.{
119118
.name = sample,
@@ -125,16 +124,18 @@ pub fn build(b: *std.Build) !void {
125124
sdl_sdk.link(exe, .dynamic);
126125
}
127126
exe.root_module.addImport("zimpact", mod_zi);
127+
const install_exe = b.addInstallArtifact(exe, .{});
128+
install_exe.step.dependOn(assets_step);
129+
b.getInstallStep().dependOn(&install_exe.step);
128130

129131
const run_cmd = b.addRunArtifact(exe);
130-
run_cmd.step.dependOn(&b.addInstallArtifact(exe, .{}).step);
132+
const run_step = b.step(b.fmt("run", .{}), b.fmt("Run {s}.zig example", .{sample}));
133+
run_cmd.step.dependOn(&install_exe.step);
134+
run_step.dependOn(&run_cmd.step);
131135

132136
if (b.args) |args| {
133137
run_cmd.addArgs(args);
134138
}
135-
136-
run_step.dependOn(assets_step);
137-
run_step.dependOn(&run_cmd.step);
138139
} else {
139140
try buildWeb(b, .{
140141
.root_source_file = b.path("samples/zdrop/main.zig"),

0 commit comments

Comments
 (0)