Skip to content

Commit 57ae19d

Browse files
committed
remove cImport specific output from build runner
1 parent f8a16f2 commit 57ae19d

11 files changed

Lines changed: 15 additions & 393 deletions

src/DocumentStore.zig

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,73 +1627,6 @@ fn createAndStoreDocument(
16271627
return &handle_future.handle;
16281628
}
16291629

1630-
/// returns `true` if all include paths could be collected
1631-
/// may return `false` because include paths from a build.zig may not have been resolved already
1632-
/// **Thread safe** takes a shared lock
1633-
pub fn collectIncludeDirs(
1634-
store: *DocumentStore,
1635-
allocator: std.mem.Allocator,
1636-
handle: *Handle,
1637-
include_dirs: *std.ArrayList([]const u8),
1638-
) error{ Canceled, OutOfMemory }!bool {
1639-
comptime std.debug.assert(supports_build_system);
1640-
1641-
const tracy_zone = tracy.trace(@src());
1642-
defer tracy_zone.end();
1643-
1644-
var arena_allocator: std.heap.ArenaAllocator = .init(allocator);
1645-
defer arena_allocator.deinit();
1646-
1647-
const target_info: std.Target = .{
1648-
.cpu = .{
1649-
.arch = builtin.cpu.arch,
1650-
.model = undefined,
1651-
.features = undefined,
1652-
},
1653-
.os = builtin.target.os,
1654-
.abi = .none,
1655-
.ofmt = comptime std.Target.ObjectFormat.default(builtin.os.tag, builtin.cpu.arch),
1656-
.dynamic_linker = std.Target.DynamicLinker.none,
1657-
};
1658-
const arena_allocator_allocator = arena_allocator.allocator();
1659-
const native_paths: std.zig.system.NativePaths = try .detect(arena_allocator_allocator, store.io, &target_info, store.config.environ_map);
1660-
1661-
try include_dirs.ensureUnusedCapacity(allocator, native_paths.include_dirs.items.len);
1662-
for (native_paths.include_dirs.items) |native_include_dir| {
1663-
include_dirs.appendAssumeCapacity(try allocator.dupe(u8, native_include_dir));
1664-
}
1665-
1666-
const collected_all = switch (try handle.getAssociatedBuildFile(store)) {
1667-
.none => true,
1668-
.unresolved => false,
1669-
.resolved => |resolved| collected_all: {
1670-
const build_config = resolved.build_file.tryLockConfig(store.io) orelse break :collected_all false;
1671-
defer resolved.build_file.unlockConfig(store.io);
1672-
1673-
const module = build_config.modules.map.get(resolved.root_source_file) orelse break :collected_all true;
1674-
1675-
try include_dirs.ensureUnusedCapacity(allocator, module.include_dirs.len);
1676-
for (module.include_dirs) |include_path| {
1677-
const absolute_path = if (std.Io.Dir.path.isAbsolute(include_path))
1678-
try allocator.dupe(u8, include_path)
1679-
else blk: {
1680-
const build_file_path = resolved.build_file.uri.toFsPath(allocator) catch |err| switch (err) {
1681-
error.OutOfMemory => return error.OutOfMemory,
1682-
error.UnsupportedScheme => continue,
1683-
};
1684-
const build_file_dirname = std.Io.Dir.path.dirname(build_file_path) orelse continue;
1685-
break :blk try std.Io.Dir.path.join(allocator, &.{ build_file_dirname, include_path });
1686-
};
1687-
1688-
include_dirs.appendAssumeCapacity(absolute_path);
1689-
}
1690-
break :collected_all true;
1691-
},
1692-
};
1693-
1694-
return collected_all;
1695-
}
1696-
16971630
pub const UriFromImportStringResult = union(enum) {
16981631
none,
16991632
one: Uri,

src/build_runner/build_runner.zig

Lines changed: 3 additions & 262 deletions
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,6 @@ fn createModuleDependenciesForStep(step: *Step) Allocator.Error!void {
981981
//
982982

983983
const shared = @import("shared.zig");
984-
const Transport = shared.Transport;
985984
const BuildConfig = shared.BuildConfig;
986985

987986
fn extractBuildInformation(
@@ -997,105 +996,28 @@ fn extractBuildInformation(
997996
.generated => |gen| try set.put(allocator, gen.file.step, {}),
998997
}
999998
}
1000-
fn addIncludeDirStepDependencies(allocator: Allocator, set: *std.array_hash_map.Auto(*Step, void), include_dir: std.Build.Module.IncludeDir) !void {
1001-
switch (include_dir) {
1002-
.path,
1003-
.path_system,
1004-
.path_after,
1005-
.framework_path,
1006-
.framework_path_system,
1007-
=> |lazy_path| try addLazyPathStepDependencies(allocator, set, lazy_path),
1008-
.other_step => |other| {
1009-
if (other.generated_h) |header| {
1010-
try set.put(allocator, header.step, {});
1011-
}
1012-
if (other.installed_headers_include_tree) |include_tree| {
1013-
try set.put(allocator, include_tree.generated_directory.step, {});
1014-
}
1015-
},
1016-
.embed_path => {
1017-
// This only affects C source files
1018-
},
1019-
.config_header_step => |config_header| try set.put(allocator, &config_header.step, {}),
1020-
}
1021-
}
1022-
/// Only adds the necessary dependencies to resolve the `root_source_file` and `include_dirs`. Does not include dependencies of imported modules.
999+
/// Only adds the necessary dependencies to resolve the `root_source_file`. Does not include dependencies of imported modules.
10231000
fn addModuleDependencies(allocator: Allocator, set: *std.array_hash_map.Auto(*Step, void), module: *std.Build.Module) !void {
10241001
if (module.root_source_file) |root_source_file| {
10251002
try addLazyPathStepDependencies(allocator, set, root_source_file);
10261003
}
1027-
1028-
for (module.include_dirs.items) |include_dir| {
1029-
try addIncludeDirStepDependencies(allocator, set, include_dir);
1030-
}
10311004
}
10321005
fn processModule(
10331006
allocator: Allocator,
1034-
modules: *std.array_hash_map.String(shared.BuildConfig.Module),
1007+
modules: *std.array_hash_map.String(BuildConfig.Module),
10351008
module: *std.Build.Module,
10361009
compile: ?*Step.Compile,
10371010
) !void {
1011+
_ = compile;
10381012
const root_source_file = module.root_source_file orelse return;
10391013

1040-
var include_dirs: std.array_hash_map.String(void) = .empty;
1041-
var c_macros: std.array_hash_map.String(void) = .empty;
1042-
1043-
if (compile) |exe| {
1044-
try processPkgConfig(allocator, &include_dirs, &c_macros, exe);
1045-
}
1046-
1047-
try c_macros.ensureUnusedCapacity(allocator, module.c_macros.items.len);
1048-
for (module.c_macros.items) |c_macro| {
1049-
c_macros.putAssumeCapacity(c_macro, {});
1050-
}
1051-
1052-
for (module.include_dirs.items) |include_dir| {
1053-
switch (include_dir) {
1054-
.path,
1055-
.path_system,
1056-
.path_after,
1057-
.framework_path,
1058-
.framework_path_system,
1059-
=> |include_path| try include_dirs.put(allocator, include_path.getPath(module.owner), {}),
1060-
1061-
.other_step => |other| {
1062-
if (other.generated_h) |header| {
1063-
try include_dirs.put(
1064-
allocator,
1065-
std.Io.Dir.path.dirname(header.getPath()).?,
1066-
{},
1067-
);
1068-
}
1069-
if (other.installed_headers_include_tree) |include_tree| {
1070-
try include_dirs.put(
1071-
allocator,
1072-
include_tree.generated_directory.getPath(),
1073-
{},
1074-
);
1075-
}
1076-
},
1077-
.embed_path => {
1078-
// This only affects C source files
1079-
},
1080-
.config_header_step => |config_header| {
1081-
try include_dirs.put(
1082-
allocator,
1083-
config_header.generated_dir.getPath(),
1084-
{},
1085-
);
1086-
},
1087-
}
1088-
}
1089-
10901014
const cwd = module.owner.graph.cache.cwd;
10911015

10921016
const root_source_file_path = try std.Io.Dir.path.resolve(allocator, &.{ cwd, root_source_file.getPath2(module.owner, null) });
10931017

10941018
// All modules with the same root source file are merged. This limitation may be lifted in the future.
10951019
const gop = try modules.getOrPutValue(allocator, root_source_file_path, .{
10961020
.import_table = .{},
1097-
.c_macros = &.{},
1098-
.include_dirs = &.{},
10991021
});
11001022

11011023
for (module.import_table.keys(), module.import_table.values()) |name, import| {
@@ -1106,8 +1028,6 @@ fn extractBuildInformation(
11061028
gop_import.value_ptr.* = try std.Io.Dir.path.resolve(allocator, &.{ cwd, import_root_source_file.getPath2(import.owner, null) });
11071029
}
11081030
}
1109-
gop.value_ptr.c_macros = try std.mem.concat(allocator, []const u8, &.{ gop.value_ptr.c_macros, c_macros.keys() });
1110-
gop.value_ptr.include_dirs = try std.mem.concat(allocator, []const u8, &.{ gop.value_ptr.include_dirs, include_dirs.keys() });
11111031
}
11121032
};
11131033
const gpa = run.gpa;
@@ -1280,185 +1200,6 @@ fn extractBuildInformation(
12801200
file_writer.interface.writeAll(stringified_build_config) catch return file_writer.err.?;
12811201
}
12821202

1283-
fn processPkgConfig(
1284-
allocator: Allocator,
1285-
include_dirs: *std.array_hash_map.String(void),
1286-
c_macros: *std.array_hash_map.String(void),
1287-
exe: *Step.Compile,
1288-
) !void {
1289-
for (exe.root_module.link_objects.items) |link_object| {
1290-
if (link_object != .system_lib) continue;
1291-
const system_lib = link_object.system_lib;
1292-
1293-
if (system_lib.use_pkg_config == .no) continue;
1294-
1295-
const args = copied_from_zig.runPkgConfig(exe, system_lib.name) catch |err| switch (err) {
1296-
error.PkgConfigInvalidOutput,
1297-
error.PkgConfigCrashed,
1298-
error.PkgConfigFailed,
1299-
error.PkgConfigNotInstalled,
1300-
error.PackageNotFound,
1301-
=> switch (system_lib.use_pkg_config) {
1302-
.yes => {
1303-
// pkg-config failed, so zig will not add any include paths
1304-
continue;
1305-
},
1306-
.force => {
1307-
std.log.warn("pkg-config failed for library {s}", .{system_lib.name});
1308-
continue;
1309-
},
1310-
.no => unreachable,
1311-
},
1312-
else => |e| return e,
1313-
};
1314-
for (args) |arg| {
1315-
if (std.mem.startsWith(u8, arg, "-I")) {
1316-
const candidate = arg[2..];
1317-
try include_dirs.put(allocator, candidate, {});
1318-
} else if (std.mem.startsWith(u8, arg, "-D")) {
1319-
try c_macros.put(allocator, arg, {});
1320-
}
1321-
}
1322-
}
1323-
}
1324-
1325-
const copied_from_zig = struct {
1326-
/// Run pkg-config for the given library name and parse the output, returning the arguments
1327-
/// that should be passed to zig to link the given library.
1328-
fn runPkgConfig(self: *Step.Compile, lib_name: []const u8) ![]const []const u8 {
1329-
const b = self.step.owner;
1330-
const pkg_name = match: {
1331-
// First we have to map the library name to pkg config name. Unfortunately,
1332-
// there are several examples where this is not straightforward:
1333-
// -lSDL2 -> pkg-config sdl2
1334-
// -lgdk-3 -> pkg-config gdk-3.0
1335-
// -latk-1.0 -> pkg-config atk
1336-
const pkgs = try getPkgConfigList(b);
1337-
1338-
// Exact match means instant winner.
1339-
for (pkgs) |pkg| {
1340-
if (mem.eql(u8, pkg.name, lib_name)) {
1341-
break :match pkg.name;
1342-
}
1343-
}
1344-
1345-
// Next we'll try ignoring case.
1346-
for (pkgs) |pkg| {
1347-
if (std.ascii.eqlIgnoreCase(pkg.name, lib_name)) {
1348-
break :match pkg.name;
1349-
}
1350-
}
1351-
1352-
// Now try appending ".0".
1353-
for (pkgs) |pkg| {
1354-
if (std.ascii.findIgnoreCase(pkg.name, lib_name)) |pos| {
1355-
if (pos != 0) continue;
1356-
if (mem.eql(u8, pkg.name[lib_name.len..], ".0")) {
1357-
break :match pkg.name;
1358-
}
1359-
}
1360-
}
1361-
1362-
// Trimming "-1.0".
1363-
if (mem.endsWith(u8, lib_name, "-1.0")) {
1364-
const trimmed_lib_name = lib_name[0 .. lib_name.len - "-1.0".len];
1365-
for (pkgs) |pkg| {
1366-
if (std.ascii.eqlIgnoreCase(pkg.name, trimmed_lib_name)) {
1367-
break :match pkg.name;
1368-
}
1369-
}
1370-
}
1371-
1372-
return error.PackageNotFound;
1373-
};
1374-
1375-
var code: u8 = undefined;
1376-
const stdout = if (b.runAllowFail(&.{
1377-
"pkg-config",
1378-
pkg_name,
1379-
"--cflags",
1380-
"--libs",
1381-
}, &code, .ignore)) |stdout| stdout else |err| switch (err) {
1382-
error.ProcessTerminated => return error.PkgConfigCrashed,
1383-
error.ExecNotSupported => return error.PkgConfigFailed,
1384-
error.ExitCodeFailure => return error.PkgConfigFailed,
1385-
error.FileNotFound => return error.PkgConfigNotInstalled,
1386-
else => return err,
1387-
};
1388-
1389-
var zig_args = std.array_list.Managed([]const u8).init(b.allocator);
1390-
defer zig_args.deinit();
1391-
1392-
var it = mem.tokenizeAny(u8, stdout, " \r\n\t");
1393-
while (it.next()) |tok| {
1394-
if (mem.eql(u8, tok, "-I")) {
1395-
const dir = it.next() orelse return error.PkgConfigInvalidOutput;
1396-
try zig_args.appendSlice(&.{ "-I", dir });
1397-
} else if (mem.startsWith(u8, tok, "-I")) {
1398-
try zig_args.append(tok);
1399-
} else if (mem.eql(u8, tok, "-L")) {
1400-
const dir = it.next() orelse return error.PkgConfigInvalidOutput;
1401-
try zig_args.appendSlice(&.{ "-L", dir });
1402-
} else if (mem.startsWith(u8, tok, "-L")) {
1403-
try zig_args.append(tok);
1404-
} else if (mem.eql(u8, tok, "-l")) {
1405-
const lib = it.next() orelse return error.PkgConfigInvalidOutput;
1406-
try zig_args.appendSlice(&.{ "-l", lib });
1407-
} else if (mem.startsWith(u8, tok, "-l")) {
1408-
try zig_args.append(tok);
1409-
} else if (mem.eql(u8, tok, "-D")) {
1410-
const macro = it.next() orelse return error.PkgConfigInvalidOutput;
1411-
try zig_args.appendSlice(&.{ "-D", macro });
1412-
} else if (mem.startsWith(u8, tok, "-D")) {
1413-
try zig_args.append(tok);
1414-
} else if (b.debug_pkg_config) {
1415-
return self.step.fail("unknown pkg-config flag '{s}'", .{tok});
1416-
}
1417-
}
1418-
1419-
return zig_args.toOwnedSlice();
1420-
}
1421-
1422-
fn execPkgConfigList(self: *std.Build, out_code: *u8) (std.Build.PkgConfigError || std.Build.RunError)![]const std.Build.PkgConfigPkg {
1423-
const stdout = try self.runAllowFail(&.{ "pkg-config", "--list-all" }, out_code, .ignore);
1424-
var list = std.array_list.Managed(std.Build.PkgConfigPkg).init(self.allocator);
1425-
errdefer list.deinit();
1426-
var line_it = mem.tokenizeAny(u8, stdout, "\r\n");
1427-
while (line_it.next()) |line| {
1428-
if (mem.trim(u8, line, " \t").len == 0) continue;
1429-
var tok_it = mem.tokenizeAny(u8, line, " \t");
1430-
try list.append(.{
1431-
.name = tok_it.next() orelse return error.PkgConfigInvalidOutput,
1432-
.desc = tok_it.rest(),
1433-
});
1434-
}
1435-
return list.toOwnedSlice();
1436-
}
1437-
1438-
fn getPkgConfigList(self: *std.Build) ![]const std.Build.PkgConfigPkg {
1439-
if (self.pkg_config_pkg_list) |res| {
1440-
return res;
1441-
}
1442-
var code: u8 = undefined;
1443-
if (execPkgConfigList(self, &code)) |list| {
1444-
self.pkg_config_pkg_list = list;
1445-
return list;
1446-
} else |err| {
1447-
const result = switch (err) {
1448-
error.ProcessTerminated => error.PkgConfigCrashed,
1449-
error.ExecNotSupported => error.PkgConfigFailed,
1450-
error.ExitCodeFailure => error.PkgConfigFailed,
1451-
error.FileNotFound => error.PkgConfigNotInstalled,
1452-
error.InvalidName => error.PkgConfigNotInstalled,
1453-
error.PkgConfigInvalidOutput => error.PkgConfigInvalidOutput,
1454-
else => return err,
1455-
};
1456-
self.pkg_config_pkg_list = result;
1457-
return result;
1458-
}
1459-
}
1460-
};
1461-
14621203
fn serveWatchErrorBundle(
14631204
io: std.Io,
14641205
step_id: u32,

src/build_runner/shared.zig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ pub const BuildConfig = struct {
1717

1818
pub const Module = struct {
1919
import_table: std.json.ArrayHashMap([]const u8),
20-
c_macros: []const []const u8,
21-
include_dirs: []const []const u8,
2220
};
2321

2422
pub const Compile = struct {

0 commit comments

Comments
 (0)