Skip to content

Commit 8e40d4b

Browse files
committed
more libraries impl
1 parent 6189a42 commit 8e40d4b

File tree

3 files changed

+230
-1
lines changed

3 files changed

+230
-1
lines changed

build.zig

Lines changed: 220 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,15 @@ const boost_libs = [_][]const u8{
116116
"coroutine2", // need boost.context
117117
};
118118

119-
pub fn build(b: *std.Build) !void {
119+
pub fn build(b: *std.Build) void {
120120
const target = b.standardTargetOptions(.{});
121121
const optimize = b.standardOptimizeOption(.{});
122122

123123
const boost = boostLibraries(b, .{
124124
.target = target,
125125
.optimize = optimize,
126126
.module = .{
127+
.atomic = b.option(bool, "atomic", "Build boost.atomic library (default: false)") orelse false,
127128
.charconv = b.option(bool, "charconv", "Build boost.charconv library (default: false)") orelse false,
128129
.cobalt = b.option(bool, "cobalt", "Build boost.cobalt library (default: false)") orelse false,
129130
.container = b.option(bool, "container", "Build boost.container library (default: false)") orelse false,
@@ -136,8 +137,12 @@ pub fn build(b: *std.Build) !void {
136137
.log = b.option(bool, "log", "Build boost.log library (default: false)") orelse false,
137138
.process = b.option(bool, "process", "Build boost.process library (default: false)") orelse false,
138139
.random = b.option(bool, "random", "Build boost.random library (default: false)") orelse false,
140+
.regex = b.option(bool, "regex", "Build boost.regex library (default: false)") orelse false,
139141
.serialization = b.option(bool, "serialization", "Build boost.serialization library (default: false)") orelse false,
142+
.stacktrace = b.option(bool, "stacktrace", "Build boost.stacktrace library (default: false)") orelse false,
140143
.system = b.option(bool, "system", "Build boost.system library (default: false)") orelse false,
144+
.url = b.option(bool, "url", "Build boost.url library (default: false)") orelse false,
145+
.wave = b.option(bool, "wave", "Build boost.wave library (default: false)") orelse false,
141146
},
142147
});
143148
b.installArtifact(boost);
@@ -183,6 +188,9 @@ pub fn boostLibraries(b: *std.Build, config: Config) *std.Build.Step.Compile {
183188
.flags = cxxFlags,
184189
});
185190
if (config.module) |module| {
191+
if (module.atomic) {
192+
buildAtomic(b, lib);
193+
}
186194
if (module.cobalt) {
187195
buildCobalt(b, lib);
188196
}
@@ -225,6 +233,18 @@ pub fn boostLibraries(b: *std.Build, config: Config) *std.Build.Step.Compile {
225233
if (module.system) {
226234
buildSystem(b, lib);
227235
}
236+
if (module.stacktrace) {
237+
buildStacktrace(b, lib);
238+
}
239+
if (module.regex) {
240+
buildRegex(b, lib);
241+
}
242+
if (module.url) {
243+
buildURL(b, lib);
244+
}
245+
if (module.wave) {
246+
buildWave(b, lib);
247+
}
228248
}
229249
if (lib.rootModuleTarget().abi == .msvc)
230250
lib.linkLibC()
@@ -243,6 +263,7 @@ pub const Config = struct {
243263

244264
// No header-only libraries
245265
const boostLibrariesModules = struct {
266+
atomic: bool = false,
246267
charconv: bool = false,
247268
cobalt: bool = false,
248269
container: bool = false,
@@ -255,8 +276,12 @@ const boostLibrariesModules = struct {
255276
log: bool = false,
256277
process: bool = false,
257278
random: bool = false,
279+
regex: bool = false,
280+
stacktrace: bool = false,
258281
serialization: bool = false,
259282
system: bool = false,
283+
url: bool = false,
284+
wave: bool = false,
260285
};
261286

262287
fn buildCobalt(b: *std.Build, obj: *std.Build.Step.Compile) void {
@@ -373,6 +398,58 @@ fn buildSystem(b: *std.Build, obj: *std.Build.Step.Compile) void {
373398
});
374399
}
375400

401+
fn buildAtomic(b: *std.Build, obj: *std.Build.Step.Compile) void {
402+
const atomicPath = b.dependency("atomic", .{}).path("src");
403+
404+
obj.addIncludePath(atomicPath);
405+
obj.addCSourceFiles(.{
406+
.root = atomicPath,
407+
.files = &.{
408+
"lock_pool.cpp",
409+
},
410+
.flags = cxxFlags,
411+
});
412+
if (obj.rootModuleTarget().os.tag == .windows)
413+
obj.addCSourceFiles(.{
414+
.root = atomicPath,
415+
.files = &.{
416+
"wait_on_address.cpp",
417+
},
418+
.flags = cxxFlags,
419+
});
420+
if (std.Target.x86.featureSetHas(obj.rootModuleTarget().cpu.features, .sse2)) {
421+
obj.addCSourceFiles(.{
422+
.root = atomicPath,
423+
.files = &.{
424+
"find_address_sse2.cpp",
425+
},
426+
.flags = cxxFlags,
427+
});
428+
}
429+
if (std.Target.x86.featureSetHas(obj.rootModuleTarget().cpu.features, .sse4_1)) {
430+
obj.addCSourceFiles(.{
431+
.root = atomicPath,
432+
.files = &.{
433+
"find_address_sse41.cpp",
434+
},
435+
.flags = cxxFlags,
436+
});
437+
}
438+
}
439+
440+
fn buildRegex(b: *std.Build, obj: *std.Build.Step.Compile) void {
441+
const regPath = b.dependency("regex", .{}).path("src");
442+
443+
obj.addCSourceFiles(.{
444+
.root = regPath,
445+
.files = &.{
446+
"posix_api.cpp",
447+
"wide_posix_api.cpp",
448+
},
449+
.flags = cxxFlags,
450+
});
451+
}
452+
376453
fn buildFileSystem(b: *std.Build, obj: *std.Build.Step.Compile) void {
377454
const fsPath = b.dependency("filesystem", .{}).path("src");
378455

@@ -664,6 +741,125 @@ fn buildException(b: *std.Build, obj: *std.Build.Step.Compile) void {
664741
});
665742
}
666743

744+
fn buildStacktrace(b: *std.Build, obj: *std.Build.Step.Compile) void {
745+
const stackPath = b.dependency("stacktrace", .{}).path("src");
746+
747+
obj.addIncludePath(stackPath);
748+
obj.addCSourceFiles(.{
749+
.root = stackPath,
750+
.files = &.{
751+
"addr2line.cpp",
752+
"basic.cpp",
753+
"from_exception.cpp",
754+
"noop.cpp",
755+
},
756+
.flags = cxxFlags,
757+
});
758+
// TODO: fix https://github.com/ziglang/zig/issues/21308
759+
// if (obj.dependsOnSystemLibrary("backtrace")) {
760+
// obj.addCSourceFiles(.{
761+
// .root = stackPath,
762+
// .files = &.{
763+
// "backtrace.cpp",
764+
// },
765+
// .flags = cxxFlags,
766+
// });
767+
// obj.linkSystemLibrary("backtrace");
768+
// }
769+
770+
if (obj.rootModuleTarget().abi == .msvc) {
771+
obj.addCSourceFiles(.{
772+
.root = stackPath,
773+
.files = &.{
774+
"windbg.cpp",
775+
"windbg_cached.cpp",
776+
},
777+
.flags = cxxFlags,
778+
});
779+
780+
obj.linkSystemLibrary("dbgeng");
781+
obj.linkSystemLibrary("ole32");
782+
}
783+
}
784+
785+
fn buildURL(b: *std.Build, obj: *std.Build.Step.Compile) void {
786+
const urlPath = b.dependency("url", .{}).path("src");
787+
788+
obj.addCSourceFiles(.{
789+
.root = urlPath,
790+
.files = &.{
791+
"authority_view.cpp",
792+
"decode_view.cpp",
793+
"detail/any_params_iter.cpp",
794+
"detail/any_segments_iter.cpp",
795+
"detail/decode.cpp",
796+
"detail/except.cpp",
797+
"detail/format_args.cpp",
798+
"detail/normalize.cpp",
799+
"detail/params_iter_impl.cpp",
800+
"detail/pattern.cpp",
801+
"detail/pct_format.cpp",
802+
"detail/replacement_field_rule.cpp",
803+
"detail/segments_iter_impl.cpp",
804+
"detail/url_impl.cpp",
805+
"detail/vformat.cpp",
806+
"encoding_opts.cpp",
807+
"error.cpp",
808+
"grammar/ci_string.cpp",
809+
"grammar/dec_octet_rule.cpp",
810+
"grammar/delim_rule.cpp",
811+
"grammar/detail/recycled.cpp",
812+
"grammar/error.cpp",
813+
"grammar/literal_rule.cpp",
814+
"grammar/string_view_base.cpp",
815+
"ipv4_address.cpp",
816+
"ipv6_address.cpp",
817+
"params_base.cpp",
818+
"params_encoded_base.cpp",
819+
"params_encoded_ref.cpp",
820+
"params_encoded_view.cpp",
821+
"params_ref.cpp",
822+
"params_view.cpp",
823+
"parse.cpp",
824+
"parse_path.cpp",
825+
"parse_query.cpp",
826+
"pct_string_view.cpp",
827+
"rfc/absolute_uri_rule.cpp",
828+
"rfc/authority_rule.cpp",
829+
"rfc/detail/h16_rule.cpp",
830+
"rfc/detail/hier_part_rule.cpp",
831+
"rfc/detail/host_rule.cpp",
832+
"rfc/detail/ip_literal_rule.cpp",
833+
"rfc/detail/ipv6_addrz_rule.cpp",
834+
"rfc/detail/ipvfuture_rule.cpp",
835+
"rfc/detail/port_rule.cpp",
836+
"rfc/detail/relative_part_rule.cpp",
837+
"rfc/detail/scheme_rule.cpp",
838+
"rfc/detail/userinfo_rule.cpp",
839+
"rfc/ipv4_address_rule.cpp",
840+
"rfc/ipv6_address_rule.cpp",
841+
"rfc/origin_form_rule.cpp",
842+
"rfc/query_rule.cpp",
843+
"rfc/relative_ref_rule.cpp",
844+
"rfc/uri_reference_rule.cpp",
845+
"rfc/uri_rule.cpp",
846+
"scheme.cpp",
847+
"segments_base.cpp",
848+
"segments_encoded_base.cpp",
849+
"segments_encoded_ref.cpp",
850+
"segments_encoded_view.cpp",
851+
"segments_ref.cpp",
852+
"segments_view.cpp",
853+
"static_url.cpp",
854+
"url.cpp",
855+
"url_base.cpp",
856+
"url_view.cpp",
857+
"url_view_base.cpp",
858+
},
859+
.flags = cxxFlags,
860+
});
861+
}
862+
667863
fn buildIOStreams(b: *std.Build, obj: *std.Build.Step.Compile) void {
668864
const iostreamPath = b.dependency("iostreams", .{}).path("src");
669865

@@ -756,3 +952,26 @@ fn buildLog(b: *std.Build, obj: *std.Build.Step.Compile) void {
756952
.flags = cxxFlags,
757953
});
758954
}
955+
956+
fn buildWave(b: *std.Build, obj: *std.Build.Step.Compile) void {
957+
const wavePath = b.dependency("wave", .{}).path("src");
958+
959+
obj.addCSourceFiles(.{
960+
.root = wavePath,
961+
.files = &.{
962+
"cpplexer/re2clex/aq.cpp",
963+
"cpplexer/re2clex/cpp_re.cpp",
964+
"instantiate_cpp_exprgrammar.cpp",
965+
"instantiate_cpp_grammar.cpp",
966+
"instantiate_cpp_literalgrs.cpp",
967+
"instantiate_defined_grammar.cpp",
968+
"instantiate_has_include_grammar.cpp",
969+
"instantiate_predef_macros.cpp",
970+
"instantiate_re2c_lexer.cpp",
971+
"instantiate_re2c_lexer_str.cpp",
972+
"token_ids.cpp",
973+
"wave_config_constant.cpp",
974+
},
975+
.flags = cxxFlags,
976+
});
977+
}

build.zig.zon

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,14 @@
454454
.url = "git+https://github.com/boostorg/random#boost-1.86.0",
455455
.hash = "12207b79d0d1acba812181283a2bab056e863ae7bbebb2b6c003836536be8e00921c",
456456
},
457+
.dll = .{
458+
.url = "git+https://github.com/boostorg/dll#boost-1.86.0",
459+
.hash = "1220e46cc6db3ea533d2b74e70c13e41b328b7466c4e088779ff554459ddf98a7cf9",
460+
},
461+
.multiprecision = .{
462+
.url = "git+https://github.com/boostorg/multiprecision#boost-1.86.0",
463+
.hash = "12200ebfce9b83b9617018a985bbcec75999ea628f438bd7ad9912af5ba795e5411a",
464+
},
457465
},
458466
.paths = .{""},
459467
}

update_zon.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ GIT_URLS=(
117117
"git+https://github.com/boostorg/exception#$BOOST_VERSION"
118118
"git+https://github.com/boostorg/multi_index#$BOOST_VERSION"
119119
"git+https://github.com/boostorg/random#$BOOST_VERSION"
120+
"git+https://github.com/boostorg/dll#$BOOST_VERSION"
121+
"git+https://github.com/boostorg/multiprecision#$BOOST_VERSION"
120122

121123
## Add more URLs here
122124
)

0 commit comments

Comments
 (0)