Skip to content

Commit

Permalink
add more libraries: boost.gil & boost.python (no-numpy support yet)
Browse files Browse the repository at this point in the history
Build boost.nowide
  • Loading branch information
kassane committed Sep 12, 2024
1 parent 575f9bc commit b5c0e2b
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ Project-Specific Options:
-Diostreams=[bool] Build boost.iostreams library (default: false)
-Djson=[bool] Build boost.json library (default: false)
-Dlog=[bool] Build boost.log library (default: false)
-Dnowide=[bool] Build boost.nowide library (default: false)
-Dprocess=[bool] Build boost.process library (default: false)
-Dpython=[bool] Build boost.python library (default: false)
-Drandom=[bool] Build boost.random library (default: false)
-Dregex=[bool] Build boost.regex library (default: false)
-Dserialization=[bool] Build boost.serialization library (default: false)
Expand Down
85 changes: 85 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,13 @@ const boost_libs = [_][]const u8{
"local_function",
"format",
"pool",
"gil",
"python",
"proto",
"property_tree",
"exception",
"property_map",
"property_map_parallel",
"multi_index",
"callable_traits",
"compat",
Expand Down Expand Up @@ -135,7 +139,9 @@ pub fn build(b: *std.Build) void {
.iostreams = b.option(bool, "iostreams", "Build boost.iostreams library (default: false)") orelse false,
.json = b.option(bool, "json", "Build boost.json library (default: false)") orelse false,
.log = b.option(bool, "log", "Build boost.log library (default: false)") orelse false,
.nowide = b.option(bool, "nowide", "Build boost.nowide library (default: false)") orelse false,
.process = b.option(bool, "process", "Build boost.process library (default: false)") orelse false,
.python = b.option(bool, "python", "Build boost.python library (default: false)") orelse false,
.random = b.option(bool, "random", "Build boost.random library (default: false)") orelse false,
.regex = b.option(bool, "regex", "Build boost.regex library (default: false)") orelse false,
.serialization = b.option(bool, "serialization", "Build boost.serialization library (default: false)") orelse false,
Expand Down Expand Up @@ -230,9 +236,15 @@ pub fn boostLibraries(b: *std.Build, config: Config) *std.Build.Step.Compile {
if (module.serialization) {
buildSerialization(b, lib);
}
if (module.nowide) {
buildNoWide(b, lib);
}
if (module.system) {
buildSystem(b, lib);
}
if (module.python) {
buildPython(b, lib);
}
if (module.stacktrace) {
buildStacktrace(b, lib);
}
Expand Down Expand Up @@ -274,7 +286,9 @@ const boostLibrariesModules = struct {
iostreams: bool = false,
json: bool = false,
log: bool = false,
nowide: bool = false,
process: bool = false,
python: bool = false,
random: bool = false,
regex: bool = false,
stacktrace: bool = false,
Expand Down Expand Up @@ -953,6 +967,77 @@ fn buildLog(b: *std.Build, obj: *std.Build.Step.Compile) void {
});
}

fn buildNoWide(b: *std.Build, obj: *std.Build.Step.Compile) void {
const nwPath = b.dependency("nowide", .{}).path("src");

obj.addIncludePath(nwPath);
obj.addCSourceFiles(.{
.root = nwPath,
.files = &.{
"console_buffer.cpp",
"cstdio.cpp",
"cstdlib.cpp",
"filebuf.cpp",
"iostream.cpp",
"stat.cpp",
},
.flags = cxxFlags,
});
}

fn buildPython(b: *std.Build, obj: *std.Build.Step.Compile) void {
const pyPath = b.dependency("python", .{}).path("src");

obj.linkSystemLibrary("python3");
obj.addCSourceFiles(.{
.root = pyPath,
.files = &.{
"converter/arg_to_python_base.cpp",
"converter/builtin_converters.cpp",
"converter/from_python.cpp",
"converter/registry.cpp",
"converter/type_id.cpp",
"dict.cpp",
"errors.cpp",
"exec.cpp",
"import.cpp",
"list.cpp",
"long.cpp",
"module.cpp",
"object/class.cpp",
"object/enum.cpp",
"object/function.cpp",
"object/function_doc_signature.cpp",
"object/inheritance.cpp",
"object/iterator.cpp",
"object/life_support.cpp",
"object/pickle_support.cpp",
"object/stl_iterator.cpp",
"object_operators.cpp",
"object_protocol.cpp",
"slice.cpp",
"str.cpp",
"tuple.cpp",
"wrapper.cpp",
},
.flags = cxxFlags,
});

// obj.linkSystemLibrary("npymath");
// obj.addCSourceFiles(.{
// .root = pyPath,
// .files = &.{
// "numpy/dtype.cpp",
// "numpy/matrix.cpp",
// "numpy/ndarray.cpp",
// "numpy/numpy.cpp",
// "numpy/scalars.cpp",
// "numpy/ufunc.cpp",
// },
// .flags = cxxFlags,
// });
}

fn buildWave(b: *std.Build, obj: *std.Build.Step.Compile) void {
const wavePath = b.dependency("wave", .{}).path("src");

Expand Down
16 changes: 16 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,22 @@
.url = "git+https://github.com/boostorg/multiprecision#boost-1.86.0",
.hash = "12200ebfce9b83b9617018a985bbcec75999ea628f438bd7ad9912af5ba795e5411a",
},
.gil = .{
.url = "git+https://github.com/boostorg/gil#boost-1.86.0",
.hash = "122041474a0277c624c8cf7608d44746cb08c027a0af6687fca27463a2373c62999d",
},
.python = .{
.url = "git+https://github.com/boostorg/python#boost-1.86.0",
.hash = "122065876f46e3dfb99e6177bce74a36932dd6e2bec9d645611b94039544cc58998f",
},
.property_map = .{
.url = "git+https://github.com/boostorg/property_map#boost-1.86.0",
.hash = "1220a0c9bc02ed543a0a19abec48a327ed926e5009fdf83b77e1d86acd021eef57fc",
},
.property_map_parallel = .{
.url = "git+https://github.com/boostorg/property_map_parallel#boost-1.86.0",
.hash = "122001fc1ec7bbcbf86fa2cbcbf6f5ee3f2de247057d9ce7c2fe7527b3070345c7ec",
},
},
.paths = .{""},
}
11 changes: 7 additions & 4 deletions tests/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ fn buildTests(b: *std.Build, options: struct {
exe.root_module.include_dirs.append(b.allocator, include_dir) catch unreachable;
}
// if not header-only, link library
exe.linkLibrary(artifact);
if (std.mem.endsWith(u8, exe.name, "server"))
exe.linkLibrary(artifact);
}

for (options.files) |file| {
Expand All @@ -65,9 +66,11 @@ fn buildTests(b: *std.Build, options: struct {
}

// for boost::asio/boost::beast/boost::cobalt
if (exe.rootModuleTarget().os.tag == .windows) {
exe.linkSystemLibrary("ws2_32");
exe.linkSystemLibrary("mswsock");
if (std.mem.endsWith(u8, exe.name, "server")) {
if (exe.rootModuleTarget().os.tag == .windows) {
exe.linkSystemLibrary("ws2_32");
exe.linkSystemLibrary("mswsock");
}
}

b.installArtifact(exe);
Expand Down
3 changes: 0 additions & 3 deletions tests/include_all.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <boost/algorithm/algorithm.hpp>
#include <boost/any.hpp>
#include <boost/array.hpp>
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/callable_traits.hpp>
#include <boost/config.hpp>
Expand Down Expand Up @@ -47,8 +46,6 @@ int main() {
std::cout << "Boost version " << BOOST_VERSION / 100000 << "."
<< BOOST_VERSION / 100 % 1000 << "." << BOOST_VERSION % 100 << "\n";

asio::io_context io_service;

testCRC();
testSafeIntegers();
testVariants();
Expand Down
4 changes: 4 additions & 0 deletions update_zon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ GIT_URLS=(
"git+https://github.com/boostorg/random#$BOOST_VERSION"
"git+https://github.com/boostorg/dll#$BOOST_VERSION"
"git+https://github.com/boostorg/multiprecision#$BOOST_VERSION"
"git+https://github.com/boostorg/gil#$BOOST_VERSION"
"git+https://github.com/boostorg/python#$BOOST_VERSION"
"git+https://github.com/boostorg/property_map#$BOOST_VERSION"
"git+https://github.com/boostorg/property_map_parallel#$BOOST_VERSION"

## Add more URLs here
)
Expand Down

0 comments on commit b5c0e2b

Please sign in to comment.