| ... | @@ -46,9 +46,9 @@ strip: ?bool, | ... | @@ -46,9 +46,9 @@ strip: ?bool, |
| 46 | unwind_tables: ?bool, | 46 | unwind_tables: ?bool, |
| 47 | // keep in sync with src/link.zig:CompressDebugSections | 47 | // keep in sync with src/link.zig:CompressDebugSections |
| 48 | compress_debug_sections: enum { none, zlib } = .none, | 48 | compress_debug_sections: enum { none, zlib } = .none, |
| 49 | lib_paths: ArrayList([]const u8), | 49 | lib_paths: ArrayList(FileSource), |
| 50 | rpaths: ArrayList([]const u8), | 50 | rpaths: ArrayList(FileSource), |
| 51 | framework_dirs: ArrayList([]const u8), | 51 | framework_dirs: ArrayList(FileSource), |
| 52 | frameworks: StringHashMap(FrameworkLinkInfo), | 52 | frameworks: StringHashMap(FrameworkLinkInfo), |
| 53 | verbose_link: bool, | 53 | verbose_link: bool, |
| 54 | verbose_cc: bool, | 54 | verbose_cc: bool, |
| ... | @@ -211,6 +211,7 @@ output_path_source: GeneratedFile, | ... | @@ -211,6 +211,7 @@ output_path_source: GeneratedFile, |
| 211 | output_lib_path_source: GeneratedFile, | 211 | output_lib_path_source: GeneratedFile, |
| 212 | output_h_path_source: GeneratedFile, | 212 | output_h_path_source: GeneratedFile, |
| 213 | output_pdb_path_source: GeneratedFile, | 213 | output_pdb_path_source: GeneratedFile, |
| | 214 | output_dirname_source: GeneratedFile, |
| 214 | | 215 | |
| 215 | pub const CSourceFiles = struct { | 216 | pub const CSourceFiles = struct { |
| 216 | files: []const []const u8, | 217 | files: []const []const u8, |
| ... | @@ -359,9 +360,9 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep { | ... | @@ -359,9 +360,9 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep { |
| 359 | .include_dirs = ArrayList(IncludeDir).init(owner.allocator), | 360 | .include_dirs = ArrayList(IncludeDir).init(owner.allocator), |
| 360 | .link_objects = ArrayList(LinkObject).init(owner.allocator), | 361 | .link_objects = ArrayList(LinkObject).init(owner.allocator), |
| 361 | .c_macros = ArrayList([]const u8).init(owner.allocator), | 362 | .c_macros = ArrayList([]const u8).init(owner.allocator), |
| 362 | .lib_paths = ArrayList([]const u8).init(owner.allocator), | 363 | .lib_paths = ArrayList(FileSource).init(owner.allocator), |
| 363 | .rpaths = ArrayList([]const u8).init(owner.allocator), | 364 | .rpaths = ArrayList(FileSource).init(owner.allocator), |
| 364 | .framework_dirs = ArrayList([]const u8).init(owner.allocator), | 365 | .framework_dirs = ArrayList(FileSource).init(owner.allocator), |
| 365 | .installed_headers = ArrayList(*Step).init(owner.allocator), | 366 | .installed_headers = ArrayList(*Step).init(owner.allocator), |
| 366 | .object_src = undefined, | 367 | .object_src = undefined, |
| 367 | .c_std = std.Build.CStd.C99, | 368 | .c_std = std.Build.CStd.C99, |
| ... | @@ -384,6 +385,7 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep { | ... | @@ -384,6 +385,7 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep { |
| 384 | .output_lib_path_source = GeneratedFile{ .step = &self.step }, | 385 | .output_lib_path_source = GeneratedFile{ .step = &self.step }, |
| 385 | .output_h_path_source = GeneratedFile{ .step = &self.step }, | 386 | .output_h_path_source = GeneratedFile{ .step = &self.step }, |
| 386 | .output_pdb_path_source = GeneratedFile{ .step = &self.step }, | 387 | .output_pdb_path_source = GeneratedFile{ .step = &self.step }, |
| | 388 | .output_dirname_source = GeneratedFile{ .step = &self.step }, |
| 387 | | 389 | |
| 388 | .target_info = NativeTargetInfo.detect(self.target) catch @panic("unhandled error"), | 390 | .target_info = NativeTargetInfo.detect(self.target) catch @panic("unhandled error"), |
| 389 | }; | 391 | }; |
| ... | @@ -914,13 +916,17 @@ pub fn setLibCFile(self: *CompileStep, libc_file: ?FileSource) void { | ... | @@ -914,13 +916,17 @@ pub fn setLibCFile(self: *CompileStep, libc_file: ?FileSource) void { |
| 914 | /// Returns the generated executable, library or object file. | 916 | /// Returns the generated executable, library or object file. |
| 915 | /// To run an executable built with zig build, use `run`, or create an install step and invoke it. | 917 | /// To run an executable built with zig build, use `run`, or create an install step and invoke it. |
| 916 | pub fn getOutputSource(self: *CompileStep) FileSource { | 918 | pub fn getOutputSource(self: *CompileStep) FileSource { |
| 917 | return FileSource{ .generated = &self.output_path_source }; | 919 | return .{ .generated = &self.output_path_source }; |
| | 920 | } |
| | 921 | |
| | 922 | pub fn getOutputDirectorySource(self: *CompileStep) FileSource { |
| | 923 | return .{ .generated = &self.output_dirname_source }; |
| 918 | } | 924 | } |
| 919 | | 925 | |
| 920 | /// Returns the generated import library. This function can only be called for libraries. | 926 | /// Returns the generated import library. This function can only be called for libraries. |
| 921 | pub fn getOutputLibSource(self: *CompileStep) FileSource { | 927 | pub fn getOutputLibSource(self: *CompileStep) FileSource { |
| 922 | assert(self.kind == .lib); | 928 | assert(self.kind == .lib); |
| 923 | return FileSource{ .generated = &self.output_lib_path_source }; | 929 | return .{ .generated = &self.output_lib_path_source }; |
| 924 | } | 930 | } |
| 925 | | 931 | |
| 926 | /// Returns the generated header file. | 932 | /// Returns the generated header file. |
| ... | @@ -928,14 +934,14 @@ pub fn getOutputLibSource(self: *CompileStep) FileSource { | ... | @@ -928,14 +934,14 @@ pub fn getOutputLibSource(self: *CompileStep) FileSource { |
| 928 | pub fn getOutputHSource(self: *CompileStep) FileSource { | 934 | pub fn getOutputHSource(self: *CompileStep) FileSource { |
| 929 | assert(self.kind != .exe and self.kind != .test_exe and self.kind != .@"test"); | 935 | assert(self.kind != .exe and self.kind != .test_exe and self.kind != .@"test"); |
| 930 | assert(self.emit_h); | 936 | assert(self.emit_h); |
| 931 | return FileSource{ .generated = &self.output_h_path_source }; | 937 | return .{ .generated = &self.output_h_path_source }; |
| 932 | } | 938 | } |
| 933 | | 939 | |
| 934 | /// Returns the generated PDB file. This function can only be called for Windows and UEFI. | 940 | /// Returns the generated PDB file. This function can only be called for Windows and UEFI. |
| 935 | pub fn getOutputPdbSource(self: *CompileStep) FileSource { | 941 | pub fn getOutputPdbSource(self: *CompileStep) FileSource { |
| 936 | // TODO: Is this right? Isn't PDB for *any* PE/COFF file? | 942 | // TODO: Is this right? Isn't PDB for *any* PE/COFF file? |
| 937 | assert(self.target.isWindows() or self.target.isUefi()); | 943 | assert(self.target.isWindows() or self.target.isUefi()); |
| 938 | return FileSource{ .generated = &self.output_pdb_path_source }; | 944 | return .{ .generated = &self.output_pdb_path_source }; |
| 939 | } | 945 | } |
| 940 | | 946 | |
| 941 | pub fn addAssemblyFile(self: *CompileStep, path: []const u8) void { | 947 | pub fn addAssemblyFile(self: *CompileStep, path: []const u8) void { |
| ... | @@ -989,17 +995,32 @@ pub fn addConfigHeader(self: *CompileStep, config_header: *ConfigHeaderStep) voi | ... | @@ -989,17 +995,32 @@ pub fn addConfigHeader(self: *CompileStep, config_header: *ConfigHeaderStep) voi |
| 989 | | 995 | |
| 990 | pub fn addLibraryPath(self: *CompileStep, path: []const u8) void { | 996 | pub fn addLibraryPath(self: *CompileStep, path: []const u8) void { |
| 991 | const b = self.step.owner; | 997 | const b = self.step.owner; |
| 992 | self.lib_paths.append(b.dupe(path)) catch @panic("OOM"); | 998 | self.lib_paths.append(.{ .path = b.dupe(path) }) catch @panic("OOM"); |
| | 999 | } |
| | 1000 | |
| | 1001 | pub fn addLibraryPathDirectorySource(self: *CompileStep, directory_source: FileSource) void { |
| | 1002 | self.lib_paths.append(directory_source) catch @panic("OOM"); |
| | 1003 | directory_source.addStepDependencies(&self.step); |
| 993 | } | 1004 | } |
| 994 | | 1005 | |
| 995 | pub fn addRPath(self: *CompileStep, path: []const u8) void { | 1006 | pub fn addRPath(self: *CompileStep, path: []const u8) void { |
| 996 | const b = self.step.owner; | 1007 | const b = self.step.owner; |
| 997 | self.rpaths.append(b.dupe(path)) catch @panic("OOM"); | 1008 | self.rpaths.append(.{ .path = b.dupe(path) }) catch @panic("OOM"); |
| | 1009 | } |
| | 1010 | |
| | 1011 | pub fn addRPathDirectorySource(self: *CompileStep, directory_source: FileSource) void { |
| | 1012 | self.rpaths.append(directory_source) catch @panic("OOM"); |
| | 1013 | directory_source.addStepDependencies(&self.step); |
| 998 | } | 1014 | } |
| 999 | | 1015 | |
| 1000 | pub fn addFrameworkPath(self: *CompileStep, dir_path: []const u8) void { | 1016 | pub fn addFrameworkPath(self: *CompileStep, dir_path: []const u8) void { |
| 1001 | const b = self.step.owner; | 1017 | const b = self.step.owner; |
| 1002 | self.framework_dirs.append(b.dupe(dir_path)) catch @panic("OOM"); | 1018 | self.framework_dirs.append(.{ .path = b.dupe(dir_path) }) catch @panic("OOM"); |
| | 1019 | } |
| | 1020 | |
| | 1021 | pub fn addFrameworkPathDirectorySource(self: *CompileStep, directory_source: FileSource) void { |
| | 1022 | self.framework_dirs.append(directory_source) catch @panic("OOM"); |
| | 1023 | directory_source.addStepDependencies(&self.step); |
| 1003 | } | 1024 | } |
| 1004 | | 1025 | |
| 1005 | /// Adds a module to be used with `@import` and exposing it in the current | 1026 | /// Adds a module to be used with `@import` and exposing it in the current |
| ... | @@ -1065,7 +1086,7 @@ pub fn addVcpkgPaths(self: *CompileStep, linkage: CompileStep.Linkage) !void { | ... | @@ -1065,7 +1086,7 @@ pub fn addVcpkgPaths(self: *CompileStep, linkage: CompileStep.Linkage) !void { |
| 1065 | try self.include_dirs.append(IncludeDir{ .raw_path = include_path }); | 1086 | try self.include_dirs.append(IncludeDir{ .raw_path = include_path }); |
| 1066 | | 1087 | |
| 1067 | const lib_path = b.pathJoin(&.{ root, "installed", triplet, "lib" }); | 1088 | const lib_path = b.pathJoin(&.{ root, "installed", triplet, "lib" }); |
| 1068 | try self.lib_paths.append(lib_path); | 1089 | try self.lib_paths.append(.{ .path = lib_path }); |
| 1069 | | 1090 | |
| 1070 | self.vcpkg_bin_path = b.pathJoin(&.{ root, "installed", triplet, "bin" }); | 1091 | self.vcpkg_bin_path = b.pathJoin(&.{ root, "installed", triplet, "bin" }); |
| 1071 | }, | 1092 | }, |
| ... | @@ -1768,30 +1789,32 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1768,30 +1789,32 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1768 | } | 1789 | } |
| 1769 | } | 1790 | } |
| 1770 | | 1791 | |
| 1771 | for (self.lib_paths.items) |lib_path| { | 1792 | for (self.c_macros.items) |c_macro| { |
| 1772 | try zig_args.append("-L"); | 1793 | try zig_args.append("-D"); |
| 1773 | try zig_args.append(lib_path); | 1794 | try zig_args.append(c_macro); |
| 1774 | } | 1795 | } |
| 1775 | | 1796 | |
| 1776 | for (self.rpaths.items) |rpath| { | 1797 | try zig_args.ensureUnusedCapacity(2 * self.lib_paths.items.len); |
| 1777 | try zig_args.append("-rpath"); | 1798 | for (self.lib_paths.items) |lib_path| { |
| 1778 | try zig_args.append(rpath); | 1799 | zig_args.appendAssumeCapacity("-L"); |
| | 1800 | zig_args.appendAssumeCapacity(lib_path.getPath2(b, step)); |
| 1779 | } | 1801 | } |
| 1780 | | 1802 | |
| 1781 | for (self.c_macros.items) |c_macro| { | 1803 | try zig_args.ensureUnusedCapacity(2 * self.rpaths.items.len); |
| 1782 | try zig_args.append("-D"); | 1804 | for (self.rpaths.items) |rpath| { |
| 1783 | try zig_args.append(c_macro); | 1805 | zig_args.appendAssumeCapacity("-rpath"); |
| | 1806 | zig_args.appendAssumeCapacity(rpath.getPath2(b, step)); |
| 1784 | } | 1807 | } |
| 1785 | | 1808 | |
| 1786 | for (self.framework_dirs.items) |dir| { | 1809 | for (self.framework_dirs.items) |directory_source| { |
| 1787 | if (b.sysroot != null) { | 1810 | if (b.sysroot != null) { |
| 1788 | try zig_args.append("-iframeworkwithsysroot"); | 1811 | try zig_args.append("-iframeworkwithsysroot"); |
| 1789 | } else { | 1812 | } else { |
| 1790 | try zig_args.append("-iframework"); | 1813 | try zig_args.append("-iframework"); |
| 1791 | } | 1814 | } |
| 1792 | try zig_args.append(dir); | 1815 | try zig_args.append(directory_source.getPath2(b, step)); |
| 1793 | try zig_args.append("-F"); | 1816 | try zig_args.append("-F"); |
| 1794 | try zig_args.append(dir); | 1817 | try zig_args.append(directory_source.getPath2(b, step)); |
| 1795 | } | 1818 | } |
| 1796 | | 1819 | |
| 1797 | { | 1820 | { |
| ... | @@ -1954,6 +1977,8 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1954,6 +1977,8 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1954 | | 1977 | |
| 1955 | // Update generated files | 1978 | // Update generated files |
| 1956 | if (self.output_dir != null) { | 1979 | if (self.output_dir != null) { |
| | 1980 | self.output_dirname_source.path = self.output_dir.?; |
| | 1981 | |
| 1957 | self.output_path_source.path = b.pathJoin( | 1982 | self.output_path_source.path = b.pathJoin( |
| 1958 | &.{ self.output_dir.?, self.out_filename }, | 1983 | &.{ self.output_dir.?, self.out_filename }, |
| 1959 | ); | 1984 | ); |