Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#465 change from defineCMacro to addCMacro #466

Merged
merged 1 commit into from
Dec 24, 2024

Conversation

zigster64
Copy link
Contributor

@zigster64 zigster64 commented Dec 24, 2024

Small change to build.zig due to change in the zig build system, in the way it passes C Macros from the Zig build system to the target

defineCMacro() -> deprecated in favour of -> root_lib.addCMacro()

Recently deprecated & removed from the zig compiler
ziglang/zig@142471f

This change has no effect on libxlswriter itself - its a zig issue, no a libxlswriter issue

Tested - built using a patched zig-libxlswriter, and added to my app for end 2 end test to generate spreadsheets.

@zigster64
Copy link
Contributor Author

@kassane - you want to review this change please

Tested using this https://github.com/zigster64/zig-xlsxwriter/blob/fix-add-c-macro/build.zig.zon to build the zig lib using the above changes. So you will need to update the hash in your main lib. Thanks

@kassane
Copy link
Contributor

kassane commented Dec 24, 2024

Nice contribution. This closes #465

If you want, you could extend the change, based on:

suggestion patch
diff --git a/build.zig b/build.zig
index a4450916..c80f9df5 100644
--- a/build.zig
+++ b/build.zig
@@ -35,7 +35,7 @@ pub fn build(b: *std.Build) void {
     }
     if (tests)
         lib.root_module.addCMacro("TESTING", "");
-    lib.addCSourceFiles(.{
+    lib.root_module.addCSourceFiles(.{
         .files = &.{
             "src/vml.c",
             "src/chartsheet.c",
@@ -69,7 +69,7 @@ pub fn build(b: *std.Build) void {
 
     // minizip
     if (minizip) {
-        lib.addCSourceFiles(.{
+        lib.root_module.addCSourceFiles(.{
             .files = switch (lib.rootModuleTarget().os.tag) {
                 .windows => minizip_src ++ [_][]const u8{
                     "third_party/minizip/iowin32.c",
@@ -86,31 +86,31 @@ pub fn build(b: *std.Build) void {
 
     // md5
     if (!md5)
-        lib.addCSourceFile(.{
+        lib.root_module.addCSourceFile(.{
             .file = b.path("third_party/md5/md5.c"),
             .flags = cflags,
         })
     else
-        lib.linkSystemLibrary("crypto");
+        lib.root_module.linkSystemLibrary("crypto", .{});
 
     // dtoa
     if (dtoa)
-        lib.addCSourceFile(.{
+        lib.root_module.addCSourceFile(.{
             .file = b.path("third_party/dtoa/emyg_dtoa.c"),
             .flags = cflags,
         });
 
     // tmpfileplus
     if (stdtmpfile)
-        lib.addCSourceFile(.{
+        lib.root_module.addCSourceFile(.{
             .file = b.path("third_party/tmpfileplus/tmpfileplus.c"),
             .flags = cflags,
         })
     else
         lib.root_module.addCMacro("USE_STANDARD_TMPFILE", "");
 
-    lib.addIncludePath(b.path("include"));
-    lib.addIncludePath(b.path("third_party"));
+    lib.root_module.addIncludePath(b.path("include"));
+    lib.root_module.addIncludePath(b.path("third_party"));
     lib.linkLibC();
 
     // get headers on include to zig-out/include
@@ -253,7 +253,7 @@ fn buildExe(b: *std.Build, info: BuildInfo) void {
         .optimize = info.lib.root_module.optimize.?,
         .target = info.lib.root_module.resolved_target.?,
     });
-    exe.addCSourceFile(.{
+    exe.root_module.addCSourceFile(.{
         .file = b.path(info.path),
         .flags = cflags,
     });
@@ -284,19 +284,19 @@ fn buildTest(b: *std.Build, info: BuildInfo) void {
         .target = info.lib.root_module.resolved_target.?,
     });
     exe.root_module.addCMacro("TESTING", "");
-    exe.addCSourceFile(.{
+    exe.root_module.addCSourceFile(.{
         .file = b.path(info.path),
         .flags = cflags,
     });
-    exe.addCSourceFile(.{
+    exe.root_module.addCSourceFile(.{
         .file = b.path("test/unit/test_all.c"),
         .flags = cflags,
     });
-    exe.addIncludePath(b.path("test/unit"));
+    exe.root_module.addIncludePath(b.path("test/unit"));
     for (info.lib.root_module.include_dirs.items) |include| {
         exe.root_module.include_dirs.append(b.allocator, include) catch {};
     }
-    exe.linkLibrary(info.lib);
+    exe.root_module.linkLibrary(info.lib);
     exe.linkLibC();
     b.installArtifact(exe);
 
@@ -347,7 +347,7 @@ fn buildZlib(b: *std.Build, options: anytype) *std.Build.Step.Compile {
         .optimize = options[1],
     })) |zlib_path| {
         libz.addIncludePath(zlib_path.path(""));
-        libz.addCSourceFiles(.{
+        libz.root_module.addCSourceFiles(.{
             .root = zlib_path.path(""),
             .files = &.{
                 "adler32.c",

build output

libxlsxwriter git:(fix-add-c-macro) ✗ ~/zig/0.13.0/files/zig build --summary all
Build Summary: 5/5 steps succeeded
install success
└─ install xlsxwriter success
   └─ zig build-lib xlsxwriter Debug native success 1s MaxRSS:145M
      ├─ zig build-lib z Debug native success 196ms MaxRSS:80M
      └─ WriteFile zconf.h successlibxlsxwriter git:(fix-add-c-macro) ✗ rm -fr .zig-cache/ zig-out/   libxlsxwriter git:(fix-add-c-macro) ✗ ~/zig/master/files/zig version            
0.14.0-dev.2546+0ff0bdb4a              libxlsxwriter git:(fix-add-c-macro) ✗ ~/zig/master/files/zig build --summary all
Build Summary: 5/5 steps succeeded
install success
└─ install xlsxwriter success
   └─ zig build-lib xlsxwriter Debug native success 1s MaxRSS:149M
      ├─ WriteFile zconf.h success
      ├─ zig build-lib z Debug native success 188ms MaxRSS:83M
      └─ zig build-lib z Debug native (reused)

cc: @jmcnamara

@jmcnamara jmcnamara merged commit da3628d into jmcnamara:main Dec 24, 2024
50 checks passed
@jmcnamara
Copy link
Owner

Merged. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants