forked from raylib-zig/raylib-zig
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject_setup.ps1
More file actions
97 lines (78 loc) · 2.95 KB
/
project_setup.ps1
File metadata and controls
97 lines (78 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
if ($args.Count -ne 1) {
$PROJECT_NAME = 'Project'
} else {
$PROJECT_NAME = $args[0]
}
New-Item -Name $PROJECT_NAME -ItemType Directory -ErrorAction Stop
Set-Location -Path $PROJECT_NAME -ErrorAction Stop
Write-Output "Generating project files..."
zig init
Remove-Item "build.zig", "src\root.zig"
$BUILD_DOT_ZIG = @"
const std = @import("std");
const rlz = @import("raylib_zig");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const raylib_dep = b.dependency("raylib_zig", .{
.target = target,
.optimize = optimize,
});
const raylib = raylib_dep.module("raylib");
const raylib_artifact = raylib_dep.artifact("raylib");
const exe_mod = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe_mod.addImport("raylib", raylib);
const run_step = b.step("run", "Run the app");
//web exports are completely separate
if (target.query.os_tag == .emscripten) {
const emsdk = rlz.emsdk;
const wasm = b.addLibrary(.{
.name = "$PROJECT_NAME",
.root_module = exe_mod,
});
const install_dir: std.Build.InstallDir = .{ .custom = "web" };
const emcc_flags = emsdk.emccDefaultFlags(b.allocator, .{
.optimize = optimize,
});
const emcc_settings = emsdk.emccDefaultSettings(b.allocator, .{
.optimize = optimize,
});
const emcc_step = emsdk.emccStep(b, raylib_artifact, wasm, .{
.optimize = optimize,
.flags = emcc_flags,
.settings = emcc_settings,
.shell_file_path = emsdk.shell(raylib_dep.builder),
.install_dir = install_dir,
.embed_paths = &.{.{ .src_path = "resources/" }},
});
b.getInstallStep().dependOn(emcc_step);
const html_filename = try std.fmt.allocPrint(b.allocator, "{s}.html", .{wasm.name});
const emrun_step = emsdk.emrunStep(
b,
b.getInstallPath(install_dir, html_filename),
&.{},
);
emrun_step.dependOn(emcc_step);
run_step.dependOn(emrun_step);
} else {
const exe = b.addExecutable(.{
.name = "$PROJECT_NAME",
.root_module = exe_mod,
});
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
run_step.dependOn(&run_cmd.step);
}
}
"@
New-Item -Name "build.zig" -ItemType "file" -Value $BUILD_DOT_ZIG -Force
zig fetch --save git+https://github.com/raylib-zig/raylib-zig#devel
zig fetch --save=emsdk git+https://github.com/emscripten-core/emsdk#4.0.9
New-Item -Name "resources" -ItemType "directory"
New-Item -Name "resources/placeholder.txt" -ItemType "file" -Value "" -Force
Copy-Item -Path "../examples/core/basic_window.zig" -Destination "src/main.zig"