| ... | ... | @@ -1308,6 +1308,12 @@ const BuildOptionArtifactArg = struct { |
| 1308 | 1308 | artifact: *LibExeObjStep, |
| 1309 | 1309 | }; |
| 1310 | 1310 | |
| 1311 | const BuildOptionWriteFileArg = struct { |
| 1312 | name: []const u8, |
| 1313 | write_file: *WriteFileStep, |
| 1314 | basename: []const u8, |
| 1315 | }; |
| 1316 | |
| 1311 | 1317 | pub const LibExeObjStep = struct { |
| 1312 | 1318 | step: Step, |
| 1313 | 1319 | builder: *Builder, |
| ... | ... | @@ -1355,6 +1361,7 @@ pub const LibExeObjStep = struct { |
| 1355 | 1361 | packages: ArrayList(Pkg), |
| 1356 | 1362 | build_options_contents: std.ArrayList(u8), |
| 1357 | 1363 | build_options_artifact_args: std.ArrayList(BuildOptionArtifactArg), |
| 1364 | build_options_write_file_args: std.ArrayList(BuildOptionWriteFileArg), |
| 1358 | 1365 | |
| 1359 | 1366 | object_src: []const u8, |
| 1360 | 1367 | |
| ... | ... | @@ -1515,6 +1522,7 @@ pub const LibExeObjStep = struct { |
| 1515 | 1522 | .object_src = undefined, |
| 1516 | 1523 | .build_options_contents = std.ArrayList(u8).init(builder.allocator), |
| 1517 | 1524 | .build_options_artifact_args = std.ArrayList(BuildOptionArtifactArg).init(builder.allocator), |
| 1525 | .build_options_write_file_args = std.ArrayList(BuildOptionWriteFileArg).init(builder.allocator), |
| 1518 | 1526 | .c_std = Builder.CStd.C99, |
| 1519 | 1527 | .override_lib_dir = null, |
| 1520 | 1528 | .main_pkg_path = null, |
| ... | ... | @@ -2008,6 +2016,23 @@ pub const LibExeObjStep = struct { |
| 2008 | 2016 | self.step.dependOn(&artifact.step); |
| 2009 | 2017 | } |
| 2010 | 2018 | |
| 2019 | /// The value is the path in the cache dir. |
| 2020 | /// Adds a dependency automatically. |
| 2021 | /// basename refers to the basename of the WriteFileStep |
| 2022 | pub fn addBuildOptionWriteFile( |
| 2023 | self: *LibExeObjStep, |
| 2024 | name: []const u8, |
| 2025 | write_file: *WriteFileStep, |
| 2026 | basename: []const u8, |
| 2027 | ) void { |
| 2028 | self.build_options_write_file_args.append(.{ |
| 2029 | .name = name, |
| 2030 | .write_file = write_file, |
| 2031 | .basename = basename, |
| 2032 | }) catch unreachable; |
| 2033 | self.step.dependOn(&write_file.step); |
| 2034 | } |
| 2035 | |
| 2011 | 2036 | pub fn addSystemIncludeDir(self: *LibExeObjStep, path: []const u8) void { |
| 2012 | 2037 | self.include_dirs.append(IncludeDir{ .RawPathSystem = self.builder.dupe(path) }) catch unreachable; |
| 2013 | 2038 | } |
| ... | ... | @@ -2228,11 +2253,27 @@ pub const LibExeObjStep = struct { |
| 2228 | 2253 | } |
| 2229 | 2254 | } |
| 2230 | 2255 | |
| 2231 | | if (self.build_options_contents.items.len > 0 or self.build_options_artifact_args.items.len > 0) { |
| 2232 | | // Render build artifact options at the last minute, now that the path is known. |
| 2256 | if (self.build_options_contents.items.len > 0 or |
| 2257 | self.build_options_artifact_args.items.len > 0 or |
| 2258 | self.build_options_write_file_args.items.len > 0) |
| 2259 | { |
| 2260 | // Render build artifact and write file options at the last minute, now that the path is known. |
| 2261 | // |
| 2262 | // Note that pathFromRoot uses resolve path, so this will have |
| 2263 | // correct behavior even if getOutputPath is already absolute. |
| 2233 | 2264 | for (self.build_options_artifact_args.items) |item| { |
| 2234 | | const out = self.build_options_contents.writer(); |
| 2235 | | out.print("pub const {s}: []const u8 = \"{}\";\n", .{ item.name, std.zig.fmtEscapes(item.artifact.getOutputPath()) }) catch unreachable; |
| 2265 | self.addBuildOption( |
| 2266 | []const u8, |
| 2267 | item.name, |
| 2268 | self.builder.pathFromRoot(item.artifact.getOutputPath()), |
| 2269 | ); |
| 2270 | } |
| 2271 | for (self.build_options_write_file_args.items) |item| { |
| 2272 | self.addBuildOption( |
| 2273 | []const u8, |
| 2274 | item.name, |
| 2275 | self.builder.pathFromRoot(item.write_file.getOutputPath(item.basename)), |
| 2276 | ); |
| 2236 | 2277 | } |
| 2237 | 2278 | |
| 2238 | 2279 | const build_options_file = try fs.path.join( |