| ... | ... | @@ -1165,6 +1165,11 @@ pub const FileSource = union(enum) { |
| 1165 | 1165 | } |
| 1166 | 1166 | }; |
| 1167 | 1167 | |
| 1168 | const BuildOptionArtifactArg = struct { |
| 1169 | name: []const u8, |
| 1170 | artifact: *LibExeObjStep, |
| 1171 | }; |
| 1172 | |
| 1168 | 1173 | pub const LibExeObjStep = struct { |
| 1169 | 1174 | step: Step, |
| 1170 | 1175 | builder: *Builder, |
| ... | ... | @@ -1210,6 +1215,7 @@ pub const LibExeObjStep = struct { |
| 1210 | 1215 | out_pdb_filename: []const u8, |
| 1211 | 1216 | packages: ArrayList(Pkg), |
| 1212 | 1217 | build_options_contents: std.ArrayList(u8), |
| 1218 | build_options_artifact_args: std.ArrayList(BuildOptionArtifactArg), |
| 1213 | 1219 | system_linker_hack: bool = false, |
| 1214 | 1220 | |
| 1215 | 1221 | object_src: []const u8, |
| ... | ... | @@ -1355,6 +1361,7 @@ pub const LibExeObjStep = struct { |
| 1355 | 1361 | .framework_dirs = ArrayList([]const u8).init(builder.allocator), |
| 1356 | 1362 | .object_src = undefined, |
| 1357 | 1363 | .build_options_contents = std.ArrayList(u8).init(builder.allocator), |
| 1364 | .build_options_artifact_args = std.ArrayList(BuildOptionArtifactArg).init(builder.allocator), |
| 1358 | 1365 | .c_std = Builder.CStd.C99, |
| 1359 | 1366 | .override_lib_dir = null, |
| 1360 | 1367 | .main_pkg_path = null, |
| ... | ... | @@ -1812,6 +1819,13 @@ pub const LibExeObjStep = struct { |
| 1812 | 1819 | out.print("pub const {} = {};\n", .{ name, value }) catch unreachable; |
| 1813 | 1820 | } |
| 1814 | 1821 | |
| 1822 | /// The value is the path in the cache dir. |
| 1823 | /// Adds a dependency automatically. |
| 1824 | pub fn addBuildOptionArtifact(self: *LibExeObjStep, name: []const u8, artifact: *LibExeObjStep) void { |
| 1825 | self.build_options_artifact_args.append(.{ .name = name, .artifact = artifact }) catch unreachable; |
| 1826 | self.step.dependOn(&artifact.step); |
| 1827 | } |
| 1828 | |
| 1815 | 1829 | pub fn addSystemIncludeDir(self: *LibExeObjStep, path: []const u8) void { |
| 1816 | 1830 | self.include_dirs.append(IncludeDir{ .RawPathSystem = self.builder.dupe(path) }) catch unreachable; |
| 1817 | 1831 | } |
| ... | ... | @@ -1995,7 +2009,15 @@ pub const LibExeObjStep = struct { |
| 1995 | 2009 | } |
| 1996 | 2010 | } |
| 1997 | 2011 | |
| 1998 | | if (self.build_options_contents.items.len > 0) { |
| 2012 | if (self.build_options_contents.items.len > 0 or self.build_options_artifact_args.items.len > 0) { |
| 2013 | // Render build artifact options at the last minute, now that the path is known. |
| 2014 | for (self.build_options_artifact_args.items) |item| { |
| 2015 | const out = self.build_options_contents.writer(); |
| 2016 | out.print("pub const {}: []const u8 = ", .{item.name}) catch unreachable; |
| 2017 | std.zig.renderStringLiteral(item.artifact.getOutputPath(), out) catch unreachable; |
| 2018 | out.writeAll(";\n") catch unreachable; |
| 2019 | } |
| 2020 | |
| 1999 | 2021 | const build_options_file = try fs.path.join( |
| 2000 | 2022 | builder.allocator, |
| 2001 | 2023 | &[_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", .{self.name}) }, |