@@ -8,22 +8,34 @@ pub fn build(b: *std.Build) !void {
88 const target = b .standardTargetOptions (.{});
99 const optimize = b .standardOptimizeOption (.{});
1010
11+ const linkage = b .option (
12+ std .builtin .LinkMode ,
13+ "linkage" ,
14+ "`.static` or `.dynamic` (default is `.dynamic`)" ,
15+ ) orelse .dynamic ;
16+
1117 const sdl_dep = b .dependency ("sdl" , .{});
1218 const sdl_ttf_dep = b .dependency ("sdl_ttf" , .{});
13- const freetype_dep = b .dependency ("freetype" , .{});
19+ const freetype_dep = b .dependency ("freetype" , .{
20+ .linkage = linkage ,
21+ .optimize = optimize ,
22+ });
1423 const wayland_scanner_dep = b .dependency ("wayland_scanner" , .{
15- .target = b .host ,
24+ .target = b .graph . host ,
1625 .optimize = .ReleaseFast ,
1726 });
1827 const font_dep = b .dependency ("fonts" , .{});
1928
2029 //
2130
22- const lib = b .addStaticLibrary (.{
31+ const lib = b .addLibrary (.{
2332 .name = "SDL3" ,
24- .target = target ,
25- .optimize = optimize ,
26- .strip = true ,
33+ .linkage = linkage ,
34+ .root_module = b .createModule (.{
35+ .root_source_file = null ,
36+ .target = target ,
37+ .optimize = optimize ,
38+ }),
2739 });
2840 {
2941 lib .addIncludePath (sdl_dep .path ("src" ));
@@ -41,12 +53,12 @@ pub fn build(b: *std.Build) !void {
4153 .ReleaseFast , .ReleaseSmall , .ReleaseSafe = > 0 ,
4254 .Debug = > 3 ,
4355 };
44- lib .defineCMacro ("SDL_ASSERT_LEVEL" , b .fmt ("{d}" , .{SDL_ASSERT_LEVEL }));
56+ lib .root_module . addCMacro ("SDL_ASSERT_LEVEL" , b .fmt ("{d}" , .{SDL_ASSERT_LEVEL }));
4557
4658 if (optimize != .Debug ) {
47- lib .defineCMacro ("NDEBUG" , "1" );
48- lib .defineCMacro ("__FILE__" , "\" __FILE__\" " );
49- lib .defineCMacro ("__LINE__" , "0" );
59+ lib .root_module . addCMacro ("NDEBUG" , "1" );
60+ lib .root_module . addCMacro ("__FILE__" , "\" __FILE__\" " );
61+ lib .root_module . addCMacro ("__LINE__" , "0" );
5062 }
5163
5264 lib .linkLibC ();
@@ -65,7 +77,7 @@ pub fn build(b: *std.Build) !void {
6577 lib .linkSystemLibrary ("version" );
6678 lib .linkSystemLibrary ("oleaut32" );
6779 lib .linkSystemLibrary ("ole32" );
68- lib .defineCMacro ("SDL_USE_BUILTIN_OPENGL_DEFINITIONS" , "1" );
80+ lib .root_module . addCMacro ("SDL_USE_BUILTIN_OPENGL_DEFINITIONS" , "1" );
6981 },
7082 .macos = > {
7183 lib .addCSourceFiles (.{
@@ -78,7 +90,7 @@ pub fn build(b: *std.Build) !void {
7890 .files = & objective_c_src_files ,
7991 .flags = &.{"-fobjc-arc" },
8092 });
81- lib .defineCMacro ("SDL_USE_BUILTIN_OPENGL_DEFINITIONS" , "1" );
93+ lib .root_module . addCMacro ("SDL_USE_BUILTIN_OPENGL_DEFINITIONS" , "1" );
8294
8395 // TODO: re-check which frameworks are needed
8496 lib .linkFramework ("AudioToolbox" );
@@ -94,14 +106,14 @@ pub fn build(b: *std.Build) !void {
94106 lib .linkFramework ("CoreVideo" );
95107 lib .linkFramework ("ForceFeedback" );
96108 lib .linkFramework ("Foundation" );
97- lib .linkFrameworkWeak ("GameController" );
109+ lib .linkFramework ("GameController" );
98110 lib .linkFramework ("IOKit" );
99- lib .linkFrameworkWeak ("Metal" );
100- lib .linkFrameworkWeak ("QuartzCore" );
101- lib .linkFrameworkWeak ("UniformTypeIdentifiers" );
111+ lib .linkFramework ("Metal" );
112+ lib .linkFramework ("QuartzCore" );
113+ lib .linkFramework ("UniformTypeIdentifiers" );
102114 lib .linkSystemLibrary ("objc" );
103115
104- const sdk = std .zig .system .darwin .getSdk (b .allocator , b .host .result ) orelse
116+ const sdk = std .zig .system .darwin .getSdk (b .allocator , b .graph . host .result ) orelse
105117 @panic ("macOS SDK is missing" );
106118 lib .addSystemIncludePath (.{ .cwd_relative = b .pathJoin (&.{ sdk , "/usr/include" }) });
107119 lib .addSystemFrameworkPath (.{ .cwd_relative = b .pathJoin (&.{ sdk , "/System/Library/Frameworks" }) });
@@ -345,8 +357,6 @@ pub fn build(b: *std.Build) !void {
345357 .SDL_CAMERA_DRIVER_DUMMY = 1 ,
346358 .SDL_CAMERA_DRIVER_V4L2 = 1 ,
347359
348- // #define DYNAPI_NEEDS_DLOPEN 1
349-
350360 .SDL_USE_IME = 1 ,
351361
352362 .SDL_LIBDECOR_VERSION_MAJOR = 0 ,
@@ -361,12 +371,33 @@ pub fn build(b: *std.Build) !void {
361371 .SDL_PROCESS_POSIX = 1 ,
362372 .SDL_PROCESS_DUMMY = 1 ,
363373 };
364- lib .installConfigHeader (b .addConfigHeader (.{
365- .style = .{ .cmake = sdl_dep .path (
366- "include/build_config/SDL_build_config.h.cmake" ,
367- ) },
374+
375+ const fix_header_exe = b .addExecutable (.{
376+ .name = "fix-header" ,
377+ .root_module = b .createModule (.{
378+ .root_source_file = b .path ("src/fix_header.zig" ),
379+ .target = b .graph .host ,
380+ .optimize = optimize ,
381+ }),
382+ });
383+ const fix_header = b .addRunArtifact (fix_header_exe );
384+ {
385+ fix_header .addFileArg (sdl_dep .path ("include/build_config/SDL_build_config.h.cmake" ));
386+ }
387+ const fixed_header = fix_header .captureStdOut ();
388+
389+ const installFixedHeader = b .addInstallFile (fixed_header , "fixed_header.h" );
390+
391+ const config_header = b .addConfigHeader (.{
392+ .style = .{ .cmake = fixed_header },
368393 .include_path = "SDL_build_config.h" ,
369- }, values ));
394+ }, values );
395+
396+ // NOTE: needed to allow `b.addConfigHeader` to use a generated
397+ // file with `.cmake`. (zig build system issue?)
398+ config_header .step .dependOn (& installFixedHeader .step );
399+
400+ lib .installConfigHeader (config_header );
370401
371402 lib .addCSourceFiles (.{
372403 .root = sdl_dep .path ("" ),
@@ -376,18 +407,22 @@ pub fn build(b: *std.Build) !void {
376407
377408 inline for (std .meta .fields (@TypeOf (values ))) | f | {
378409 const value = b .fmt ("{any}" , .{@field (values , f .name )});
379- lib .defineCMacro (f .name , value );
410+ lib .root_module .addCMacro (f .name , value );
411+ }
412+
413+ if (linkage == .dynamic ) {
414+ lib .setVersionScript (sdl_dep .path ("src/dynapi/SDL_dynapi.sym" ));
380415 }
381416
382417 // SDL3_DYNAMIC_API=/my/actual/libSDL3.so.0
383418 //
384419 // If we want to _avoid_ dyn api, we can do so:
385- // lib.defineCMacro ("SDL_dynapi_h_", "1");
386- // lib.defineCMacro ("SDL_DYNAMIC_API", "0");
420+ // lib.root_module.addCMacro ("SDL_dynapi_h_", "1");
421+ // lib.root_module.addCMacro ("SDL_DYNAMIC_API", "0");
387422
388423 // Avoid
389424 // SDL/include/build_config/SDL_build_config_minimal.h
390- lib .defineCMacro ("SDL_build_config_minimal_h_" , "1" );
425+ // lib.root_module.addCMacro ("SDL_build_config_minimal_h_", "1");
391426
392427 //--
393428
@@ -485,25 +520,14 @@ pub fn build(b: *std.Build) !void {
485520 b .installArtifact (lib );
486521 }
487522
488- // needed to allow SDL_ttf to #include "SDL.h"
489- const sdl_for_libs = b .addStaticLibrary (.{
490- .name = "SDL3-for-libs" ,
491- .target = target ,
492- .optimize = optimize ,
493- .root_source_file = b .addWriteFiles ().add ("stub.c" , "" ),
494- .strip = true ,
495- });
496- {
497- sdl_for_libs .addIncludePath (sdl_dep .path ("include" ));
498- sdl_for_libs .installHeadersDirectory (sdl_dep .path ("include" ), "" , .{});
499- b .installArtifact (sdl_for_libs );
500- }
501-
502- const SDL_ttf = b .addStaticLibrary (.{
523+ const SDL_ttf = b .addLibrary (.{
503524 .name = "SDL3_ttf" ,
504- .target = target ,
505- .optimize = optimize ,
506- .strip = true ,
525+ .linkage = linkage ,
526+ .root_module = b .createModule (.{
527+ .root_source_file = null ,
528+ .target = target ,
529+ .optimize = optimize ,
530+ }),
507531 });
508532 {
509533 SDL_ttf .addCSourceFiles (.{
@@ -521,16 +545,17 @@ pub fn build(b: *std.Build) !void {
521545 SDL_ttf .installHeadersDirectory (sdl_ttf_dep .path ("include/SDL3_ttf" ), "SDL3_ttf" , .{});
522546
523547 SDL_ttf .linkLibrary (freetype_dep .artifact ("freetype" ));
548+ SDL_ttf .linkLibrary (lib );
524549
525550 if (target .result .os .tag == .macos ) {
526- const sdk = std .zig .system .darwin .getSdk (b .allocator , b .host .result ) orelse
551+ const sdk = std .zig .system .darwin .getSdk (b .allocator , b .graph . host .result ) orelse
527552 @panic ("macOS SDK is missing" );
528553 SDL_ttf .addSystemIncludePath (.{ .cwd_relative = b .pathJoin (&.{ sdk , "/usr/include" }) });
529554 SDL_ttf .addSystemFrameworkPath (.{ .cwd_relative = b .pathJoin (&.{ sdk , "/System/Library/Frameworks" }) });
530555 SDL_ttf .addLibraryPath (.{ .cwd_relative = b .pathJoin (&.{ sdk , "/usr/lib" }) });
531556 }
532557
533- SDL_ttf .linkLibrary ( sdl_for_libs );
558+ SDL_ttf .addIncludePath ( sdl_dep . path ( "include" ) );
534559
535560 b .installArtifact (SDL_ttf );
536561 }
@@ -545,7 +570,6 @@ pub fn build(b: *std.Build) !void {
545570 \\});
546571 \\pub const fonts = @import("fonts");
547572 ),
548- .link_libc = true ,
549573 });
550574 {
551575 module .linkLibrary (lib );
@@ -577,12 +601,11 @@ pub fn build(b: *std.Build) !void {
577601 .target = target ,
578602 .root_source_file = b .path (b .fmt ("src/{s}.zig" , .{name })),
579603 .optimize = optimize ,
580- .strip = true ,
581604 });
582605 exe .root_module .addImport ("sdl" , module );
583606
584607 if (target .result .os .tag == .macos ) {
585- const sdk = std .zig .system .darwin .getSdk (b .allocator , b .host .result ) orelse
608+ const sdk = std .zig .system .darwin .getSdk (b .allocator , b .graph . host .result ) orelse
586609 @panic ("macOS SDK is missing" );
587610 exe .addSystemIncludePath (.{ .cwd_relative = b .pathJoin (&.{ sdk , "/usr/include" }) });
588611 exe .addSystemFrameworkPath (.{ .cwd_relative = b .pathJoin (&.{ sdk , "/System/Library/Frameworks" }) });
@@ -855,7 +878,7 @@ pub fn build(b: *std.Build) !void {
855878 exe .linkLibrary (test_utils );
856879
857880 if (target .result .os .tag == .macos ) {
858- const sdk = std .zig .system .darwin .getSdk (b .allocator , b .host .result ) orelse
881+ const sdk = std .zig .system .darwin .getSdk (b .allocator , b .graph . host .result ) orelse
859882 @panic ("macOS SDK is missing" );
860883 exe .addSystemIncludePath (.{ .cwd_relative = b .pathJoin (&.{ sdk , "/usr/include" }) });
861884 exe .addSystemFrameworkPath (.{ .cwd_relative = b .pathJoin (&.{ sdk , "/System/Library/Frameworks" }) });
@@ -928,7 +951,7 @@ pub fn build(b: *std.Build) !void {
928951 exe .linkLibrary (lib );
929952
930953 if (target .result .os .tag == .macos ) {
931- const sdk = std .zig .system .darwin .getSdk (b .allocator , b .host .result ) orelse
954+ const sdk = std .zig .system .darwin .getSdk (b .allocator , b .graph . host .result ) orelse
932955 @panic ("macOS SDK is missing" );
933956 exe .addSystemIncludePath (.{ .cwd_relative = b .pathJoin (&.{ sdk , "/usr/include" }) });
934957 exe .addSystemFrameworkPath (.{ .cwd_relative = b .pathJoin (&.{ sdk , "/System/Library/Frameworks" }) });
@@ -1025,14 +1048,14 @@ const generic_src_files = [_][]const u8{
10251048 "src/gpu/vulkan/SDL_gpu_vulkan.c" ,
10261049
10271050 "src/haptic/SDL_haptic.c" ,
1028- "src/haptic/dummy/SDL_syshaptic.c" ,
1051+ // "src/haptic/dummy/SDL_syshaptic.c",
10291052
10301053 "src/hidapi/SDL_hidapi.c" ,
10311054
10321055 "src/joystick/SDL_gamepad.c" ,
10331056 "src/joystick/SDL_joystick.c" ,
10341057 "src/joystick/SDL_steam_virtual_gamepad.c" ,
1035- // "src/joystick/dummy/SDL_sysjoystick.c",
1058+ "src/joystick/dummy/SDL_sysjoystick.c" ,
10361059 "src/joystick/controller_type.c" ,
10371060 "src/joystick/virtual/SDL_virtualjoystick.c" ,
10381061
@@ -1078,7 +1101,7 @@ const generic_src_files = [_][]const u8{
10781101 "src/power/SDL_power.c" ,
10791102
10801103 "src/process/SDL_process.c" ,
1081- "src/process/dummy/SDL_dummyprocess.c" ,
1104+ // "src/process/dummy/SDL_dummyprocess.c",
10821105
10831106 "src/render/SDL_d3dmath.c" ,
10841107 "src/render/SDL_render.c" ,
@@ -1154,7 +1177,7 @@ const generic_src_files = [_][]const u8{
11541177 "src/timer/SDL_timer.c" ,
11551178
11561179 "src/tray/SDL_tray_utils.c" ,
1157- "src/tray/dummy/SDL_tray.c" ,
1180+ // "src/tray/dummy/SDL_tray.c",
11581181
11591182 "src/video/SDL_RLEaccel.c" ,
11601183 "src/video/SDL_blit.c" ,
0 commit comments