|
| 1 | +const std = @import("std"); |
| 2 | + |
| 3 | +pub fn build(b: *std.Build) !void { |
| 4 | + const target = b.standardTargetOptions(.{}); |
| 5 | + const optimize = b.standardOptimizeOption(.{}); |
| 6 | + |
| 7 | + const upstream = b.dependency("abseil-cpp", .{}); |
| 8 | + |
| 9 | + const abseil_mod = b.createModule(.{ |
| 10 | + .target = target, |
| 11 | + .optimize = optimize, |
| 12 | + .link_libc = true, |
| 13 | + .link_libcpp = true, |
| 14 | + }); |
| 15 | + |
| 16 | + if (target.result.os.tag == .windows) { |
| 17 | + abseil_mod.linkSystemLibrary("dbghelp", .{}); |
| 18 | + } else if (target.result.os.tag == .macos) { |
| 19 | + abseil_mod.linkFramework("CoreFoundation", .{}); |
| 20 | + } |
| 21 | + |
| 22 | + abseil_mod.addIncludePath(upstream.path("")); |
| 23 | + abseil_mod.addCSourceFiles(.{ |
| 24 | + .root = upstream.path("absl"), |
| 25 | + .files = asbeil_sources, |
| 26 | + .language = .cpp, |
| 27 | + }); |
| 28 | + |
| 29 | + if (target.result.os.tag == .windows) { |
| 30 | + abseil_mod.addCSourceFiles(.{ |
| 31 | + .root = upstream.path("absl"), |
| 32 | + .files = asbeil_sources_win32, |
| 33 | + .language = .cpp, |
| 34 | + }); |
| 35 | + } |
| 36 | + |
| 37 | + const abseil = b.addLibrary(.{ |
| 38 | + .name = "abseil", |
| 39 | + .root_module = abseil_mod, |
| 40 | + .linkage = .static, |
| 41 | + }); |
| 42 | + |
| 43 | + abseil.installHeadersDirectory( |
| 44 | + upstream.path("absl"), |
| 45 | + "absl", |
| 46 | + .{ .include_extensions = &.{ ".h", ".inc" } }, |
| 47 | + ); |
| 48 | + |
| 49 | + b.installArtifact(abseil); |
| 50 | + |
| 51 | + const test_step = b.step("test", "Run library tests"); |
| 52 | + |
| 53 | + try test_abseil(b, .{ |
| 54 | + .target = target, |
| 55 | + .optimize = optimize, |
| 56 | + |
| 57 | + .upstream = upstream, |
| 58 | + .abseil = abseil, |
| 59 | + |
| 60 | + .test_step = test_step, |
| 61 | + }); |
| 62 | +} |
| 63 | + |
| 64 | +fn test_abseil(b: *std.Build, options: anytype) !void { |
| 65 | + const abseil = options.abseil; |
| 66 | + |
| 67 | + for (asbeil_tests) |test_path| { |
| 68 | + const test_mod = b.createModule(.{ |
| 69 | + .target = options.target, |
| 70 | + .optimize = options.optimize, |
| 71 | + .link_libc = true, |
| 72 | + .link_libcpp = true, |
| 73 | + }); |
| 74 | + |
| 75 | + test_mod.linkLibrary(abseil); |
| 76 | + |
| 77 | + test_mod.addCSourceFiles(.{ |
| 78 | + .root = options.upstream.path("absl"), |
| 79 | + .files = &.{ |
| 80 | + test_path, |
| 81 | + }, |
| 82 | + .language = if (std.mem.endsWith(u8, test_path, ".cc")) |
| 83 | + .cpp |
| 84 | + else |
| 85 | + .c, |
| 86 | + }); |
| 87 | + |
| 88 | + const test_name = try std.mem.replaceOwned(u8, b.allocator, std.fs.path.stem(test_path), ".", "_"); |
| 89 | + defer b.allocator.free(test_name); |
| 90 | + |
| 91 | + const test_exe = b.addExecutable(.{ |
| 92 | + .name = test_name, |
| 93 | + .root_module = test_mod, |
| 94 | + }); |
| 95 | + |
| 96 | + const run_test = b.addRunArtifact(test_exe); |
| 97 | + options.test_step.dependOn(&run_test.step); |
| 98 | + } |
| 99 | +} |
| 100 | + |
| 101 | +const asbeil_sources: []const []const u8 = &.{ |
| 102 | + "base/log_severity.cc", |
| 103 | + "base/throw_delegate.cc", |
| 104 | + "base/internal/cycleclock.cc", |
| 105 | + "base/internal/spinlock.cc", |
| 106 | + "base/internal/spinlock_wait.cc", |
| 107 | + "base/internal/sysinfo.cc", |
| 108 | + "base/internal/thread_identity.cc", |
| 109 | + "base/internal/unscaledcycleclock.cc", |
| 110 | + "base/internal/raw_logging.cc", |
| 111 | + "base/internal/low_level_alloc.cc", |
| 112 | + "base/internal/strerror.cc", |
| 113 | + |
| 114 | + "strings/cord.cc", |
| 115 | + "strings/cord_analysis.cc", |
| 116 | + "strings/internal/cord_internal.cc", |
| 117 | + "strings/internal/cord_rep_btree.cc", |
| 118 | + "strings/internal/cord_rep_btree_navigator.cc", |
| 119 | + "strings/internal/cord_rep_btree_reader.cc", |
| 120 | + "strings/internal/cord_rep_crc.cc", |
| 121 | + "strings/internal/cord_rep_consume.cc", |
| 122 | + "strings/internal/cordz_functions.cc", |
| 123 | + "strings/internal/cordz_handle.cc", |
| 124 | + "strings/internal/cordz_info.cc", |
| 125 | + "strings/internal/cordz_sample_token.cc", |
| 126 | + "strings/internal/str_format/arg.cc", |
| 127 | + "strings/internal/str_format/bind.cc", |
| 128 | + "strings/internal/str_format/extension.cc", |
| 129 | + "strings/internal/str_format/float_conversion.cc", |
| 130 | + "strings/internal/str_format/output.cc", |
| 131 | + "strings/internal/str_format/parser.cc", |
| 132 | + "strings/internal/charconv_bigint.cc", |
| 133 | + "strings/internal/charconv_parse.cc", |
| 134 | + "strings/internal/damerau_levenshtein_distance.cc", |
| 135 | + "strings/internal/memutil.cc", |
| 136 | + "strings/internal/stringify_sink.cc", |
| 137 | + "strings/internal/utf8.cc", |
| 138 | + "strings/internal/escaping.cc", |
| 139 | + |
| 140 | + "debugging/symbolize.cc", |
| 141 | + "debugging/stacktrace.cc", |
| 142 | + "debugging/leak_check.cc", |
| 143 | + "debugging/internal/examine_stack.cc", |
| 144 | + "debugging/internal/address_is_readable.cc", |
| 145 | + "debugging/internal/demangle.cc", |
| 146 | + "debugging/internal/vdso_support.cc", |
| 147 | + "debugging/internal/elf_mem_image.cc", |
| 148 | + "debugging/internal/demangle_rust.cc", |
| 149 | + "debugging/internal/decode_rust_punycode.cc", |
| 150 | + "debugging/internal/utf8_for_code_point.cc", |
| 151 | + |
| 152 | + "hash/internal/hash.cc", |
| 153 | + "hash/internal/city.cc", |
| 154 | + |
| 155 | + "log/die_if_null.cc", |
| 156 | + "log/initialize.cc", |
| 157 | + "log/log_sink.cc", |
| 158 | + "log/globals.cc", |
| 159 | + "log/internal/log_message.cc", |
| 160 | + "log/internal/structured_proto.cc", |
| 161 | + "log/internal/check_op.cc", |
| 162 | + "log/internal/log_sink_set.cc", |
| 163 | + "log/internal/proto.cc", |
| 164 | + "log/internal/globals.cc", |
| 165 | + "log/internal/log_format.cc", |
| 166 | + "log/internal/nullguard.cc", |
| 167 | + "log/internal/conditions.cc", |
| 168 | + |
| 169 | + "random/discrete_distribution.cc", |
| 170 | + "random/gaussian_distribution.cc", |
| 171 | + |
| 172 | + "status/status.cc", |
| 173 | + "status/status_payload_printer.cc", |
| 174 | + "status/statusor.cc", |
| 175 | + "strings/ascii.cc", |
| 176 | + "strings/charconv.cc", |
| 177 | + "strings/escaping.cc", |
| 178 | + "strings/match.cc", |
| 179 | + "strings/numbers.cc", |
| 180 | + "strings/str_cat.cc", |
| 181 | + "strings/str_replace.cc", |
| 182 | + "strings/str_split.cc", |
| 183 | + "strings/substitute.cc", |
| 184 | + "status/internal/status_internal.cc", |
| 185 | + |
| 186 | + // absl::synchronization |
| 187 | + "synchronization/barrier.cc", |
| 188 | + "synchronization/blocking_counter.cc", |
| 189 | + "synchronization/notification.cc", |
| 190 | + "synchronization/mutex.cc", |
| 191 | + "synchronization/internal/create_thread_identity.cc", |
| 192 | + "synchronization/internal/futex_waiter.cc", |
| 193 | + "synchronization/internal/per_thread_sem.cc", |
| 194 | + "synchronization/internal/pthread_waiter.cc", |
| 195 | + "synchronization/internal/sem_waiter.cc", |
| 196 | + "synchronization/internal/stdcpp_waiter.cc", |
| 197 | + "synchronization/internal/waiter_base.cc", |
| 198 | + "synchronization/internal/win32_waiter.cc", |
| 199 | + "synchronization/internal/graphcycles.cc", |
| 200 | + "synchronization/internal/kernel_timeout.cc", |
| 201 | + |
| 202 | + "time/civil_time.cc", |
| 203 | + "time/clock.cc", |
| 204 | + "time/duration.cc", |
| 205 | + "time/format.cc", |
| 206 | + "time/time.cc", |
| 207 | + //"time/internal/get_current_time_chrono.inc", |
| 208 | + "time/internal/get_current_time_posix.inc", |
| 209 | + "time/internal/cctz/src/civil_time_detail.cc", |
| 210 | + "time/internal/cctz/src/time_zone_fixed.cc", |
| 211 | + "time/internal/cctz/src/time_zone_format.cc", |
| 212 | + "time/internal/cctz/src/time_zone_if.cc", |
| 213 | + "time/internal/cctz/src/time_zone_impl.cc", |
| 214 | + "time/internal/cctz/src/time_zone_info.cc", |
| 215 | + "time/internal/cctz/src/time_zone_libc.cc", |
| 216 | + "time/internal/cctz/src/time_zone_lookup.cc", |
| 217 | + "time/internal/cctz/src/time_zone_posix.cc", |
| 218 | + "time/internal/cctz/src/zone_info_source.cc", |
| 219 | + |
| 220 | + "container/internal/raw_hash_set.cc", |
| 221 | + "container/internal/hashtablez_sampler.cc", |
| 222 | + "container/internal/hashtablez_sampler_force_weak_definition.cc", |
| 223 | + |
| 224 | + "crc/crc32c.cc", |
| 225 | + "crc/internal/crc.cc", |
| 226 | + "crc/internal/cpu_detect.cc", |
| 227 | + "crc/internal/crc_cord_state.cc", |
| 228 | + "crc/internal/crc_x86_arm_combined.cc", |
| 229 | + "crc/internal/crc_memcpy_fallback.cc", |
| 230 | + "crc/internal/crc_memcpy_x86_arm_combined.cc", |
| 231 | + "crc/internal/crc_non_temporal_memcpy.cc", |
| 232 | + |
| 233 | + "profiling/internal/exponential_biased.cc", |
| 234 | + |
| 235 | + "numeric/int128.cc", |
| 236 | +}; |
| 237 | + |
| 238 | +const asbeil_sources_win32: []const []const u8 = &.{ |
| 239 | + "time/internal/cctz/src/time_zone_name_win.cc", |
| 240 | +}; |
| 241 | + |
| 242 | +const asbeil_tests: []const []const u8 = &.{ |
| 243 | + "base/c_header_test.c", |
| 244 | +}; |
0 commit comments