11const std = @import ("std" );
2+ const Step = std .Build .Step ;
23
34pub fn build (b : * std.Build ) void {
45 const target = b .standardTargetOptions (.{});
@@ -37,7 +38,9 @@ pub fn build(b: *std.Build) void {
3738 // To maintain the relative paths inside the files in src/
3839 lib .installHeadersDirectory (b .path ("include/GLFW" ), "include/GLFW" , .{});
3940 }
40- // GLFW headers depend on these headers, so they must be distributed too.
41+ //
42+ // Header packaging for easy cross compilation
43+ //
4144 if (b .lazyDependency ("vulkan_headers" , .{
4245 .target = target ,
4346 .optimize = optimize ,
@@ -60,7 +63,7 @@ pub fn build(b: *std.Build) void {
6063 }
6164 }
6265
63- if (target .result .isDarwin ()) {
66+ if (target .result .os . tag . isDarwin ()) {
6467 // MacOS: this must be defined for macOS 13.3 and older.
6568 lib .root_module .addCMacro ("__kernel_ptr_semantics" , "" );
6669
@@ -74,8 +77,12 @@ pub fn build(b: *std.Build) void {
7477 }
7578 }
7679
77- const include_src_flag = "-Isrc" ;
78-
80+ //
81+ // Source files
82+ //
83+ lib .addCSourceFiles (.{
84+ .files = & base_sources ,
85+ });
7986 switch (target .result .os .tag ) {
8087 .windows = > {
8188 lib .linkSystemLibrary ("gdi32" );
@@ -90,14 +97,9 @@ pub fn build(b: *std.Build) void {
9097 lib .linkSystemLibrary ("GLESv3" );
9198 }
9299
93- const flags = [_ ][]const u8 { "-D_GLFW_WIN32" , include_src_flag };
94- lib .addCSourceFiles (.{
95- .files = & base_sources ,
96- .flags = & flags ,
97- });
100+ lib .root_module .addCMacro ("_GLFW_WIN32" , "1" );
98101 lib .addCSourceFiles (.{
99102 .files = & windows_sources ,
100- .flags = & flags ,
101103 });
102104 },
103105 .macos = > {
@@ -126,44 +128,35 @@ pub fn build(b: *std.Build) void {
126128 lib .linkFramework ("OpenGL" );
127129 }
128130
129- const flags = [_ ][]const u8 { "-D_GLFW_COCOA" , include_src_flag };
130- lib .addCSourceFiles (.{
131- .files = & base_sources ,
132- .flags = & flags ,
133- });
131+ lib .root_module .addCMacro ("_GLFW_COCOA" , "1" );
134132 lib .addCSourceFiles (.{
135133 .files = & macos_sources ,
136- .flags = & flags ,
137134 });
138135 },
139136
140137 // everything that isn't windows or mac is linux :P
141138 else = > {
142- var sources = std .BoundedArray ([]const u8 , 64 ).init (0 ) catch unreachable ;
143- var flags = std .BoundedArray ([]const u8 , 16 ).init (0 ) catch unreachable ;
144-
145- sources .appendSlice (& base_sources ) catch unreachable ;
146- sources .appendSlice (& linux_sources ) catch unreachable ;
139+ lib .addCSourceFiles (.{
140+ .files = & linux_sources ,
141+ });
147142
148143 if (use_x11 ) {
149- sources .appendSlice (& linux_x11_sources ) catch unreachable ;
150- flags .append ("-D_GLFW_X11" ) catch unreachable ;
144+ lib .root_module .addCMacro ("_GLFW_X11" , "1" );
145+ lib .addCSourceFiles (.{
146+ .files = & linux_x11_sources ,
147+ });
151148 }
152149
153150 if (use_wl ) {
154- lib .root_module .addCMacro ("WL_MARSHAL_FLAG_DESTROY" , "1" );
155-
156- sources .appendSlice (& linux_wl_sources ) catch unreachable ;
157- flags .append ("-D_GLFW_WAYLAND" ) catch unreachable ;
158- flags .append ("-Wno-implicit-function-declaration" ) catch unreachable ;
151+ lib .root_module .addCMacro ("_GLFW_WAYLAND" , "1" );
152+
153+ lib .addCSourceFiles (.{
154+ .files = & linux_wl_sources ,
155+ .flags = &.{
156+ "-Wno-implicit-function-declaration" ,
157+ },
158+ });
159159 }
160-
161- flags .append (include_src_flag ) catch unreachable ;
162-
163- lib .addCSourceFiles (.{
164- .files = sources .slice (),
165- .flags = flags .slice (),
166- });
167160 },
168161 }
169162 b .installArtifact (lib );
0 commit comments