| ... | @@ -24,36 +24,24 @@ const Compile = @This(); | ... | @@ -24,36 +24,24 @@ const Compile = @This(); |
| 24 | pub const base_id: Step.Id = .compile; | 24 | pub const base_id: Step.Id = .compile; |
| 25 | | 25 | |
| 26 | step: Step, | 26 | step: Step, |
| | 27 | root_module: Module, |
| | 28 | |
| 27 | name: []const u8, | 29 | name: []const u8, |
| 28 | target: CrossTarget, | | |
| 29 | target_info: NativeTargetInfo, | | |
| 30 | optimize: std.builtin.OptimizeMode, | | |
| 31 | linker_script: ?LazyPath = null, | 30 | linker_script: ?LazyPath = null, |
| 32 | version_script: ?[]const u8 = null, | 31 | version_script: ?[]const u8 = null, |
| 33 | out_filename: []const u8, | 32 | out_filename: []const u8, |
| | 33 | out_lib_filename: []const u8, |
| 34 | linkage: ?Linkage = null, | 34 | linkage: ?Linkage = null, |
| 35 | version: ?std.SemanticVersion, | 35 | version: ?std.SemanticVersion, |
| 36 | kind: Kind, | 36 | kind: Kind, |
| 37 | major_only_filename: ?[]const u8, | 37 | major_only_filename: ?[]const u8, |
| 38 | name_only_filename: ?[]const u8, | 38 | name_only_filename: ?[]const u8, |
| 39 | strip: ?bool, | | |
| 40 | formatted_panics: ?bool = null, | | |
| 41 | unwind_tables: ?bool, | | |
| 42 | // keep in sync with src/link.zig:CompressDebugSections | 39 | // keep in sync with src/link.zig:CompressDebugSections |
| 43 | compress_debug_sections: enum { none, zlib, zstd } = .none, | 40 | compress_debug_sections: enum { none, zlib, zstd } = .none, |
| 44 | lib_paths: ArrayList(LazyPath), | | |
| 45 | rpaths: ArrayList(LazyPath), | | |
| 46 | frameworks: StringHashMap(FrameworkLinkInfo), | | |
| 47 | verbose_link: bool, | 41 | verbose_link: bool, |
| 48 | verbose_cc: bool, | 42 | verbose_cc: bool, |
| 49 | bundle_compiler_rt: ?bool = null, | 43 | bundle_compiler_rt: ?bool = null, |
| 50 | single_threaded: ?bool, | | |
| 51 | stack_protector: ?bool = null, | | |
| 52 | disable_stack_probing: bool, | | |
| 53 | disable_sanitize_c: bool, | | |
| 54 | sanitize_thread: bool, | | |
| 55 | rdynamic: bool, | 44 | rdynamic: bool, |
| 56 | dwarf_format: ?std.dwarf.Format = null, | | |
| 57 | import_memory: bool = false, | 45 | import_memory: bool = false, |
| 58 | export_memory: bool = false, | 46 | export_memory: bool = false, |
| 59 | /// For WebAssembly targets, this will allow for undefined symbols to | 47 | /// For WebAssembly targets, this will allow for undefined symbols to |
| ... | @@ -65,31 +53,16 @@ initial_memory: ?u64 = null, | ... | @@ -65,31 +53,16 @@ initial_memory: ?u64 = null, |
| 65 | max_memory: ?u64 = null, | 53 | max_memory: ?u64 = null, |
| 66 | shared_memory: bool = false, | 54 | shared_memory: bool = false, |
| 67 | global_base: ?u64 = null, | 55 | global_base: ?u64 = null, |
| 68 | c_std: std.Build.CStd, | | |
| 69 | /// Set via options; intended to be read-only after that. | 56 | /// Set via options; intended to be read-only after that. |
| 70 | zig_lib_dir: ?LazyPath, | 57 | zig_lib_dir: ?LazyPath, |
| 71 | /// Set via options; intended to be read-only after that. | | |
| 72 | main_mod_path: ?LazyPath, | | |
| 73 | exec_cmd_args: ?[]const ?[]const u8, | 58 | exec_cmd_args: ?[]const ?[]const u8, |
| 74 | filter: ?[]const u8, | 59 | filter: ?[]const u8, |
| 75 | test_evented_io: bool = false, | 60 | test_evented_io: bool = false, |
| 76 | test_runner: ?[]const u8, | 61 | test_runner: ?[]const u8, |
| 77 | test_server_mode: bool, | 62 | test_server_mode: bool, |
| 78 | code_model: std.builtin.CodeModel = .default, | | |
| 79 | wasi_exec_model: ?std.builtin.WasiExecModel = null, | 63 | wasi_exec_model: ?std.builtin.WasiExecModel = null, |
| 80 | /// Symbols to be exported when compiling to wasm | | |
| 81 | export_symbol_names: []const []const u8 = &.{}, | | |
| 82 | | | |
| 83 | root_src: ?LazyPath, | | |
| 84 | out_lib_filename: []const u8, | | |
| 85 | modules: std.StringArrayHashMap(*Module), | | |
| 86 | | 64 | |
| 87 | link_objects: ArrayList(LinkObject), | | |
| 88 | include_dirs: ArrayList(IncludeDir), | | |
| 89 | c_macros: ArrayList([]const u8), | | |
| 90 | installed_headers: ArrayList(*Step), | 65 | installed_headers: ArrayList(*Step), |
| 91 | is_linking_libc: bool, | | |
| 92 | is_linking_libcpp: bool, | | |
| 93 | vcpkg_bin_path: ?[]const u8 = null, | 66 | vcpkg_bin_path: ?[]const u8 = null, |
| 94 | | 67 | |
| 95 | // keep in sync with src/Compilation.zig:RcIncludes | 68 | // keep in sync with src/Compilation.zig:RcIncludes |
| ... | @@ -111,7 +84,6 @@ image_base: ?u64 = null, | ... | @@ -111,7 +84,6 @@ image_base: ?u64 = null, |
| 111 | | 84 | |
| 112 | libc_file: ?LazyPath = null, | 85 | libc_file: ?LazyPath = null, |
| 113 | | 86 | |
| 114 | valgrind_support: ?bool = null, | | |
| 115 | each_lib_rpath: ?bool = null, | 87 | each_lib_rpath: ?bool = null, |
| 116 | /// On ELF targets, this will emit a link section called ".note.gnu.build-id" | 88 | /// On ELF targets, this will emit a link section called ".note.gnu.build-id" |
| 117 | /// which can be used to coordinate a stripped binary with its debug symbols. | 89 | /// which can be used to coordinate a stripped binary with its debug symbols. |
| ... | @@ -177,15 +149,9 @@ headerpad_max_install_names: bool = false, | ... | @@ -177,15 +149,9 @@ headerpad_max_install_names: bool = false, |
| 177 | /// (Darwin) Remove dylibs that are unreachable by the entry point or exported symbols. | 149 | /// (Darwin) Remove dylibs that are unreachable by the entry point or exported symbols. |
| 178 | dead_strip_dylibs: bool = false, | 150 | dead_strip_dylibs: bool = false, |
| 179 | | 151 | |
| 180 | /// Position Independent Code | | |
| 181 | force_pic: ?bool = null, | | |
| 182 | | | |
| 183 | /// Position Independent Executable | 152 | /// Position Independent Executable |
| 184 | pie: ?bool = null, | 153 | pie: ?bool = null, |
| 185 | | 154 | |
| 186 | red_zone: ?bool = null, | | |
| 187 | | | |
| 188 | omit_frame_pointer: ?bool = null, | | |
| 189 | dll_export_fns: ?bool = null, | 155 | dll_export_fns: ?bool = null, |
| 190 | | 156 | |
| 191 | subsystem: ?std.Target.SubSystem = null, | 157 | subsystem: ?std.Target.SubSystem = null, |
| ... | @@ -226,90 +192,16 @@ generated_h: ?*GeneratedFile, | ... | @@ -226,90 +192,16 @@ generated_h: ?*GeneratedFile, |
| 226 | /// Defaults to `std.math.maxInt(u16)` | 192 | /// Defaults to `std.math.maxInt(u16)` |
| 227 | error_limit: ?u32 = null, | 193 | error_limit: ?u32 = null, |
| 228 | | 194 | |
| | 195 | /// Computed during make(). |
| | 196 | is_linking_libc: bool = false, |
| | 197 | /// Computed during make(). |
| | 198 | is_linking_libcpp: bool = false, |
| | 199 | |
| 229 | pub const ExpectedCompileErrors = union(enum) { | 200 | pub const ExpectedCompileErrors = union(enum) { |
| 230 | contains: []const u8, | 201 | contains: []const u8, |
| 231 | exact: []const []const u8, | 202 | exact: []const []const u8, |
| 232 | }; | 203 | }; |
| 233 | | 204 | |
| 234 | pub const CSourceFiles = struct { | | |
| 235 | dependency: ?*std.Build.Dependency, | | |
| 236 | /// If `dependency` is not null relative to it, | | |
| 237 | /// else relative to the build root. | | |
| 238 | files: []const []const u8, | | |
| 239 | flags: []const []const u8, | | |
| 240 | }; | | |
| 241 | | | |
| 242 | pub const CSourceFile = struct { | | |
| 243 | file: LazyPath, | | |
| 244 | flags: []const []const u8, | | |
| 245 | | | |
| 246 | pub fn dupe(self: CSourceFile, b: *std.Build) CSourceFile { | | |
| 247 | return .{ | | |
| 248 | .file = self.file.dupe(b), | | |
| 249 | .flags = b.dupeStrings(self.flags), | | |
| 250 | }; | | |
| 251 | } | | |
| 252 | }; | | |
| 253 | | | |
| 254 | pub const RcSourceFile = struct { | | |
| 255 | file: LazyPath, | | |
| 256 | /// Any option that rc.exe accepts will work here, with the exception of: | | |
| 257 | /// - `/fo`: The output filename is set by the build system | | |
| 258 | /// - `/p`: Only running the preprocessor is not supported in this context | | |
| 259 | /// - `/:no-preprocess` (non-standard option): Not supported in this context | | |
| 260 | /// - Any MUI-related option | | |
| 261 | /// https://learn.microsoft.com/en-us/windows/win32/menurc/using-rc-the-rc-command-line- | | |
| 262 | /// | | |
| 263 | /// Implicitly defined options: | | |
| 264 | /// /x (ignore the INCLUDE environment variable) | | |
| 265 | /// /D_DEBUG or /DNDEBUG depending on the optimization mode | | |
| 266 | flags: []const []const u8 = &.{}, | | |
| 267 | | | |
| 268 | pub fn dupe(self: RcSourceFile, b: *std.Build) RcSourceFile { | | |
| 269 | return .{ | | |
| 270 | .file = self.file.dupe(b), | | |
| 271 | .flags = b.dupeStrings(self.flags), | | |
| 272 | }; | | |
| 273 | } | | |
| 274 | }; | | |
| 275 | | | |
| 276 | pub const LinkObject = union(enum) { | | |
| 277 | static_path: LazyPath, | | |
| 278 | other_step: *Compile, | | |
| 279 | system_lib: SystemLib, | | |
| 280 | assembly_file: LazyPath, | | |
| 281 | c_source_file: *CSourceFile, | | |
| 282 | c_source_files: *CSourceFiles, | | |
| 283 | win32_resource_file: *RcSourceFile, | | |
| 284 | }; | | |
| 285 | | | |
| 286 | pub const SystemLib = struct { | | |
| 287 | name: []const u8, | | |
| 288 | needed: bool, | | |
| 289 | weak: bool, | | |
| 290 | use_pkg_config: UsePkgConfig, | | |
| 291 | preferred_link_mode: std.builtin.LinkMode, | | |
| 292 | search_strategy: SystemLib.SearchStrategy, | | |
| 293 | | | |
| 294 | pub const UsePkgConfig = enum { | | |
| 295 | /// Don't use pkg-config, just pass -lfoo where foo is name. | | |
| 296 | no, | | |
| 297 | /// Try to get information on how to link the library from pkg-config. | | |
| 298 | /// If that fails, fall back to passing -lfoo where foo is name. | | |
| 299 | yes, | | |
| 300 | /// Try to get information on how to link the library from pkg-config. | | |
| 301 | /// If that fails, error out. | | |
| 302 | force, | | |
| 303 | }; | | |
| 304 | | | |
| 305 | pub const SearchStrategy = enum { paths_first, mode_first, no_fallback }; | | |
| 306 | }; | | |
| 307 | | | |
| 308 | const FrameworkLinkInfo = struct { | | |
| 309 | needed: bool = false, | | |
| 310 | weak: bool = false, | | |
| 311 | }; | | |
| 312 | | | |
| 313 | const Entry = union(enum) { | 205 | const Entry = union(enum) { |
| 314 | /// Let the compiler decide whether to make an entry point and what to name | 206 | /// Let the compiler decide whether to make an entry point and what to name |
| 315 | /// it. | 207 | /// it. |
| ... | @@ -322,42 +214,24 @@ const Entry = union(enum) { | ... | @@ -322,42 +214,24 @@ const Entry = union(enum) { |
| 322 | symbol_name: []const u8, | 214 | symbol_name: []const u8, |
| 323 | }; | 215 | }; |
| 324 | | 216 | |
| 325 | pub const IncludeDir = union(enum) { | | |
| 326 | path: LazyPath, | | |
| 327 | path_system: LazyPath, | | |
| 328 | path_after: LazyPath, | | |
| 329 | framework_path: LazyPath, | | |
| 330 | framework_path_system: LazyPath, | | |
| 331 | other_step: *Compile, | | |
| 332 | config_header_step: *Step.ConfigHeader, | | |
| 333 | }; | | |
| 334 | | | |
| 335 | pub const Options = struct { | 217 | pub const Options = struct { |
| 336 | name: []const u8, | 218 | name: []const u8, |
| 337 | root_source_file: ?LazyPath = null, | 219 | root_module: Module.CreateOptions, |
| 338 | target: CrossTarget, | | |
| 339 | optimize: std.builtin.OptimizeMode, | | |
| 340 | kind: Kind, | 220 | kind: Kind, |
| 341 | linkage: ?Linkage = null, | 221 | linkage: ?Linkage = null, |
| 342 | version: ?std.SemanticVersion = null, | 222 | version: ?std.SemanticVersion = null, |
| 343 | max_rss: usize = 0, | 223 | max_rss: usize = 0, |
| 344 | filter: ?[]const u8 = null, | 224 | filter: ?[]const u8 = null, |
| 345 | test_runner: ?[]const u8 = null, | 225 | test_runner: ?[]const u8 = null, |
| 346 | link_libc: ?bool = null, | | |
| 347 | single_threaded: ?bool = null, | | |
| 348 | use_llvm: ?bool = null, | 226 | use_llvm: ?bool = null, |
| 349 | use_lld: ?bool = null, | 227 | use_lld: ?bool = null, |
| 350 | zig_lib_dir: ?LazyPath = null, | 228 | zig_lib_dir: ?LazyPath = null, |
| 351 | main_mod_path: ?LazyPath = null, | | |
| 352 | /// Embed a `.manifest` file in the compilation if the object format supports it. | 229 | /// Embed a `.manifest` file in the compilation if the object format supports it. |
| 353 | /// https://learn.microsoft.com/en-us/windows/win32/sbscs/manifest-files-reference | 230 | /// https://learn.microsoft.com/en-us/windows/win32/sbscs/manifest-files-reference |
| 354 | /// Manifest files must have the extension `.manifest`. | 231 | /// Manifest files must have the extension `.manifest`. |
| 355 | /// Can be set regardless of target. The `.manifest` file will be ignored | 232 | /// Can be set regardless of target. The `.manifest` file will be ignored |
| 356 | /// if the target object format does not support embedded manifests. | 233 | /// if the target object format does not support embedded manifests. |
| 357 | win32_manifest: ?LazyPath = null, | 234 | win32_manifest: ?LazyPath = null, |
| 358 | | | |
| 359 | /// deprecated; use `main_mod_path`. | | |
| 360 | main_pkg_path: ?LazyPath = null, | | |
| 361 | }; | 235 | }; |
| 362 | | 236 | |
| 363 | pub const BuildId = union(enum) { | 237 | pub const BuildId = union(enum) { |
| ... | @@ -447,7 +321,6 @@ pub const Linkage = enum { dynamic, static }; | ... | @@ -447,7 +321,6 @@ pub const Linkage = enum { dynamic, static }; |
| 447 | | 321 | |
| 448 | pub fn create(owner: *std.Build, options: Options) *Compile { | 322 | pub fn create(owner: *std.Build, options: Options) *Compile { |
| 449 | const name = owner.dupe(options.name); | 323 | const name = owner.dupe(options.name); |
| 450 | const root_src: ?LazyPath = if (options.root_source_file) |rsrc| rsrc.dupe(owner) else null; | | |
| 451 | if (mem.indexOf(u8, name, "/") != null or mem.indexOf(u8, name, "\\") != null) { | 324 | if (mem.indexOf(u8, name, "/") != null or mem.indexOf(u8, name, "\\") != null) { |
| 452 | panic("invalid name: '{s}'. It looks like a file path, but it is supposed to be the library or application name.", .{name}); | 325 | panic("invalid name: '{s}'. It looks like a file path, but it is supposed to be the library or application name.", .{name}); |
| 453 | } | 326 | } |
| ... | @@ -466,11 +339,12 @@ pub fn create(owner: *std.Build, options: Options) *Compile { | ... | @@ -466,11 +339,12 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 466 | .@"test" => "zig test", | 339 | .@"test" => "zig test", |
| 467 | }, | 340 | }, |
| 468 | name_adjusted, | 341 | name_adjusted, |
| 469 | @tagName(options.optimize), | 342 | @tagName(options.root_module.optimize), |
| 470 | options.target.zigTriple(owner.allocator) catch @panic("OOM"), | 343 | options.root_module.target.zigTriple(owner.allocator) catch @panic("OOM"), |
| 471 | }); | 344 | }); |
| 472 | | 345 | |
| 473 | const target_info = NativeTargetInfo.detect(options.target) catch @panic("unhandled error"); | 346 | const target_info = NativeTargetInfo.detect(options.root_module.target) catch |
| | 347 | @panic("unhandled error"); |
| 474 | | 348 | |
| 475 | const out_filename = std.zig.binNameAlloc(owner.allocator, .{ | 349 | const out_filename = std.zig.binNameAlloc(owner.allocator, .{ |
| 476 | .root_name = name, | 350 | .root_name = name, |
| ... | @@ -489,17 +363,12 @@ pub fn create(owner: *std.Build, options: Options) *Compile { | ... | @@ -489,17 +363,12 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 489 | | 363 | |
| 490 | const self = owner.allocator.create(Compile) catch @panic("OOM"); | 364 | const self = owner.allocator.create(Compile) catch @panic("OOM"); |
| 491 | self.* = .{ | 365 | self.* = .{ |
| 492 | .strip = null, | 366 | .root_module = Module.init(owner, options.root_module, self), |
| 493 | .unwind_tables = null, | | |
| 494 | .verbose_link = false, | 367 | .verbose_link = false, |
| 495 | .verbose_cc = false, | 368 | .verbose_cc = false, |
| 496 | .optimize = options.optimize, | | |
| 497 | .target = options.target, | | |
| 498 | .linkage = options.linkage, | 369 | .linkage = options.linkage, |
| 499 | .kind = options.kind, | 370 | .kind = options.kind, |
| 500 | .root_src = root_src, | | |
| 501 | .name = name, | 371 | .name = name, |
| 502 | .frameworks = StringHashMap(FrameworkLinkInfo).init(owner.allocator), | | |
| 503 | .step = Step.init(.{ | 372 | .step = Step.init(.{ |
| 504 | .id = base_id, | 373 | .id = base_id, |
| 505 | .name = step_name, | 374 | .name = step_name, |
| ... | @@ -512,23 +381,12 @@ pub fn create(owner: *std.Build, options: Options) *Compile { | ... | @@ -512,23 +381,12 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 512 | .out_lib_filename = undefined, | 381 | .out_lib_filename = undefined, |
| 513 | .major_only_filename = null, | 382 | .major_only_filename = null, |
| 514 | .name_only_filename = null, | 383 | .name_only_filename = null, |
| 515 | .modules = std.StringArrayHashMap(*Module).init(owner.allocator), | | |
| 516 | .include_dirs = ArrayList(IncludeDir).init(owner.allocator), | | |
| 517 | .link_objects = ArrayList(LinkObject).init(owner.allocator), | | |
| 518 | .c_macros = ArrayList([]const u8).init(owner.allocator), | | |
| 519 | .lib_paths = ArrayList(LazyPath).init(owner.allocator), | | |
| 520 | .rpaths = ArrayList(LazyPath).init(owner.allocator), | | |
| 521 | .installed_headers = ArrayList(*Step).init(owner.allocator), | 384 | .installed_headers = ArrayList(*Step).init(owner.allocator), |
| 522 | .c_std = std.Build.CStd.C99, | | |
| 523 | .zig_lib_dir = null, | 385 | .zig_lib_dir = null, |
| 524 | .main_mod_path = null, | | |
| 525 | .exec_cmd_args = null, | 386 | .exec_cmd_args = null, |
| 526 | .filter = options.filter, | 387 | .filter = options.filter, |
| 527 | .test_runner = options.test_runner, | 388 | .test_runner = options.test_runner, |
| 528 | .test_server_mode = options.test_runner == null, | 389 | .test_server_mode = options.test_runner == null, |
| 529 | .disable_stack_probing = false, | | |
| 530 | .disable_sanitize_c = false, | | |
| 531 | .sanitize_thread = false, | | |
| 532 | .rdynamic = false, | 390 | .rdynamic = false, |
| 533 | .installed_path = null, | 391 | .installed_path = null, |
| 534 | .force_undefined_symbols = StringHashMap(void).init(owner.allocator), | 392 | .force_undefined_symbols = StringHashMap(void).init(owner.allocator), |
| ... | @@ -543,11 +401,6 @@ pub fn create(owner: *std.Build, options: Options) *Compile { | ... | @@ -543,11 +401,6 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 543 | .generated_llvm_ir = null, | 401 | .generated_llvm_ir = null, |
| 544 | .generated_h = null, | 402 | .generated_h = null, |
| 545 | | 403 | |
| 546 | .target_info = target_info, | | |
| 547 | | | |
| 548 | .is_linking_libc = options.link_libc orelse false, | | |
| 549 | .is_linking_libcpp = false, | | |
| 550 | .single_threaded = options.single_threaded, | | |
| 551 | .use_llvm = options.use_llvm, | 404 | .use_llvm = options.use_llvm, |
| 552 | .use_lld = options.use_lld, | 405 | .use_lld = options.use_lld, |
| 553 | }; | 406 | }; |
| ... | @@ -557,14 +410,9 @@ pub fn create(owner: *std.Build, options: Options) *Compile { | ... | @@ -557,14 +410,9 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 557 | lp.addStepDependencies(&self.step); | 410 | lp.addStepDependencies(&self.step); |
| 558 | } | 411 | } |
| 559 | | 412 | |
| 560 | if (options.main_mod_path orelse options.main_pkg_path) |lp| { | | |
| 561 | self.main_mod_path = lp.dupe(self.step.owner); | | |
| 562 | lp.addStepDependencies(&self.step); | | |
| 563 | } | | |
| 564 | | | |
| 565 | // Only the PE/COFF format has a Resource Table which is where the manifest | 413 | // Only the PE/COFF format has a Resource Table which is where the manifest |
| 566 | // gets embedded, so for any other target the manifest file is just ignored. | 414 | // gets embedded, so for any other target the manifest file is just ignored. |
| 567 | if (self.target.getObjectFormat() == .coff) { | 415 | if (target_info.target.ofmt == .coff) { |
| 568 | if (options.win32_manifest) |lp| { | 416 | if (options.win32_manifest) |lp| { |
| 569 | self.win32_manifest = lp.dupe(self.step.owner); | 417 | self.win32_manifest = lp.dupe(self.step.owner); |
| 570 | lp.addStepDependencies(&self.step); | 418 | lp.addStepDependencies(&self.step); |
| ... | @@ -600,8 +448,6 @@ pub fn create(owner: *std.Build, options: Options) *Compile { | ... | @@ -600,8 +448,6 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 600 | } | 448 | } |
| 601 | } | 449 | } |
| 602 | | 450 | |
| 603 | if (root_src) |rs| rs.addStepDependencies(&self.step); | | |
| 604 | | | |
| 605 | return self; | 451 | return self; |
| 606 | } | 452 | } |
| 607 | | 453 | |
| ... | @@ -738,19 +584,30 @@ pub fn linkFrameworkWeak(self: *Compile, framework_name: []const u8) void { | ... | @@ -738,19 +584,30 @@ pub fn linkFrameworkWeak(self: *Compile, framework_name: []const u8) void { |
| 738 | } | 584 | } |
| 739 | | 585 | |
| 740 | /// Returns whether the library, executable, or object depends on a particular system library. | 586 | /// Returns whether the library, executable, or object depends on a particular system library. |
| 741 | pub fn dependsOnSystemLibrary(self: Compile, name: []const u8) bool { | 587 | pub fn dependsOnSystemLibrary(self: *const Compile, name: []const u8) bool { |
| 742 | if (isLibCLibrary(name)) { | 588 | var is_linking_libc = false; |
| 743 | return self.is_linking_libc; | 589 | var is_linking_libcpp = false; |
| | 590 | |
| | 591 | var it = self.root_module.iterateDependencies(self); |
| | 592 | while (it.next()) |module| { |
| | 593 | for (module.link_objects.items) |link_object| { |
| | 594 | switch (link_object) { |
| | 595 | .system_lib => |lib| if (mem.eql(u8, lib.name, name)) return true, |
| | 596 | else => continue, |
| | 597 | } |
| | 598 | } |
| | 599 | is_linking_libc = is_linking_libc or module.link_libcpp == true; |
| | 600 | is_linking_libcpp = is_linking_libcpp or module.link_libcpp == true; |
| 744 | } | 601 | } |
| 745 | if (isLibCppLibrary(name)) { | 602 | |
| 746 | return self.is_linking_libcpp; | 603 | if (self.root_module.target_info.target.is_libc_lib_name(name)) { |
| | 604 | return is_linking_libc; |
| 747 | } | 605 | } |
| 748 | for (self.link_objects.items) |link_object| { | 606 | |
| 749 | switch (link_object) { | 607 | if (self.root_module.target_info.target.is_libcpp_lib_name(name)) { |
| 750 | .system_lib => |lib| if (mem.eql(u8, lib.name, name)) return true, | 608 | return is_linking_libcpp; |
| 751 | else => continue, | | |
| 752 | } | | |
| 753 | } | 609 | } |
| | 610 | |
| 754 | return false; | 611 | return false; |
| 755 | } | 612 | } |
| 756 | | 613 | |
| ... | @@ -759,11 +616,11 @@ pub fn linkLibrary(self: *Compile, lib: *Compile) void { | ... | @@ -759,11 +616,11 @@ pub fn linkLibrary(self: *Compile, lib: *Compile) void { |
| 759 | self.linkLibraryOrObject(lib); | 616 | self.linkLibraryOrObject(lib); |
| 760 | } | 617 | } |
| 761 | | 618 | |
| 762 | pub fn isDynamicLibrary(self: *Compile) bool { | 619 | pub fn isDynamicLibrary(self: *const Compile) bool { |
| 763 | return self.kind == .lib and self.linkage == Linkage.dynamic; | 620 | return self.kind == .lib and self.linkage == Linkage.dynamic; |
| 764 | } | 621 | } |
| 765 | | 622 | |
| 766 | pub fn isStaticLibrary(self: *Compile) bool { | 623 | pub fn isStaticLibrary(self: *const Compile) bool { |
| 767 | return self.kind == .lib and self.linkage != Linkage.dynamic; | 624 | return self.kind == .lib and self.linkage != Linkage.dynamic; |
| 768 | } | 625 | } |
| 769 | | 626 | |
| ... | @@ -777,15 +634,15 @@ pub fn producesPdbFile(self: *Compile) bool { | ... | @@ -777,15 +634,15 @@ pub fn producesPdbFile(self: *Compile) bool { |
| 777 | } | 634 | } |
| 778 | | 635 | |
| 779 | pub fn producesImplib(self: *Compile) bool { | 636 | pub fn producesImplib(self: *Compile) bool { |
| 780 | return self.isDynamicLibrary() and self.target.isWindows(); | 637 | return self.isDynamicLibrary() and self.root_module.target_info.target.os.tag == .windows; |
| 781 | } | 638 | } |
| 782 | | 639 | |
| 783 | pub fn linkLibC(self: *Compile) void { | 640 | pub fn linkLibC(self: *Compile) void { |
| 784 | self.is_linking_libc = true; | 641 | self.root_module.link_libc = true; |
| 785 | } | 642 | } |
| 786 | | 643 | |
| 787 | pub fn linkLibCpp(self: *Compile) void { | 644 | pub fn linkLibCpp(self: *Compile) void { |
| 788 | self.is_linking_libcpp = true; | 645 | self.root_module.link_libcpp = true; |
| 789 | } | 646 | } |
| 790 | | 647 | |
| 791 | /// If the value is omitted, it is set to 1. | 648 | /// If the value is omitted, it is set to 1. |
| ... | @@ -802,31 +659,6 @@ pub fn defineCMacroRaw(self: *Compile, name_and_value: []const u8) void { | ... | @@ -802,31 +659,6 @@ pub fn defineCMacroRaw(self: *Compile, name_and_value: []const u8) void { |
| 802 | self.c_macros.append(b.dupe(name_and_value)) catch @panic("OOM"); | 659 | self.c_macros.append(b.dupe(name_and_value)) catch @panic("OOM"); |
| 803 | } | 660 | } |
| 804 | | 661 | |
| 805 | /// deprecated: use linkSystemLibrary2 | | |
| 806 | pub fn linkSystemLibraryName(self: *Compile, name: []const u8) void { | | |
| 807 | return linkSystemLibrary2(self, name, .{ .use_pkg_config = .no }); | | |
| 808 | } | | |
| 809 | | | |
| 810 | /// deprecated: use linkSystemLibrary2 | | |
| 811 | pub fn linkSystemLibraryNeededName(self: *Compile, name: []const u8) void { | | |
| 812 | return linkSystemLibrary2(self, name, .{ .needed = true, .use_pkg_config = .no }); | | |
| 813 | } | | |
| 814 | | | |
| 815 | /// deprecated: use linkSystemLibrary2 | | |
| 816 | pub fn linkSystemLibraryWeakName(self: *Compile, name: []const u8) void { | | |
| 817 | return linkSystemLibrary2(self, name, .{ .weak = true, .use_pkg_config = .no }); | | |
| 818 | } | | |
| 819 | | | |
| 820 | /// deprecated: use linkSystemLibrary2 | | |
| 821 | pub fn linkSystemLibraryPkgConfigOnly(self: *Compile, lib_name: []const u8) void { | | |
| 822 | return linkSystemLibrary2(self, lib_name, .{ .use_pkg_config = .force }); | | |
| 823 | } | | |
| 824 | | | |
| 825 | /// deprecated: use linkSystemLibrary2 | | |
| 826 | pub fn linkSystemLibraryNeededPkgConfigOnly(self: *Compile, lib_name: []const u8) void { | | |
| 827 | return linkSystemLibrary2(self, lib_name, .{ .needed = true, .use_pkg_config = .force }); | | |
| 828 | } | | |
| 829 | | | |
| 830 | /// Run pkg-config for the given library name and parse the output, returning the arguments | 662 | /// Run pkg-config for the given library name and parse the output, returning the arguments |
| 831 | /// that should be passed to zig to link the given library. | 663 | /// that should be passed to zig to link the given library. |
| 832 | fn runPkgConfig(self: *Compile, lib_name: []const u8) ![]const []const u8 { | 664 | fn runPkgConfig(self: *Compile, lib_name: []const u8) ![]const []const u8 { |
| ... | @@ -924,98 +756,31 @@ fn runPkgConfig(self: *Compile, lib_name: []const u8) ![]const []const u8 { | ... | @@ -924,98 +756,31 @@ fn runPkgConfig(self: *Compile, lib_name: []const u8) ![]const []const u8 { |
| 924 | } | 756 | } |
| 925 | | 757 | |
| 926 | pub fn linkSystemLibrary(self: *Compile, name: []const u8) void { | 758 | pub fn linkSystemLibrary(self: *Compile, name: []const u8) void { |
| 927 | self.linkSystemLibrary2(name, .{}); | 759 | return self.root_module.linkSystemLibrary(name, .{}); |
| 928 | } | | |
| 929 | | | |
| 930 | /// deprecated: use linkSystemLibrary2 | | |
| 931 | pub fn linkSystemLibraryNeeded(self: *Compile, name: []const u8) void { | | |
| 932 | return linkSystemLibrary2(self, name, .{ .needed = true }); | | |
| 933 | } | 760 | } |
| 934 | | 761 | |
| 935 | /// deprecated: use linkSystemLibrary2 | | |
| 936 | pub fn linkSystemLibraryWeak(self: *Compile, name: []const u8) void { | | |
| 937 | return linkSystemLibrary2(self, name, .{ .weak = true }); | | |
| 938 | } | | |
| 939 | | | |
| 940 | pub const LinkSystemLibraryOptions = struct { | | |
| 941 | needed: bool = false, | | |
| 942 | weak: bool = false, | | |
| 943 | use_pkg_config: SystemLib.UsePkgConfig = .yes, | | |
| 944 | preferred_link_mode: std.builtin.LinkMode = .Dynamic, | | |
| 945 | search_strategy: SystemLib.SearchStrategy = .paths_first, | | |
| 946 | }; | | |
| 947 | | | |
| 948 | pub fn linkSystemLibrary2( | 762 | pub fn linkSystemLibrary2( |
| 949 | self: *Compile, | 763 | self: *Compile, |
| 950 | name: []const u8, | 764 | name: []const u8, |
| 951 | options: LinkSystemLibraryOptions, | 765 | options: Module.LinkSystemLibraryOptions, |
| 952 | ) void { | 766 | ) void { |
| 953 | const b = self.step.owner; | 767 | return self.root_module.linkSystemLibrary(name, options); |
| 954 | if (isLibCLibrary(name)) { | | |
| 955 | self.linkLibC(); | | |
| 956 | return; | | |
| 957 | } | | |
| 958 | if (isLibCppLibrary(name)) { | | |
| 959 | self.linkLibCpp(); | | |
| 960 | return; | | |
| 961 | } | | |
| 962 | | | |
| 963 | self.link_objects.append(.{ | | |
| 964 | .system_lib = .{ | | |
| 965 | .name = b.dupe(name), | | |
| 966 | .needed = options.needed, | | |
| 967 | .weak = options.weak, | | |
| 968 | .use_pkg_config = options.use_pkg_config, | | |
| 969 | .preferred_link_mode = options.preferred_link_mode, | | |
| 970 | .search_strategy = options.search_strategy, | | |
| 971 | }, | | |
| 972 | }) catch @panic("OOM"); | | |
| 973 | } | 768 | } |
| 974 | | 769 | |
| 975 | pub const AddCSourceFilesOptions = struct { | | |
| 976 | /// When provided, `files` are relative to `dependency` rather than the package that owns the `Compile` step. | | |
| 977 | dependency: ?*std.Build.Dependency = null, | | |
| 978 | files: []const []const u8, | | |
| 979 | flags: []const []const u8 = &.{}, | | |
| 980 | }; | | |
| 981 | | | |
| 982 | /// Handy when you have many C/C++ source files and want them all to have the same flags. | 770 | /// Handy when you have many C/C++ source files and want them all to have the same flags. |
| 983 | pub fn addCSourceFiles(self: *Compile, options: AddCSourceFilesOptions) void { | 771 | pub fn addCSourceFiles(self: *Compile, options: Module.AddCSourceFilesOptions) void { |
| 984 | const b = self.step.owner; | 772 | self.root_module.addCSourceFiles(options); |
| 985 | const c_source_files = b.allocator.create(CSourceFiles) catch @panic("OOM"); | | |
| 986 | | | |
| 987 | const files_copy = b.dupeStrings(options.files); | | |
| 988 | const flags_copy = b.dupeStrings(options.flags); | | |
| 989 | | | |
| 990 | c_source_files.* = .{ | | |
| 991 | .dependency = options.dependency, | | |
| 992 | .files = files_copy, | | |
| 993 | .flags = flags_copy, | | |
| 994 | }; | | |
| 995 | self.link_objects.append(.{ .c_source_files = c_source_files }) catch @panic("OOM"); | | |
| 996 | } | 773 | } |
| 997 | | 774 | |
| 998 | pub fn addCSourceFile(self: *Compile, source: CSourceFile) void { | 775 | pub fn addCSourceFile(self: *Compile, source: Module.CSourceFile) void { |
| 999 | const b = self.step.owner; | 776 | self.root_module.addCSourceFile(source); |
| 1000 | const c_source_file = b.allocator.create(CSourceFile) catch @panic("OOM"); | | |
| 1001 | c_source_file.* = source.dupe(b); | | |
| 1002 | self.link_objects.append(.{ .c_source_file = c_source_file }) catch @panic("OOM"); | | |
| 1003 | source.file.addStepDependencies(&self.step); | | |
| 1004 | } | 777 | } |
| 1005 | | 778 | |
| 1006 | /// Resource files must have the extension `.rc`. | 779 | /// Resource files must have the extension `.rc`. |
| 1007 | /// Can be called regardless of target. The .rc file will be ignored | 780 | /// Can be called regardless of target. The .rc file will be ignored |
| 1008 | /// if the target object format does not support embedded resources. | 781 | /// if the target object format does not support embedded resources. |
| 1009 | pub fn addWin32ResourceFile(self: *Compile, source: RcSourceFile) void { | 782 | pub fn addWin32ResourceFile(self: *Compile, source: Module.RcSourceFile) void { |
| 1010 | // Only the PE/COFF format has a Resource Table, so for any other target | 783 | self.root_module.addWin32ResourceFile(source); |
| 1011 | // the resource file is just ignored. | | |
| 1012 | if (self.target.getObjectFormat() != .coff) return; | | |
| 1013 | | | |
| 1014 | const b = self.step.owner; | | |
| 1015 | const rc_source_file = b.allocator.create(RcSourceFile) catch @panic("OOM"); | | |
| 1016 | rc_source_file.* = source.dupe(b); | | |
| 1017 | self.link_objects.append(.{ .win32_resource_file = rc_source_file }) catch @panic("OOM"); | | |
| 1018 | source.file.addStepDependencies(&self.step); | | |
| 1019 | } | 784 | } |
| 1020 | | 785 | |
| 1021 | pub fn setVerboseLink(self: *Compile, value: bool) void { | 786 | pub fn setVerboseLink(self: *Compile, value: bool) void { |
| ... | @@ -1112,16 +877,11 @@ pub fn getEmittedLlvmBc(self: *Compile) LazyPath { | ... | @@ -1112,16 +877,11 @@ pub fn getEmittedLlvmBc(self: *Compile) LazyPath { |
| 1112 | } | 877 | } |
| 1113 | | 878 | |
| 1114 | pub fn addAssemblyFile(self: *Compile, source: LazyPath) void { | 879 | pub fn addAssemblyFile(self: *Compile, source: LazyPath) void { |
| 1115 | const b = self.step.owner; | 880 | self.root_module.addAssemblyFile(source); |
| 1116 | const source_duped = source.dupe(b); | | |
| 1117 | self.link_objects.append(.{ .assembly_file = source_duped }) catch @panic("OOM"); | | |
| 1118 | source_duped.addStepDependencies(&self.step); | | |
| 1119 | } | 881 | } |
| 1120 | | 882 | |
| 1121 | pub fn addObjectFile(self: *Compile, source: LazyPath) void { | 883 | pub fn addObjectFile(self: *Compile, source: LazyPath) void { |
| 1122 | const b = self.step.owner; | 884 | self.root_module.addObjectFile(source); |
| 1123 | self.link_objects.append(.{ .static_path = source.dupe(b) }) catch @panic("OOM"); | | |
| 1124 | source.addStepDependencies(&self.step); | | |
| 1125 | } | 885 | } |
| 1126 | | 886 | |
| 1127 | pub fn addObject(self: *Compile, obj: *Compile) void { | 887 | pub fn addObject(self: *Compile, obj: *Compile) void { |
| ... | @@ -1131,19 +891,19 @@ pub fn addObject(self: *Compile, obj: *Compile) void { | ... | @@ -1131,19 +891,19 @@ pub fn addObject(self: *Compile, obj: *Compile) void { |
| 1131 | | 891 | |
| 1132 | pub fn addAfterIncludePath(self: *Compile, path: LazyPath) void { | 892 | pub fn addAfterIncludePath(self: *Compile, path: LazyPath) void { |
| 1133 | const b = self.step.owner; | 893 | const b = self.step.owner; |
| 1134 | self.include_dirs.append(IncludeDir{ .path_after = path.dupe(b) }) catch @panic("OOM"); | 894 | self.include_dirs.append(.{ .path_after = path.dupe(b) }) catch @panic("OOM"); |
| 1135 | path.addStepDependencies(&self.step); | 895 | path.addStepDependencies(&self.step); |
| 1136 | } | 896 | } |
| 1137 | | 897 | |
| 1138 | pub fn addSystemIncludePath(self: *Compile, path: LazyPath) void { | 898 | pub fn addSystemIncludePath(self: *Compile, path: LazyPath) void { |
| 1139 | const b = self.step.owner; | 899 | const b = self.step.owner; |
| 1140 | self.include_dirs.append(IncludeDir{ .path_system = path.dupe(b) }) catch @panic("OOM"); | 900 | self.include_dirs.append(.{ .path_system = path.dupe(b) }) catch @panic("OOM"); |
| 1141 | path.addStepDependencies(&self.step); | 901 | path.addStepDependencies(&self.step); |
| 1142 | } | 902 | } |
| 1143 | | 903 | |
| 1144 | pub fn addIncludePath(self: *Compile, path: LazyPath) void { | 904 | pub fn addIncludePath(self: *Compile, path: LazyPath) void { |
| 1145 | const b = self.step.owner; | 905 | const b = self.step.owner; |
| 1146 | self.include_dirs.append(IncludeDir{ .path = path.dupe(b) }) catch @panic("OOM"); | 906 | self.include_dirs.append(.{ .path = path.dupe(b) }) catch @panic("OOM"); |
| 1147 | path.addStepDependencies(&self.step); | 907 | path.addStepDependencies(&self.step); |
| 1148 | } | 908 | } |
| 1149 | | 909 | |
| ... | @@ -1166,48 +926,16 @@ pub fn addRPath(self: *Compile, directory_source: LazyPath) void { | ... | @@ -1166,48 +926,16 @@ pub fn addRPath(self: *Compile, directory_source: LazyPath) void { |
| 1166 | | 926 | |
| 1167 | pub fn addSystemFrameworkPath(self: *Compile, directory_source: LazyPath) void { | 927 | pub fn addSystemFrameworkPath(self: *Compile, directory_source: LazyPath) void { |
| 1168 | const b = self.step.owner; | 928 | const b = self.step.owner; |
| 1169 | self.include_dirs.append(IncludeDir{ .framework_path_system = directory_source.dupe(b) }) catch @panic("OOM"); | 929 | self.include_dirs.append(.{ .framework_path_system = directory_source.dupe(b) }) catch @panic("OOM"); |
| 1170 | directory_source.addStepDependencies(&self.step); | 930 | directory_source.addStepDependencies(&self.step); |
| 1171 | } | 931 | } |
| 1172 | | 932 | |
| 1173 | pub fn addFrameworkPath(self: *Compile, directory_source: LazyPath) void { | 933 | pub fn addFrameworkPath(self: *Compile, directory_source: LazyPath) void { |
| 1174 | const b = self.step.owner; | 934 | const b = self.step.owner; |
| 1175 | self.include_dirs.append(IncludeDir{ .framework_path = directory_source.dupe(b) }) catch @panic("OOM"); | 935 | self.include_dirs.append(.{ .framework_path = directory_source.dupe(b) }) catch @panic("OOM"); |
| 1176 | directory_source.addStepDependencies(&self.step); | 936 | directory_source.addStepDependencies(&self.step); |
| 1177 | } | 937 | } |
| 1178 | | 938 | |
| 1179 | /// Adds a module to be used with `@import` and exposing it in the current | | |
| 1180 | /// package's module table using `name`. | | |
| 1181 | pub fn addModule(cs: *Compile, name: []const u8, module: *Module) void { | | |
| 1182 | const b = cs.step.owner; | | |
| 1183 | cs.modules.put(b.dupe(name), module) catch @panic("OOM"); | | |
| 1184 | | | |
| 1185 | var done = std.AutoHashMap(*Module, void).init(b.allocator); | | |
| 1186 | defer done.deinit(); | | |
| 1187 | cs.addRecursiveBuildDeps(module, &done) catch @panic("OOM"); | | |
| 1188 | } | | |
| 1189 | | | |
| 1190 | /// Adds a module to be used with `@import` without exposing it in the current | | |
| 1191 | /// package's module table. | | |
| 1192 | pub fn addAnonymousModule(cs: *Compile, name: []const u8, options: std.Build.CreateModuleOptions) void { | | |
| 1193 | const b = cs.step.owner; | | |
| 1194 | const module = b.createModule(options); | | |
| 1195 | return addModule(cs, name, module); | | |
| 1196 | } | | |
| 1197 | | | |
| 1198 | pub fn addOptions(cs: *Compile, module_name: []const u8, options: *Step.Options) void { | | |
| 1199 | addModule(cs, module_name, options.createModule()); | | |
| 1200 | } | | |
| 1201 | | | |
| 1202 | fn addRecursiveBuildDeps(cs: *Compile, module: *Module, done: *std.AutoHashMap(*Module, void)) !void { | | |
| 1203 | if (done.contains(module)) return; | | |
| 1204 | try done.put(module, {}); | | |
| 1205 | module.source_file.addStepDependencies(&cs.step); | | |
| 1206 | for (module.dependencies.values()) |dep| { | | |
| 1207 | try cs.addRecursiveBuildDeps(dep, done); | | |
| 1208 | } | | |
| 1209 | } | | |
| 1210 | | | |
| 1211 | /// If Vcpkg was found on the system, it will be added to include and lib | 939 | /// If Vcpkg was found on the system, it will be added to include and lib |
| 1212 | /// paths for the specified target. | 940 | /// paths for the specified target. |
| 1213 | pub fn addVcpkgPaths(self: *Compile, linkage: Compile.Linkage) !void { | 941 | pub fn addVcpkgPaths(self: *Compile, linkage: Compile.Linkage) !void { |
| ... | @@ -1236,7 +964,7 @@ pub fn addVcpkgPaths(self: *Compile, linkage: Compile.Linkage) !void { | ... | @@ -1236,7 +964,7 @@ pub fn addVcpkgPaths(self: *Compile, linkage: Compile.Linkage) !void { |
| 1236 | | 964 | |
| 1237 | const include_path = b.pathJoin(&.{ root, "installed", triplet, "include" }); | 965 | const include_path = b.pathJoin(&.{ root, "installed", triplet, "include" }); |
| 1238 | errdefer allocator.free(include_path); | 966 | errdefer allocator.free(include_path); |
| 1239 | try self.include_dirs.append(IncludeDir{ .path = .{ .path = include_path } }); | 967 | try self.include_dirs.append(.{ .path = .{ .path = include_path } }); |
| 1240 | | 968 | |
| 1241 | const lib_path = b.pathJoin(&.{ root, "installed", triplet, "lib" }); | 969 | const lib_path = b.pathJoin(&.{ root, "installed", triplet, "lib" }); |
| 1242 | try self.lib_paths.append(.{ .path = lib_path }); | 970 | try self.lib_paths.append(.{ .path = lib_path }); |
| ... | @@ -1270,87 +998,53 @@ fn linkLibraryOrObject(self: *Compile, other: *Compile) void { | ... | @@ -1270,87 +998,53 @@ fn linkLibraryOrObject(self: *Compile, other: *Compile) void { |
| 1270 | } | 998 | } |
| 1271 | } | 999 | } |
| 1272 | | 1000 | |
| 1273 | fn appendModuleArgs( | 1001 | fn appendModuleArgs(cs: *Compile, zig_args: *ArrayList([]const u8)) !void { |
| 1274 | cs: *Compile, | | |
| 1275 | zig_args: *ArrayList([]const u8), | | |
| 1276 | ) error{OutOfMemory}!void { | | |
| 1277 | const b = cs.step.owner; | 1002 | const b = cs.step.owner; |
| 1278 | // First, traverse the whole dependency graph and give every module a unique name, ideally one | 1003 | // First, traverse the whole dependency graph and give every module a |
| 1279 | // named after what it's called somewhere in the graph. It will help here to have both a mapping | 1004 | // unique name, ideally one named after what it's called somewhere in the |
| 1280 | // from module to name and a set of all the currently-used names. | 1005 | // graph. It will help here to have both a mapping from module to name and |
| 1281 | var mod_names = std.AutoHashMap(*Module, []const u8).init(b.allocator); | 1006 | // a set of all the currently-used names. |
| | 1007 | var mod_names: std.AutoArrayHashMapUnmanaged(*Module, []const u8) = .{}; |
| 1282 | var names = std.StringHashMap(void).init(b.allocator); | 1008 | var names = std.StringHashMap(void).init(b.allocator); |
| 1283 | | 1009 | |
| 1284 | var to_name = std.ArrayList(struct { | | |
| 1285 | name: []const u8, | | |
| 1286 | mod: *Module, | | |
| 1287 | }).init(b.allocator); | | |
| 1288 | { | 1010 | { |
| 1289 | var it = cs.modules.iterator(); | 1011 | var it = cs.root_module.iterateDependencies(null); |
| 1290 | while (it.next()) |kv| { | 1012 | _ = it.next(); // Skip over the root module. |
| | 1013 | while (it.next()) |item| { |
| 1291 | // While we're traversing the root dependencies, let's make sure that no module names | 1014 | // While we're traversing the root dependencies, let's make sure that no module names |
| 1292 | // have colons in them, since the CLI forbids it. We handle this for transitive | 1015 | // have colons in them, since the CLI forbids it. We handle this for transitive |
| 1293 | // dependencies further down. | 1016 | // dependencies further down. |
| 1294 | if (std.mem.indexOfScalar(u8, kv.key_ptr.*, ':') != null) { | 1017 | if (std.mem.indexOfScalar(u8, item.name, ':') != null) { |
| 1295 | @panic("Module names cannot contain colons"); | 1018 | return cs.step.fail("module '{s}' contains a colon", .{item.name}); |
| 1296 | } | 1019 | } |
| 1297 | try to_name.append(.{ | | |
| 1298 | .name = kv.key_ptr.*, | | |
| 1299 | .mod = kv.value_ptr.*, | | |
| 1300 | }); | | |
| 1301 | } | | |
| 1302 | } | | |
| 1303 | | | |
| 1304 | while (to_name.popOrNull()) |dep| { | | |
| 1305 | if (mod_names.contains(dep.mod)) continue; | | |
| 1306 | | 1020 | |
| 1307 | // We'll use this buffer to store the name we decide on | 1021 | var name = item.name; |
| 1308 | var buf = try b.allocator.alloc(u8, dep.name.len + 32); | 1022 | var n: usize = 0; |
| 1309 | // First, try just the exposed dependency name | 1023 | while (names.contains(name)) { |
| 1310 | @memcpy(buf[0..dep.name.len], dep.name); | 1024 | name = b.fmt("{s}{d}", .{ item.name, n }); |
| 1311 | var name = buf[0..dep.name.len]; | 1025 | n += 1; |
| 1312 | var n: usize = 0; | | |
| 1313 | while (names.contains(name)) { | | |
| 1314 | // If that failed, append an incrementing number to the end | | |
| 1315 | name = std.fmt.bufPrint(buf, "{s}{}", .{ dep.name, n }) catch unreachable; | | |
| 1316 | n += 1; | | |
| 1317 | } | | |
| 1318 | | | |
| 1319 | try mod_names.put(dep.mod, name); | | |
| 1320 | try names.put(name, {}); | | |
| 1321 | | | |
| 1322 | var it = dep.mod.dependencies.iterator(); | | |
| 1323 | while (it.next()) |kv| { | | |
| 1324 | // Same colon-in-name check as above, but for transitive dependencies. | | |
| 1325 | if (std.mem.indexOfScalar(u8, kv.key_ptr.*, ':') != null) { | | |
| 1326 | @panic("Module names cannot contain colons"); | | |
| 1327 | } | 1026 | } |
| 1328 | try to_name.append(.{ | 1027 | |
| 1329 | .name = kv.key_ptr.*, | 1028 | try mod_names.put(b.allocator, item.module, name); |
| 1330 | .mod = kv.value_ptr.*, | 1029 | try names.put(name, {}); |
| 1331 | }); | | |
| 1332 | } | 1030 | } |
| 1333 | } | 1031 | } |
| 1334 | | 1032 | |
| 1335 | // Since the module names given to the CLI are based off of the exposed names, we already know | 1033 | // Since the module names given to the CLI are based off of the exposed |
| 1336 | // that none of the CLI names have colons in them, so there's no need to check that explicitly. | 1034 | // names, we already know that none of the CLI names have colons in them, |
| | 1035 | // so there's no need to check that explicitly. |
| 1337 | | 1036 | |
| 1338 | // Every module in the graph is now named; output their definitions | 1037 | // Every module in the graph is now named; output their definitions |
| 1339 | { | 1038 | for (mod_names.keys(), mod_names.values()) |mod, name| { |
| 1340 | var it = mod_names.iterator(); | 1039 | const root_src = mod.root_source_file orelse continue; |
| 1341 | while (it.next()) |kv| { | 1040 | const deps_str = try constructDepString(b.allocator, mod_names, mod.import_table); |
| 1342 | const mod = kv.key_ptr.*; | 1041 | const src = root_src.getPath2(mod.owner, &cs.step); |
| 1343 | const name = kv.value_ptr.*; | 1042 | try zig_args.append("--mod"); |
| 1344 | | 1043 | try zig_args.append(b.fmt("{s}:{s}:{s}", .{ name, deps_str, src })); |
| 1345 | const deps_str = try constructDepString(b.allocator, mod_names, mod.dependencies); | | |
| 1346 | const src = mod.source_file.getPath(mod.builder); | | |
| 1347 | try zig_args.append("--mod"); | | |
| 1348 | try zig_args.append(try std.fmt.allocPrint(b.allocator, "{s}:{s}:{s}", .{ name, deps_str, src })); | | |
| 1349 | } | | |
| 1350 | } | 1044 | } |
| 1351 | | 1045 | |
| 1352 | // Lastly, output the root dependencies | 1046 | // Lastly, output the root dependencies |
| 1353 | const deps_str = try constructDepString(b.allocator, mod_names, cs.modules); | 1047 | const deps_str = try constructDepString(b.allocator, mod_names, cs.root_module.import_table); |
| 1354 | if (deps_str.len > 0) { | 1048 | if (deps_str.len > 0) { |
| 1355 | try zig_args.append("--deps"); | 1049 | try zig_args.append("--deps"); |
| 1356 | try zig_args.append(deps_str); | 1050 | try zig_args.append(deps_str); |
| ... | @@ -1359,7 +1053,7 @@ fn appendModuleArgs( | ... | @@ -1359,7 +1053,7 @@ fn appendModuleArgs( |
| 1359 | | 1053 | |
| 1360 | fn constructDepString( | 1054 | fn constructDepString( |
| 1361 | allocator: std.mem.Allocator, | 1055 | allocator: std.mem.Allocator, |
| 1362 | mod_names: std.AutoHashMap(*Module, []const u8), | 1056 | mod_names: std.AutoArrayHashMapUnmanaged(*Module, []const u8), |
| 1363 | deps: std.StringArrayHashMap(*Module), | 1057 | deps: std.StringArrayHashMap(*Module), |
| 1364 | ) ![]const u8 { | 1058 | ) ![]const u8 { |
| 1365 | var deps_str = std.ArrayList(u8).init(allocator); | 1059 | var deps_str = std.ArrayList(u8).init(allocator); |
| ... | @@ -1408,10 +1102,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1408,10 +1102,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1408 | const b = step.owner; | 1102 | const b = step.owner; |
| 1409 | const self = @fieldParentPtr(Compile, "step", step); | 1103 | const self = @fieldParentPtr(Compile, "step", step); |
| 1410 | | 1104 | |
| 1411 | if (self.root_src == null and self.link_objects.items.len == 0) { | | |
| 1412 | return step.fail("the linker needs one or more objects to link", .{}); | | |
| 1413 | } | | |
| 1414 | | | |
| 1415 | var zig_args = ArrayList([]const u8).init(b.allocator); | 1105 | var zig_args = ArrayList([]const u8).init(b.allocator); |
| 1416 | defer zig_args.deinit(); | 1106 | defer zig_args.deinit(); |
| 1417 | | 1107 | |
| ... | @@ -1432,7 +1122,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1432,7 +1122,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1432 | try addFlag(&zig_args, "llvm", self.use_llvm); | 1122 | try addFlag(&zig_args, "llvm", self.use_llvm); |
| 1433 | try addFlag(&zig_args, "lld", self.use_lld); | 1123 | try addFlag(&zig_args, "lld", self.use_lld); |
| 1434 | | 1124 | |
| 1435 | if (self.target.ofmt) |ofmt| { | 1125 | if (self.root_module.target.ofmt) |ofmt| { |
| 1436 | try zig_args.append(try std.fmt.allocPrint(b.allocator, "-ofmt={s}", .{@tagName(ofmt)})); | 1126 | try zig_args.append(try std.fmt.allocPrint(b.allocator, "-ofmt={s}", .{@tagName(ofmt)})); |
| 1437 | } | 1127 | } |
| 1438 | | 1128 | |
| ... | @@ -1458,204 +1148,248 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1458,204 +1148,248 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1458 | try zig_args.append(try std.fmt.allocPrint(b.allocator, "{}", .{stack_size})); | 1148 | try zig_args.append(try std.fmt.allocPrint(b.allocator, "{}", .{stack_size})); |
| 1459 | } | 1149 | } |
| 1460 | | 1150 | |
| 1461 | if (self.root_src) |root_src| try zig_args.append(root_src.getPath(b)); | 1151 | { |
| | 1152 | var seen_system_libs: std.StringHashMapUnmanaged(void) = .{}; |
| | 1153 | var frameworks: std.StringArrayHashMapUnmanaged(Module.FrameworkLinkInfo) = .{}; |
| | 1154 | |
| | 1155 | var prev_has_cflags = false; |
| | 1156 | var prev_has_rcflags = false; |
| | 1157 | var prev_search_strategy: Module.SystemLib.SearchStrategy = .paths_first; |
| | 1158 | var prev_preferred_link_mode: std.builtin.LinkMode = .Dynamic; |
| | 1159 | // Track the number of positional arguments so that a nice error can be |
| | 1160 | // emitted if there is nothing to link. |
| | 1161 | var total_linker_objects: usize = 0; |
| | 1162 | |
| | 1163 | if (self.root_module.root_source_file) |lp| { |
| | 1164 | try zig_args.append(lp.getPath(b)); |
| | 1165 | total_linker_objects += 1; |
| | 1166 | } |
| 1462 | | 1167 | |
| 1463 | // We will add link objects from transitive dependencies, but we want to keep | 1168 | try self.root_module.appendZigProcessFlags(&zig_args, step); |
| 1464 | // all link objects in the same order provided. | | |
| 1465 | // This array is used to keep self.link_objects immutable. | | |
| 1466 | var transitive_deps: TransitiveDeps = .{ | | |
| 1467 | .link_objects = ArrayList(LinkObject).init(b.allocator), | | |
| 1468 | .seen_system_libs = StringHashMap(void).init(b.allocator), | | |
| 1469 | .seen_steps = std.AutoHashMap(*const Step, void).init(b.allocator), | | |
| 1470 | .is_linking_libcpp = self.is_linking_libcpp, | | |
| 1471 | .is_linking_libc = self.is_linking_libc, | | |
| 1472 | .frameworks = &self.frameworks, | | |
| 1473 | }; | | |
| 1474 | | 1169 | |
| 1475 | try transitive_deps.seen_steps.put(&self.step, {}); | 1170 | var it = self.root_module.iterateDependencies(self); |
| 1476 | try transitive_deps.add(self.link_objects.items); | 1171 | while (it.next()) |key| { |
| 1477 | | 1172 | const module = key.module; |
| 1478 | var prev_has_cflags = false; | 1173 | const compile = key.compile.?; |
| 1479 | var prev_has_rcflags = false; | 1174 | const dyn = compile.isDynamicLibrary(); |
| 1480 | var prev_search_strategy: SystemLib.SearchStrategy = .paths_first; | | |
| 1481 | var prev_preferred_link_mode: std.builtin.LinkMode = .Dynamic; | | |
| 1482 | | | |
| 1483 | for (transitive_deps.link_objects.items) |link_object| { | | |
| 1484 | switch (link_object) { | | |
| 1485 | .static_path => |static_path| try zig_args.append(static_path.getPath(b)), | | |
| 1486 | | | |
| 1487 | .other_step => |other| switch (other.kind) { | | |
| 1488 | .exe => @panic("Cannot link with an executable build artifact"), | | |
| 1489 | .@"test" => @panic("Cannot link with a test"), | | |
| 1490 | .obj => { | | |
| 1491 | try zig_args.append(other.getEmittedBin().getPath(b)); | | |
| 1492 | }, | | |
| 1493 | .lib => l: { | | |
| 1494 | if (self.isStaticLibrary() and other.isStaticLibrary()) { | | |
| 1495 | // Avoid putting a static library inside a static library. | | |
| 1496 | break :l; | | |
| 1497 | } | | |
| 1498 | | 1175 | |
| 1499 | // For DLLs, we gotta link against the implib. For | 1176 | // Inherit dependency on libc and libc++. |
| 1500 | // everything else, we directly link against the library file. | 1177 | if (module.link_libc == true) self.is_linking_libc = true; |
| 1501 | const full_path_lib = if (other.producesImplib()) | 1178 | if (module.link_libcpp == true) self.is_linking_libcpp = true; |
| 1502 | other.getGeneratedFilePath("generated_implib", &self.step) | | |
| 1503 | else | | |
| 1504 | other.getGeneratedFilePath("generated_bin", &self.step); | | |
| 1505 | try zig_args.append(full_path_lib); | | |
| 1506 | | | |
| 1507 | if (other.linkage == Linkage.dynamic and !self.target.isWindows()) { | | |
| 1508 | if (fs.path.dirname(full_path_lib)) |dirname| { | | |
| 1509 | try zig_args.append("-rpath"); | | |
| 1510 | try zig_args.append(dirname); | | |
| 1511 | } | | |
| 1512 | } | | |
| 1513 | }, | | |
| 1514 | }, | | |
| 1515 | | 1179 | |
| 1516 | .system_lib => |system_lib| { | 1180 | // Inherit dependencies on darwin frameworks. |
| 1517 | if ((system_lib.search_strategy != prev_search_strategy or | 1181 | if (!dyn) { |
| 1518 | system_lib.preferred_link_mode != prev_preferred_link_mode) and | 1182 | for (module.frameworks.keys(), module.frameworks.values()) |name, info| { |
| 1519 | self.linkage != .static) | 1183 | try frameworks.put(b.allocator, name, info); |
| 1520 | { | | |
| 1521 | switch (system_lib.search_strategy) { | | |
| 1522 | .no_fallback => switch (system_lib.preferred_link_mode) { | | |
| 1523 | .Dynamic => try zig_args.append("-search_dylibs_only"), | | |
| 1524 | .Static => try zig_args.append("-search_static_only"), | | |
| 1525 | }, | | |
| 1526 | .paths_first => switch (system_lib.preferred_link_mode) { | | |
| 1527 | .Dynamic => try zig_args.append("-search_paths_first"), | | |
| 1528 | .Static => try zig_args.append("-search_paths_first_static"), | | |
| 1529 | }, | | |
| 1530 | .mode_first => switch (system_lib.preferred_link_mode) { | | |
| 1531 | .Dynamic => try zig_args.append("-search_dylibs_first"), | | |
| 1532 | .Static => try zig_args.append("-search_static_first"), | | |
| 1533 | }, | | |
| 1534 | } | | |
| 1535 | prev_search_strategy = system_lib.search_strategy; | | |
| 1536 | prev_preferred_link_mode = system_lib.preferred_link_mode; | | |
| 1537 | } | 1184 | } |
| | 1185 | } |
| 1538 | | 1186 | |
| 1539 | const prefix: []const u8 = prefix: { | 1187 | // Inherit dependencies on system libraries and static libraries. |
| 1540 | if (system_lib.needed) break :prefix "-needed-l"; | 1188 | total_linker_objects += module.link_objects.items.len; |
| 1541 | if (system_lib.weak) break :prefix "-weak-l"; | 1189 | for (module.link_objects.items) |link_object| { |
| 1542 | break :prefix "-l"; | 1190 | switch (link_object) { |
| 1543 | }; | 1191 | .static_path => |static_path| try zig_args.append(static_path.getPath(b)), |
| 1544 | switch (system_lib.use_pkg_config) { | 1192 | .system_lib => |system_lib| { |
| 1545 | .no => try zig_args.append(b.fmt("{s}{s}", .{ prefix, system_lib.name })), | 1193 | if ((try seen_system_libs.fetchPut(b.allocator, system_lib.name, {})) != null) |
| 1546 | .yes, .force => { | 1194 | continue; |
| 1547 | if (self.runPkgConfig(system_lib.name)) |args| { | 1195 | |
| 1548 | try zig_args.appendSlice(args); | 1196 | if (dyn) |
| 1549 | } else |err| switch (err) { | 1197 | continue; |
| 1550 | error.PkgConfigInvalidOutput, | 1198 | |
| 1551 | error.PkgConfigCrashed, | 1199 | if ((system_lib.search_strategy != prev_search_strategy or |
| 1552 | error.PkgConfigFailed, | 1200 | system_lib.preferred_link_mode != prev_preferred_link_mode) and |
| 1553 | error.PkgConfigNotInstalled, | 1201 | self.linkage != .static) |
| 1554 | error.PackageNotFound, | 1202 | { |
| 1555 | => switch (system_lib.use_pkg_config) { | 1203 | switch (system_lib.search_strategy) { |
| 1556 | .yes => { | 1204 | .no_fallback => switch (system_lib.preferred_link_mode) { |
| 1557 | // pkg-config failed, so fall back to linking the library | 1205 | .Dynamic => try zig_args.append("-search_dylibs_only"), |
| 1558 | // by name directly. | 1206 | .Static => try zig_args.append("-search_static_only"), |
| 1559 | try zig_args.append(b.fmt("{s}{s}", .{ | 1207 | }, |
| 1560 | prefix, | 1208 | .paths_first => switch (system_lib.preferred_link_mode) { |
| 1561 | system_lib.name, | 1209 | .Dynamic => try zig_args.append("-search_paths_first"), |
| 1562 | })); | 1210 | .Static => try zig_args.append("-search_paths_first_static"), |
| 1563 | }, | 1211 | }, |
| 1564 | .force => { | 1212 | .mode_first => switch (system_lib.preferred_link_mode) { |
| 1565 | panic("pkg-config failed for library {s}", .{system_lib.name}); | 1213 | .Dynamic => try zig_args.append("-search_dylibs_first"), |
| | 1214 | .Static => try zig_args.append("-search_static_first"), |
| 1566 | }, | 1215 | }, |
| 1567 | .no => unreachable, | 1216 | } |
| | 1217 | prev_search_strategy = system_lib.search_strategy; |
| | 1218 | prev_preferred_link_mode = system_lib.preferred_link_mode; |
| | 1219 | } |
| | 1220 | |
| | 1221 | const prefix: []const u8 = prefix: { |
| | 1222 | if (system_lib.needed) break :prefix "-needed-l"; |
| | 1223 | if (system_lib.weak) break :prefix "-weak-l"; |
| | 1224 | break :prefix "-l"; |
| | 1225 | }; |
| | 1226 | switch (system_lib.use_pkg_config) { |
| | 1227 | .no => try zig_args.append(b.fmt("{s}{s}", .{ prefix, system_lib.name })), |
| | 1228 | .yes, .force => { |
| | 1229 | if (self.runPkgConfig(system_lib.name)) |args| { |
| | 1230 | try zig_args.appendSlice(args); |
| | 1231 | } else |err| switch (err) { |
| | 1232 | error.PkgConfigInvalidOutput, |
| | 1233 | error.PkgConfigCrashed, |
| | 1234 | error.PkgConfigFailed, |
| | 1235 | error.PkgConfigNotInstalled, |
| | 1236 | error.PackageNotFound, |
| | 1237 | => switch (system_lib.use_pkg_config) { |
| | 1238 | .yes => { |
| | 1239 | // pkg-config failed, so fall back to linking the library |
| | 1240 | // by name directly. |
| | 1241 | try zig_args.append(b.fmt("{s}{s}", .{ |
| | 1242 | prefix, |
| | 1243 | system_lib.name, |
| | 1244 | })); |
| | 1245 | }, |
| | 1246 | .force => { |
| | 1247 | panic("pkg-config failed for library {s}", .{system_lib.name}); |
| | 1248 | }, |
| | 1249 | .no => unreachable, |
| | 1250 | }, |
| | 1251 | |
| | 1252 | else => |e| return e, |
| | 1253 | } |
| | 1254 | }, |
| | 1255 | } |
| | 1256 | }, |
| | 1257 | .other_step => |other| { |
| | 1258 | const included_in_lib = (compile.kind == .lib and other.kind == .obj); |
| | 1259 | if (dyn or included_in_lib) |
| | 1260 | continue; |
| | 1261 | |
| | 1262 | switch (other.kind) { |
| | 1263 | .exe => return step.fail("cannot link with an executable build artifact", .{}), |
| | 1264 | .@"test" => return step.fail("cannot link with a test", .{}), |
| | 1265 | .obj => { |
| | 1266 | try zig_args.append(other.getEmittedBin().getPath(b)); |
| | 1267 | }, |
| | 1268 | .lib => l: { |
| | 1269 | if (self.isStaticLibrary() and other.isStaticLibrary()) { |
| | 1270 | // Avoid putting a static library inside a static library. |
| | 1271 | break :l; |
| | 1272 | } |
| | 1273 | |
| | 1274 | // For DLLs, we gotta link against the implib. For |
| | 1275 | // everything else, we directly link against the library file. |
| | 1276 | const full_path_lib = if (other.producesImplib()) |
| | 1277 | other.getGeneratedFilePath("generated_implib", &self.step) |
| | 1278 | else |
| | 1279 | other.getGeneratedFilePath("generated_bin", &self.step); |
| | 1280 | try zig_args.append(full_path_lib); |
| | 1281 | |
| | 1282 | if (other.linkage == Linkage.dynamic and |
| | 1283 | self.root_module.target_info.target.os.tag != .windows) |
| | 1284 | { |
| | 1285 | if (fs.path.dirname(full_path_lib)) |dirname| { |
| | 1286 | try zig_args.append("-rpath"); |
| | 1287 | try zig_args.append(dirname); |
| | 1288 | } |
| | 1289 | } |
| 1568 | }, | 1290 | }, |
| | 1291 | } |
| | 1292 | }, |
| | 1293 | .assembly_file => |asm_file| { |
| | 1294 | if (prev_has_cflags) { |
| | 1295 | try zig_args.append("-cflags"); |
| | 1296 | try zig_args.append("--"); |
| | 1297 | prev_has_cflags = false; |
| | 1298 | } |
| | 1299 | try zig_args.append(asm_file.getPath(b)); |
| | 1300 | }, |
| 1569 | | 1301 | |
| 1570 | else => |e| return e, | 1302 | .c_source_file => |c_source_file| { |
| | 1303 | if (c_source_file.flags.len == 0) { |
| | 1304 | if (prev_has_cflags) { |
| | 1305 | try zig_args.append("-cflags"); |
| | 1306 | try zig_args.append("--"); |
| | 1307 | prev_has_cflags = false; |
| | 1308 | } |
| | 1309 | } else { |
| | 1310 | try zig_args.append("-cflags"); |
| | 1311 | for (c_source_file.flags) |arg| { |
| | 1312 | try zig_args.append(arg); |
| | 1313 | } |
| | 1314 | try zig_args.append("--"); |
| | 1315 | prev_has_cflags = true; |
| 1571 | } | 1316 | } |
| | 1317 | try zig_args.append(c_source_file.file.getPath(b)); |
| 1572 | }, | 1318 | }, |
| 1573 | } | | |
| 1574 | }, | | |
| 1575 | | 1319 | |
| 1576 | .assembly_file => |asm_file| { | 1320 | .c_source_files => |c_source_files| { |
| 1577 | if (prev_has_cflags) { | 1321 | if (c_source_files.flags.len == 0) { |
| 1578 | try zig_args.append("-cflags"); | 1322 | if (prev_has_cflags) { |
| 1579 | try zig_args.append("--"); | 1323 | try zig_args.append("-cflags"); |
| 1580 | prev_has_cflags = false; | 1324 | try zig_args.append("--"); |
| 1581 | } | 1325 | prev_has_cflags = false; |
| 1582 | try zig_args.append(asm_file.getPath(b)); | 1326 | } |
| 1583 | }, | 1327 | } else { |
| | 1328 | try zig_args.append("-cflags"); |
| | 1329 | for (c_source_files.flags) |flag| { |
| | 1330 | try zig_args.append(flag); |
| | 1331 | } |
| | 1332 | try zig_args.append("--"); |
| | 1333 | prev_has_cflags = true; |
| | 1334 | } |
| | 1335 | if (c_source_files.dependency) |dep| { |
| | 1336 | for (c_source_files.files) |file| { |
| | 1337 | try zig_args.append(dep.builder.pathFromRoot(file)); |
| | 1338 | } |
| | 1339 | } else { |
| | 1340 | for (c_source_files.files) |file| { |
| | 1341 | try zig_args.append(b.pathFromRoot(file)); |
| | 1342 | } |
| | 1343 | } |
| | 1344 | }, |
| 1584 | | 1345 | |
| 1585 | .c_source_file => |c_source_file| { | 1346 | .win32_resource_file => |rc_source_file| { |
| 1586 | if (c_source_file.flags.len == 0) { | 1347 | if (rc_source_file.flags.len == 0) { |
| 1587 | if (prev_has_cflags) { | 1348 | if (prev_has_rcflags) { |
| 1588 | try zig_args.append("-cflags"); | 1349 | try zig_args.append("-rcflags"); |
| 1589 | try zig_args.append("--"); | 1350 | try zig_args.append("--"); |
| 1590 | prev_has_cflags = false; | 1351 | prev_has_rcflags = false; |
| 1591 | } | 1352 | } |
| 1592 | } else { | 1353 | } else { |
| 1593 | try zig_args.append("-cflags"); | 1354 | try zig_args.append("-rcflags"); |
| 1594 | for (c_source_file.flags) |arg| { | 1355 | for (rc_source_file.flags) |arg| { |
| 1595 | try zig_args.append(arg); | 1356 | try zig_args.append(arg); |
| 1596 | } | 1357 | } |
| 1597 | try zig_args.append("--"); | 1358 | try zig_args.append("--"); |
| 1598 | prev_has_cflags = true; | 1359 | prev_has_rcflags = true; |
| | 1360 | } |
| | 1361 | try zig_args.append(rc_source_file.file.getPath(b)); |
| | 1362 | }, |
| 1599 | } | 1363 | } |
| 1600 | try zig_args.append(c_source_file.file.getPath(b)); | 1364 | } |
| 1601 | }, | 1365 | } |
| 1602 | | 1366 | |
| 1603 | .c_source_files => |c_source_files| { | 1367 | if (total_linker_objects == 0) { |
| 1604 | if (c_source_files.flags.len == 0) { | 1368 | return step.fail("the linker needs one or more objects to link", .{}); |
| 1605 | if (prev_has_cflags) { | 1369 | } |
| 1606 | try zig_args.append("-cflags"); | | |
| 1607 | try zig_args.append("--"); | | |
| 1608 | prev_has_cflags = false; | | |
| 1609 | } | | |
| 1610 | } else { | | |
| 1611 | try zig_args.append("-cflags"); | | |
| 1612 | for (c_source_files.flags) |flag| { | | |
| 1613 | try zig_args.append(flag); | | |
| 1614 | } | | |
| 1615 | try zig_args.append("--"); | | |
| 1616 | prev_has_cflags = true; | | |
| 1617 | } | | |
| 1618 | if (c_source_files.dependency) |dep| { | | |
| 1619 | for (c_source_files.files) |file| { | | |
| 1620 | try zig_args.append(dep.builder.pathFromRoot(file)); | | |
| 1621 | } | | |
| 1622 | } else { | | |
| 1623 | for (c_source_files.files) |file| { | | |
| 1624 | try zig_args.append(b.pathFromRoot(file)); | | |
| 1625 | } | | |
| 1626 | } | | |
| 1627 | }, | | |
| 1628 | | 1370 | |
| 1629 | .win32_resource_file => |rc_source_file| { | 1371 | for (frameworks.keys(), frameworks.values()) |name, info| { |
| 1630 | if (rc_source_file.flags.len == 0) { | 1372 | if (info.needed) { |
| 1631 | if (prev_has_rcflags) { | 1373 | try zig_args.append("-needed_framework"); |
| 1632 | try zig_args.append("-rcflags"); | 1374 | } else if (info.weak) { |
| 1633 | try zig_args.append("--"); | 1375 | try zig_args.append("-weak_framework"); |
| 1634 | prev_has_rcflags = false; | 1376 | } else { |
| 1635 | } | 1377 | try zig_args.append("-framework"); |
| 1636 | } else { | 1378 | } |
| 1637 | try zig_args.append("-rcflags"); | 1379 | try zig_args.append(name); |
| 1638 | for (rc_source_file.flags) |arg| { | | |
| 1639 | try zig_args.append(arg); | | |
| 1640 | } | | |
| 1641 | try zig_args.append("--"); | | |
| 1642 | prev_has_rcflags = true; | | |
| 1643 | } | | |
| 1644 | try zig_args.append(rc_source_file.file.getPath(b)); | | |
| 1645 | }, | | |
| 1646 | } | 1380 | } |
| 1647 | } | | |
| 1648 | | 1381 | |
| 1649 | if (self.win32_manifest) |manifest_file| { | 1382 | if (self.is_linking_libcpp) { |
| 1650 | try zig_args.append(manifest_file.getPath(b)); | 1383 | try zig_args.append("-lc++"); |
| 1651 | } | 1384 | } |
| 1652 | | 1385 | |
| 1653 | if (transitive_deps.is_linking_libcpp) { | 1386 | if (self.is_linking_libc) { |
| 1654 | try zig_args.append("-lc++"); | 1387 | try zig_args.append("-lc"); |
| | 1388 | } |
| 1655 | } | 1389 | } |
| 1656 | | 1390 | |
| 1657 | if (transitive_deps.is_linking_libc) { | 1391 | if (self.win32_manifest) |manifest_file| { |
| 1658 | try zig_args.append("-lc"); | 1392 | try zig_args.append(manifest_file.getPath(b)); |
| 1659 | } | 1393 | } |
| 1660 | | 1394 | |
| 1661 | if (self.image_base) |image_base| { | 1395 | if (self.image_base) |image_base| { |
| ... | @@ -1702,17 +1436,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1702,17 +1436,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1702 | if (self.generated_llvm_ir != null) try zig_args.append("-femit-llvm-ir"); | 1436 | if (self.generated_llvm_ir != null) try zig_args.append("-femit-llvm-ir"); |
| 1703 | if (self.generated_h != null) try zig_args.append("-femit-h"); | 1437 | if (self.generated_h != null) try zig_args.append("-femit-h"); |
| 1704 | | 1438 | |
| 1705 | try addFlag(&zig_args, "strip", self.strip); | | |
| 1706 | try addFlag(&zig_args, "formatted-panics", self.formatted_panics); | | |
| 1707 | try addFlag(&zig_args, "unwind-tables", self.unwind_tables); | | |
| 1708 | | | |
| 1709 | if (self.dwarf_format) |dwarf_format| { | | |
| 1710 | try zig_args.append(switch (dwarf_format) { | | |
| 1711 | .@"32" => "-gdwarf32", | | |
| 1712 | .@"64" => "-gdwarf64", | | |
| 1713 | }); | | |
| 1714 | } | | |
| 1715 | | | |
| 1716 | switch (self.compress_debug_sections) { | 1439 | switch (self.compress_debug_sections) { |
| 1717 | .none => {}, | 1440 | .none => {}, |
| 1718 | .zlib => try zig_args.append("--compress-debug-sections=zlib"), | 1441 | .zlib => try zig_args.append("--compress-debug-sections=zlib"), |
| ... | @@ -1769,11 +1492,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1769,11 +1492,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1769 | try zig_args.append(libc_file); | 1492 | try zig_args.append(libc_file); |
| 1770 | } | 1493 | } |
| 1771 | | 1494 | |
| 1772 | switch (self.optimize) { | | |
| 1773 | .Debug => {}, // Skip since it's the default. | | |
| 1774 | else => try zig_args.append(b.fmt("-O{s}", .{@tagName(self.optimize)})), | | |
| 1775 | } | | |
| 1776 | | | |
| 1777 | try zig_args.append("--cache-dir"); | 1495 | try zig_args.append("--cache-dir"); |
| 1778 | try zig_args.append(b.cache_root.path orelse "."); | 1496 | try zig_args.append(b.cache_root.path orelse "."); |
| 1779 | | 1497 | |
| ... | @@ -1793,11 +1511,11 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1793,11 +1511,11 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1793 | try zig_args.append(b.fmt("{}", .{version})); | 1511 | try zig_args.append(b.fmt("{}", .{version})); |
| 1794 | } | 1512 | } |
| 1795 | | 1513 | |
| 1796 | if (self.target.isDarwin()) { | 1514 | if (self.root_module.target_info.target.isDarwin()) { |
| 1797 | const install_name = self.install_name orelse b.fmt("@rpath/{s}{s}{s}", .{ | 1515 | const install_name = self.install_name orelse b.fmt("@rpath/{s}{s}{s}", .{ |
| 1798 | self.target.libPrefix(), | 1516 | self.root_module.target_info.target.libPrefix(), |
| 1799 | self.name, | 1517 | self.name, |
| 1800 | self.target.dynamicLibSuffix(), | 1518 | self.root_module.target_info.target.dynamicLibSuffix(), |
| 1801 | }); | 1519 | }); |
| 1802 | try zig_args.append("-install_name"); | 1520 | try zig_args.append("-install_name"); |
| 1803 | try zig_args.append(install_name); | 1521 | try zig_args.append(install_name); |
| ... | @@ -1823,27 +1541,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1823,27 +1541,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1823 | } | 1541 | } |
| 1824 | | 1542 | |
| 1825 | try addFlag(&zig_args, "compiler-rt", self.bundle_compiler_rt); | 1543 | try addFlag(&zig_args, "compiler-rt", self.bundle_compiler_rt); |
| 1826 | try addFlag(&zig_args, "single-threaded", self.single_threaded); | | |
| 1827 | if (self.disable_stack_probing) { | | |
| 1828 | try zig_args.append("-fno-stack-check"); | | |
| 1829 | } | | |
| 1830 | try addFlag(&zig_args, "stack-protector", self.stack_protector); | | |
| 1831 | if (self.red_zone) |red_zone| { | | |
| 1832 | if (red_zone) { | | |
| 1833 | try zig_args.append("-mred-zone"); | | |
| 1834 | } else { | | |
| 1835 | try zig_args.append("-mno-red-zone"); | | |
| 1836 | } | | |
| 1837 | } | | |
| 1838 | try addFlag(&zig_args, "omit-frame-pointer", self.omit_frame_pointer); | | |
| 1839 | try addFlag(&zig_args, "dll-export-fns", self.dll_export_fns); | 1544 | try addFlag(&zig_args, "dll-export-fns", self.dll_export_fns); |
| 1840 | | | |
| 1841 | if (self.disable_sanitize_c) { | | |
| 1842 | try zig_args.append("-fno-sanitize-c"); | | |
| 1843 | } | | |
| 1844 | if (self.sanitize_thread) { | | |
| 1845 | try zig_args.append("-fsanitize-thread"); | | |
| 1846 | } | | |
| 1847 | if (self.rdynamic) { | 1545 | if (self.rdynamic) { |
| 1848 | try zig_args.append("-rdynamic"); | 1546 | try zig_args.append("-rdynamic"); |
| 1849 | } | 1547 | } |
| ... | @@ -1875,29 +1573,9 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1875,29 +1573,9 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1875 | try zig_args.append(b.fmt("--global-base={d}", .{global_base})); | 1573 | try zig_args.append(b.fmt("--global-base={d}", .{global_base})); |
| 1876 | } | 1574 | } |
| 1877 | | 1575 | |
| 1878 | if (self.code_model != .default) { | | |
| 1879 | try zig_args.append("-mcmodel"); | | |
| 1880 | try zig_args.append(@tagName(self.code_model)); | | |
| 1881 | } | | |
| 1882 | if (self.wasi_exec_model) |model| { | 1576 | if (self.wasi_exec_model) |model| { |
| 1883 | try zig_args.append(b.fmt("-mexec-model={s}", .{@tagName(model)})); | 1577 | try zig_args.append(b.fmt("-mexec-model={s}", .{@tagName(model)})); |
| 1884 | } | 1578 | } |
| 1885 | for (self.export_symbol_names) |symbol_name| { | | |
| 1886 | try zig_args.append(b.fmt("--export={s}", .{symbol_name})); | | |
| 1887 | } | | |
| 1888 | | | |
| 1889 | if (!self.target.isNative()) { | | |
| 1890 | try zig_args.appendSlice(&.{ | | |
| 1891 | "-target", try self.target.zigTriple(b.allocator), | | |
| 1892 | "-mcpu", try std.Build.serializeCpu(b.allocator, self.target.getCpu()), | | |
| 1893 | }); | | |
| 1894 | | | |
| 1895 | if (self.target.dynamic_linker.get()) |dynamic_linker| { | | |
| 1896 | try zig_args.append("--dynamic-linker"); | | |
| 1897 | try zig_args.append(dynamic_linker); | | |
| 1898 | } | | |
| 1899 | } | | |
| 1900 | | | |
| 1901 | if (self.linker_script) |linker_script| { | 1579 | if (self.linker_script) |linker_script| { |
| 1902 | try zig_args.append("--script"); | 1580 | try zig_args.append("--script"); |
| 1903 | try zig_args.append(linker_script.getPath(b)); | 1581 | try zig_args.append(linker_script.getPath(b)); |
| ... | @@ -1923,97 +1601,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1923,97 +1601,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1923 | | 1601 | |
| 1924 | try self.appendModuleArgs(&zig_args); | 1602 | try self.appendModuleArgs(&zig_args); |
| 1925 | | 1603 | |
| 1926 | for (self.include_dirs.items) |include_dir| { | | |
| 1927 | switch (include_dir) { | | |
| 1928 | .path => |include_path| { | | |
| 1929 | try zig_args.append("-I"); | | |
| 1930 | try zig_args.append(include_path.getPath(b)); | | |
| 1931 | }, | | |
| 1932 | .path_system => |include_path| { | | |
| 1933 | try zig_args.append("-isystem"); | | |
| 1934 | try zig_args.append(include_path.getPath(b)); | | |
| 1935 | }, | | |
| 1936 | .path_after => |include_path| { | | |
| 1937 | try zig_args.append("-idirafter"); | | |
| 1938 | try zig_args.append(include_path.getPath(b)); | | |
| 1939 | }, | | |
| 1940 | .framework_path => |include_path| { | | |
| 1941 | try zig_args.append("-F"); | | |
| 1942 | try zig_args.append(include_path.getPath2(b, step)); | | |
| 1943 | }, | | |
| 1944 | .framework_path_system => |include_path| { | | |
| 1945 | try zig_args.append("-iframework"); | | |
| 1946 | try zig_args.append(include_path.getPath2(b, step)); | | |
| 1947 | }, | | |
| 1948 | .other_step => |other| { | | |
| 1949 | if (other.generated_h) |header| { | | |
| 1950 | try zig_args.append("-isystem"); | | |
| 1951 | try zig_args.append(fs.path.dirname(header.path.?).?); | | |
| 1952 | } | | |
| 1953 | if (other.installed_headers.items.len > 0) { | | |
| 1954 | try zig_args.append("-I"); | | |
| 1955 | try zig_args.append(b.pathJoin(&.{ | | |
| 1956 | other.step.owner.install_prefix, "include", | | |
| 1957 | })); | | |
| 1958 | } | | |
| 1959 | }, | | |
| 1960 | .config_header_step => |config_header| { | | |
| 1961 | const full_file_path = config_header.output_file.path.?; | | |
| 1962 | const header_dir_path = full_file_path[0 .. full_file_path.len - config_header.include_path.len]; | | |
| 1963 | try zig_args.appendSlice(&.{ "-I", header_dir_path }); | | |
| 1964 | }, | | |
| 1965 | } | | |
| 1966 | } | | |
| 1967 | | | |
| 1968 | for (self.c_macros.items) |c_macro| { | | |
| 1969 | try zig_args.append("-D"); | | |
| 1970 | try zig_args.append(c_macro); | | |
| 1971 | } | | |
| 1972 | | | |
| 1973 | try zig_args.ensureUnusedCapacity(2 * self.lib_paths.items.len); | | |
| 1974 | for (self.lib_paths.items) |lib_path| { | | |
| 1975 | zig_args.appendAssumeCapacity("-L"); | | |
| 1976 | zig_args.appendAssumeCapacity(lib_path.getPath2(b, step)); | | |
| 1977 | } | | |
| 1978 | | | |
| 1979 | try zig_args.ensureUnusedCapacity(2 * self.rpaths.items.len); | | |
| 1980 | for (self.rpaths.items) |rpath| { | | |
| 1981 | zig_args.appendAssumeCapacity("-rpath"); | | |
| 1982 | | | |
| 1983 | if (self.target_info.target.isDarwin()) switch (rpath) { | | |
| 1984 | .path, .cwd_relative => |path| { | | |
| 1985 | // On Darwin, we should not try to expand special runtime paths such as | | |
| 1986 | // * @executable_path | | |
| 1987 | // * @loader_path | | |
| 1988 | if (mem.startsWith(u8, path, "@executable_path") or | | |
| 1989 | mem.startsWith(u8, path, "@loader_path")) | | |
| 1990 | { | | |
| 1991 | zig_args.appendAssumeCapacity(path); | | |
| 1992 | continue; | | |
| 1993 | } | | |
| 1994 | }, | | |
| 1995 | .generated, .dependency => {}, | | |
| 1996 | }; | | |
| 1997 | | | |
| 1998 | zig_args.appendAssumeCapacity(rpath.getPath2(b, step)); | | |
| 1999 | } | | |
| 2000 | | | |
| 2001 | { | | |
| 2002 | var it = self.frameworks.iterator(); | | |
| 2003 | while (it.next()) |entry| { | | |
| 2004 | const name = entry.key_ptr.*; | | |
| 2005 | const info = entry.value_ptr.*; | | |
| 2006 | if (info.needed) { | | |
| 2007 | try zig_args.append("-needed_framework"); | | |
| 2008 | } else if (info.weak) { | | |
| 2009 | try zig_args.append("-weak_framework"); | | |
| 2010 | } else { | | |
| 2011 | try zig_args.append("-framework"); | | |
| 2012 | } | | |
| 2013 | try zig_args.append(name); | | |
| 2014 | } | | |
| 2015 | } | | |
| 2016 | | | |
| 2017 | if (b.sysroot) |sysroot| { | 1604 | if (b.sysroot) |sysroot| { |
| 2018 | try zig_args.appendSlice(&[_][]const u8{ "--sysroot", sysroot }); | 1605 | try zig_args.appendSlice(&[_][]const u8{ "--sysroot", sysroot }); |
| 2019 | } | 1606 | } |
| ... | @@ -2058,7 +1645,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -2058,7 +1645,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 2058 | try zig_args.append(@tagName(self.rc_includes)); | 1645 | try zig_args.append(@tagName(self.rc_includes)); |
| 2059 | } | 1646 | } |
| 2060 | | 1647 | |
| 2061 | try addFlag(&zig_args, "valgrind", self.valgrind_support); | | |
| 2062 | try addFlag(&zig_args, "each-lib-rpath", self.each_lib_rpath); | 1648 | try addFlag(&zig_args, "each-lib-rpath", self.each_lib_rpath); |
| 2063 | | 1649 | |
| 2064 | if (self.build_id) |build_id| { | 1650 | if (self.build_id) |build_id| { |
| ... | @@ -2075,12 +1661,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -2075,12 +1661,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 2075 | try zig_args.append(dir.getPath(b)); | 1661 | try zig_args.append(dir.getPath(b)); |
| 2076 | } | 1662 | } |
| 2077 | | 1663 | |
| 2078 | if (self.main_mod_path) |dir| { | | |
| 2079 | try zig_args.append("--main-mod-path"); | | |
| 2080 | try zig_args.append(dir.getPath(b)); | | |
| 2081 | } | | |
| 2082 | | | |
| 2083 | try addFlag(&zig_args, "PIC", self.force_pic); | | |
| 2084 | try addFlag(&zig_args, "PIE", self.pie); | 1664 | try addFlag(&zig_args, "PIE", self.pie); |
| 2085 | try addFlag(&zig_args, "lto", self.want_lto); | 1665 | try addFlag(&zig_args, "lto", self.want_lto); |
| 2086 | | 1666 | |
| ... | @@ -2223,7 +1803,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -2223,7 +1803,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 2223 | } | 1803 | } |
| 2224 | | 1804 | |
| 2225 | if (self.kind == .lib and self.linkage != null and self.linkage.? == .dynamic and | 1805 | if (self.kind == .lib and self.linkage != null and self.linkage.? == .dynamic and |
| 2226 | self.version != null and self.target.wantSharedLibSymLinks()) | 1806 | self.version != null and self.root_module.target.wantSharedLibSymLinks()) |
| 2227 | { | 1807 | { |
| 2228 | try doAtomicSymLinks( | 1808 | try doAtomicSymLinks( |
| 2229 | step, | 1809 | step, |
| ... | @@ -2234,24 +1814,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -2234,24 +1814,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 2234 | } | 1814 | } |
| 2235 | } | 1815 | } |
| 2236 | | 1816 | |
| 2237 | fn isLibCLibrary(name: []const u8) bool { | | |
| 2238 | const libc_libraries = [_][]const u8{ "c", "m", "dl", "rt", "pthread" }; | | |
| 2239 | for (libc_libraries) |libc_lib_name| { | | |
| 2240 | if (mem.eql(u8, name, libc_lib_name)) | | |
| 2241 | return true; | | |
| 2242 | } | | |
| 2243 | return false; | | |
| 2244 | } | | |
| 2245 | | | |
| 2246 | fn isLibCppLibrary(name: []const u8) bool { | | |
| 2247 | const libcpp_libraries = [_][]const u8{ "c++", "stdc++" }; | | |
| 2248 | for (libcpp_libraries) |libcpp_lib_name| { | | |
| 2249 | if (mem.eql(u8, name, libcpp_lib_name)) | | |
| 2250 | return true; | | |
| 2251 | } | | |
| 2252 | return false; | | |
| 2253 | } | | |
| 2254 | | | |
| 2255 | /// Returned slice must be freed by the caller. | 1817 | /// Returned slice must be freed by the caller. |
| 2256 | fn findVcpkgRoot(allocator: Allocator) !?[]const u8 { | 1818 | fn findVcpkgRoot(allocator: Allocator) !?[]const u8 { |
| 2257 | const appdata_path = try fs.getAppDataDir(allocator, "vcpkg"); | 1819 | const appdata_path = try fs.getAppDataDir(allocator, "vcpkg"); |
| ... | @@ -2345,67 +1907,6 @@ fn addFlag(args: *ArrayList([]const u8), comptime name: []const u8, opt: ?bool) | ... | @@ -2345,67 +1907,6 @@ fn addFlag(args: *ArrayList([]const u8), comptime name: []const u8, opt: ?bool) |
| 2345 | } | 1907 | } |
| 2346 | } | 1908 | } |
| 2347 | | 1909 | |
| 2348 | const TransitiveDeps = struct { | | |
| 2349 | link_objects: ArrayList(LinkObject), | | |
| 2350 | seen_system_libs: StringHashMap(void), | | |
| 2351 | seen_steps: std.AutoHashMap(*const Step, void), | | |
| 2352 | is_linking_libcpp: bool, | | |
| 2353 | is_linking_libc: bool, | | |
| 2354 | frameworks: *StringHashMap(FrameworkLinkInfo), | | |
| 2355 | | | |
| 2356 | fn add(td: *TransitiveDeps, link_objects: []const LinkObject) !void { | | |
| 2357 | try td.link_objects.ensureUnusedCapacity(link_objects.len); | | |
| 2358 | | | |
| 2359 | for (link_objects) |link_object| { | | |
| 2360 | try td.link_objects.append(link_object); | | |
| 2361 | switch (link_object) { | | |
| 2362 | .other_step => |other| try addInner(td, other, other.isDynamicLibrary()), | | |
| 2363 | else => {}, | | |
| 2364 | } | | |
| 2365 | } | | |
| 2366 | } | | |
| 2367 | | | |
| 2368 | fn addInner(td: *TransitiveDeps, other: *Compile, dyn: bool) !void { | | |
| 2369 | // Inherit dependency on libc and libc++ | | |
| 2370 | td.is_linking_libcpp = td.is_linking_libcpp or other.is_linking_libcpp; | | |
| 2371 | td.is_linking_libc = td.is_linking_libc or other.is_linking_libc; | | |
| 2372 | | | |
| 2373 | // Inherit dependencies on darwin frameworks | | |
| 2374 | if (!dyn) { | | |
| 2375 | var it = other.frameworks.iterator(); | | |
| 2376 | while (it.next()) |framework| { | | |
| 2377 | try td.frameworks.put(framework.key_ptr.*, framework.value_ptr.*); | | |
| 2378 | } | | |
| 2379 | } | | |
| 2380 | | | |
| 2381 | // Inherit dependencies on system libraries and static libraries. | | |
| 2382 | for (other.link_objects.items) |other_link_object| { | | |
| 2383 | switch (other_link_object) { | | |
| 2384 | .system_lib => |system_lib| { | | |
| 2385 | if ((try td.seen_system_libs.fetchPut(system_lib.name, {})) != null) | | |
| 2386 | continue; | | |
| 2387 | | | |
| 2388 | if (dyn) | | |
| 2389 | continue; | | |
| 2390 | | | |
| 2391 | try td.link_objects.append(other_link_object); | | |
| 2392 | }, | | |
| 2393 | .other_step => |inner_other| { | | |
| 2394 | if ((try td.seen_steps.fetchPut(&inner_other.step, {})) != null) | | |
| 2395 | continue; | | |
| 2396 | | | |
| 2397 | const included_in_lib = (other.kind == .lib and inner_other.kind == .obj); | | |
| 2398 | if (!dyn and !included_in_lib) | | |
| 2399 | try td.link_objects.append(other_link_object); | | |
| 2400 | | | |
| 2401 | try addInner(td, inner_other, dyn or inner_other.isDynamicLibrary()); | | |
| 2402 | }, | | |
| 2403 | else => continue, | | |
| 2404 | } | | |
| 2405 | } | | |
| 2406 | } | | |
| 2407 | }; | | |
| 2408 | | | |
| 2409 | fn checkCompileErrors(self: *Compile) !void { | 1910 | fn checkCompileErrors(self: *Compile) !void { |
| 2410 | // Clear this field so that it does not get printed by the build runner. | 1911 | // Clear this field so that it does not get printed by the build runner. |
| 2411 | const actual_eb = self.step.result_error_bundle; | 1912 | const actual_eb = self.step.result_error_bundle; |