From 9d8ef8e3004ad28176a9991f814afffa0d02f63e Mon Sep 17 00:00:00 2001 From: fjebaker Date: Sat, 9 Dec 2023 20:34:21 +0000 Subject: [PATCH 1/4] feat: added minimal build.zig for md4c --- build.zig | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 build.zig diff --git a/build.zig b/build.zig new file mode 100644 index 00000000..7ee9072b --- /dev/null +++ b/build.zig @@ -0,0 +1,44 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) !void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + const shared = b.option( + bool, + "shared", + "Build wd4c as a shared library", + ) orelse false; + + const lib = if (shared) + b.addSharedLibrary(.{ + .name = "md4c", + .target = target, + .optimize = optimize, + .version = .{ .major = 0, .minor = 4, .patch = 9 }, + }) + else + b.addStaticLibrary(.{ + .name = "md4c", + .target = target, + .optimize = optimize, + }); + + lib.defineCMacro("MD4C_USE_UTF8", ""); + lib.addCSourceFiles(.{ + .files = &md4c_sources, + .flags = &md4c_flags, + }); + lib.linkLibC(); + lib.installHeader("src/md4c.h", "md4c.h"); + + b.installArtifact(lib); +} + +const md4c_flags = [_][]const u8{ + "-Wall", +}; + +const md4c_sources = [_][]const u8{ + "src/md4c.c", +}; From 2416c31507ebf0d68ba48ecccdaac5723eb4b74a Mon Sep 17 00:00:00 2001 From: fjebaker Date: Sat, 27 Apr 2024 12:33:48 +0100 Subject: [PATCH 2/4] feat: rework build.zig for 0.12.0 --- build.zig | 87 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 77 insertions(+), 10 deletions(-) diff --git a/build.zig b/build.zig index 7ee9072b..300d2099 100644 --- a/build.zig +++ b/build.zig @@ -1,21 +1,35 @@ const std = @import("std"); +const VERSION: std.SemanticVersion = .{ + .major = 0, + .minor = 4, + .patch = 8, +}; + pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - const shared = b.option( - bool, - "shared", - "Build wd4c as a shared library", - ) orelse false; + // On Windows, given there is no standard lib install dir etc., we rather + // by default build static lib. + const build_shared = !target.result.isMinGW(); + + // build options + var with_utf8 = b.option(bool, "utf8", "Use UTF8") orelse false; + const with_utf16 = b.option(bool, "utf16", "Use UTF16") orelse false; + const with_ascii = b.option(bool, "ascii", "Use UTF8") orelse false; - const lib = if (shared) + // defaults to UTF8 if nothing else set + if (!with_utf8 and !with_utf16 and !with_ascii) { + with_utf8 = true; + } + + const lib = if (build_shared) b.addSharedLibrary(.{ .name = "md4c", .target = target, .optimize = optimize, - .version = .{ .major = 0, .minor = 4, .patch = 9 }, + .version = VERSION, }) else b.addStaticLibrary(.{ @@ -24,15 +38,60 @@ pub fn build(b: *std.Build) !void { .optimize = optimize, }); - lib.defineCMacro("MD4C_USE_UTF8", ""); lib.addCSourceFiles(.{ .files = &md4c_sources, .flags = &md4c_flags, }); - lib.linkLibC(); - lib.installHeader("src/md4c.h", "md4c.h"); + setDefines(lib, with_utf8, with_utf16, with_ascii); + lib.linkLibC(); + lib.installHeader(.{ .path = "src/md4c.h" }, "md4c.h"); b.installArtifact(lib); + + const exe = b.addExecutable(.{ + .name = "md2html", + .target = target, + .optimize = optimize, + }); + + setDefines(exe, with_utf8, with_utf16, with_ascii); + exe.addCSourceFiles(.{ + .files = &md2html_sources, + .flags = &md4c_flags, + }); + exe.linkLibC(); + + const install_exe = b.addInstallArtifact(exe, .{}); + const md2html_step = b.step("md2html", "Compile the md2html executable"); + md2html_step.dependOn(&install_exe.step); +} + +fn setDefines( + lib_or_exe: *std.Build.Step.Compile, + with_utf8: bool, + with_utf16: bool, + with_ascii: bool, +) void { + lib_or_exe.root_module.addCMacro( + "MD_VERSION_MAJOR", + std.fmt.comptimePrint("{d}", .{VERSION.major}), + ); + lib_or_exe.root_module.addCMacro( + "MD_VERSION_MINOR", + std.fmt.comptimePrint("{d}", .{VERSION.minor}), + ); + lib_or_exe.root_module.addCMacro( + "MD_VERSION_RELEASE", + std.fmt.comptimePrint("{d}", .{VERSION.patch}), + ); + + if (with_utf8) { + lib_or_exe.defineCMacro("MD4C_USE_UTF8", "1"); + } else if (with_ascii) { + lib_or_exe.defineCMacro("MD4C_USE_ASCII", "1"); + } else if (with_utf16) { + lib_or_exe.defineCMacro("MD4C_USE_UTF16", "1"); + } } const md4c_flags = [_][]const u8{ @@ -42,3 +101,11 @@ const md4c_flags = [_][]const u8{ const md4c_sources = [_][]const u8{ "src/md4c.c", }; + +const md2html_sources = [_][]const u8{ + "src/md4c.c", + "src/md4c-html.c", + "src/entity.c", + "md2html/cmdline.c", + "md2html/md2html.c", +}; From 7933a0c0fb65b39b65f709143d03cb5f177cff48 Mon Sep 17 00:00:00 2001 From: fjebaker Date: Mon, 6 May 2024 16:34:51 +0100 Subject: [PATCH 3/4] fix(build.zig): expose shared option --- build.zig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/build.zig b/build.zig index 300d2099..e58dabbc 100644 --- a/build.zig +++ b/build.zig @@ -12,7 +12,11 @@ pub fn build(b: *std.Build) !void { // On Windows, given there is no standard lib install dir etc., we rather // by default build static lib. - const build_shared = !target.result.isMinGW(); + const build_shared = b.option( + bool, + "md4c-shared", + "Build md4c as a shared library", + ) orelse !target.result.isMinGW(); // build options var with_utf8 = b.option(bool, "utf8", "Use UTF8") orelse false; From 39d5b06c8c873a0042843b2c9ca2b23bdbe84db7 Mon Sep 17 00:00:00 2001 From: fjebaker Date: Thu, 30 May 2024 12:02:10 +0100 Subject: [PATCH 4/4] feat: update for zig 0.13.0-dev.339+6b020c3d1 --- build.zig | 2 +- src/md4c.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.zig b/build.zig index e58dabbc..2829ca3a 100644 --- a/build.zig +++ b/build.zig @@ -49,7 +49,7 @@ pub fn build(b: *std.Build) !void { setDefines(lib, with_utf8, with_utf16, with_ascii); lib.linkLibC(); - lib.installHeader(.{ .path = "src/md4c.h" }, "md4c.h"); + lib.installHeader(b.path("src/md4c.h"), "md4c.h"); b.installArtifact(lib); const exe = b.addExecutable(.{ diff --git a/src/md4c.h b/src/md4c.h index 8d6be1cb..e4a34746 100644 --- a/src/md4c.h +++ b/src/md4c.h @@ -164,7 +164,7 @@ typedef enum MD_TEXTTYPE { MD_TEXT_SOFTBR, /* '\n' in source text where it is not semantically meaningful (soft break) */ /* Entity. - * (a) Named entity, e.g.   + * (a) Named entity, e.g.   * (Note MD4C does not have a list of known entities. * Anything matching the regexp /&[A-Za-z][A-Za-z0-9]{1,47};/ is * treated as a named entity.)