Skip to content

Commit f73ed36

Browse files
committed
revert naming
1 parent bf314e4 commit f73ed36

File tree

2 files changed

+34
-80
lines changed

2 files changed

+34
-80
lines changed

lib/std/Build/Module.zig

Lines changed: 15 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ pub const LinkObject = union(enum) {
5050
other_step: *Step.Compile,
5151
system_lib: SystemLib,
5252
assembly_file: LazyPath,
53-
foreign_source_file: *ForeignSourceFile,
54-
foreign_source_files: *ForeignSourceFiles,
53+
c_source_file: *CSourceFile,
54+
c_source_files: *CSourceFiles,
5555
win32_resource_file: *RcSourceFile,
5656
};
5757

@@ -88,7 +88,7 @@ pub const ForeignSourceLanguage = enum {
8888
find_by_file_extension,
8989
};
9090

91-
pub const ForeignSourceFiles = struct {
91+
pub const CSourceFiles = struct {
9292
root: LazyPath,
9393
/// `files` is relative to `root`, which is
9494
/// the build root by default
@@ -97,19 +97,6 @@ pub const ForeignSourceFiles = struct {
9797
language: ForeignSourceLanguage,
9898
};
9999

100-
pub const ForeignSourceFile = struct {
101-
file: LazyPath,
102-
flags: []const []const u8 = &.{},
103-
language: ForeignSourceLanguage,
104-
105-
pub fn dupe(file: ForeignSourceFile, b: *std.Build) ForeignSourceFile {
106-
return .{
107-
.file = file.file.dupe(b),
108-
.flags = b.dupeStrings(file.flags),
109-
.language = file.language,
110-
};
111-
}
112-
};
113100
pub const CSourceFile = struct {
114101
file: LazyPath,
115102
flags: []const []const u8 = &.{},
@@ -314,10 +301,10 @@ fn addShallowDependencies(m: *Module, dependee: *Module) void {
314301
.assembly_file,
315302
=> |lp| addLazyPathDependencies(m, dependee, lp),
316303

317-
.foreign_source_file => |x| addLazyPathDependencies(m, dependee, x.file),
304+
.c_source_file => |x| addLazyPathDependencies(m, dependee, x.file),
318305
.win32_resource_file => |x| addLazyPathDependencies(m, dependee, x.file),
319306

320-
.foreign_source_files,
307+
.c_source_files,
321308
.system_lib,
322309
=> {},
323310
};
@@ -504,14 +491,6 @@ pub fn linkFramework(m: *Module, name: []const u8, options: LinkFrameworkOptions
504491
m.frameworks.put(b.allocator, b.dupe(name), options) catch @panic("OOM");
505492
}
506493

507-
pub const AddForeignSourceFilesOptions = struct {
508-
/// When provided, `files` are relative to `root` rather than the
509-
/// package that owns the `Compile` step.
510-
root: ?LazyPath = null,
511-
files: []const []const u8,
512-
flags: []const []const u8 = &.{},
513-
language: ForeignSourceLanguage,
514-
};
515494
pub const AddCSourceFilesOptions = struct {
516495
/// When provided, `files` are relative to `root` rather than the
517496
/// package that owns the `Compile` step.
@@ -522,57 +501,39 @@ pub const AddCSourceFilesOptions = struct {
522501
};
523502

524503
/// Handy when you have many non-Zig source files and want them all to have the same flags.
525-
pub fn addForeignSourceFiles(m: *Module, options: AddForeignSourceFilesOptions) void {
504+
pub fn addCSourceFiles(m: *Module, options: AddCSourceFilesOptions) void {
526505
const b = m.owner;
527506
const allocator = b.allocator;
528507

529508
for (options.files) |path| {
530509
if (std.fs.path.isAbsolute(path)) {
531510
std.debug.panic(
532-
"file paths added with 'addForeignSourceFiles' must be relative, found absolute path '{s}'",
511+
"file paths added with 'addCSourceFiles' must be relative, found absolute path '{s}'",
533512
.{path},
534513
);
535514
}
536515
}
537516

538-
const source_files = allocator.create(ForeignSourceFiles) catch @panic("OOM");
539-
source_files.* = .{
517+
const c_source_files = allocator.create(CSourceFiles) catch @panic("OOM");
518+
c_source_files.* = .{
540519
.root = options.root orelse b.path(""),
541520
.files = b.dupeStrings(options.files),
542521
.flags = b.dupeStrings(options.flags),
543522
.language = options.language,
544523
};
545-
m.link_objects.append(allocator, .{ .foreign_source_files = source_files }) catch @panic("OOM");
546-
addLazyPathDependenciesOnly(m, source_files.root);
524+
m.link_objects.append(allocator, .{ .c_source_files = c_source_files }) catch @panic("OOM");
525+
addLazyPathDependenciesOnly(m, c_source_files.root);
547526
}
548527

549-
/// Handy when you have many C/C++ source files and want them all to have the same flags.
550-
pub fn addCSourceFiles(m: *Module, options: AddCSourceFilesOptions) void {
551-
addForeignSourceFiles(m, .{
552-
.root = options.root,
553-
.files = options.files,
554-
.flags = options.flags,
555-
.language = options.language,
556-
});
557-
}
558-
559-
pub fn addForeignSourceFile(m: *Module, source: ForeignSourceFile) void {
528+
pub fn addCSourceFile(m: *Module, source: CSourceFile) void {
560529
const b = m.owner;
561530
const allocator = b.allocator;
562-
const source_file = allocator.create(ForeignSourceFile) catch @panic("OOM");
563-
source_file.* = source.dupe(b);
564-
m.link_objects.append(allocator, .{ .foreign_source_file = source_file }) catch @panic("OOM");
531+
const c_source_file = allocator.create(CSourceFile) catch @panic("OOM");
532+
c_source_file.* = source.dupe(b);
533+
m.link_objects.append(allocator, .{ .c_source_file = c_source_file }) catch @panic("OOM");
565534
addLazyPathDependenciesOnly(m, source.file);
566535
}
567536

568-
pub fn addCSourceFile(m: *Module, source: CSourceFile) void {
569-
addForeignSourceFile(m, .{
570-
.file = source.file,
571-
.flags = source.flags,
572-
.language = source.language,
573-
});
574-
}
575-
576537
/// Resource files must have the extension `.rc`.
577538
/// Can be called regardless of target. The .rc file will be ignored
578539
/// if the target object format does not support embedded resources.

lib/std/Build/Step/Compile.zig

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -785,17 +785,10 @@ pub fn linkFrameworkWeak(c: *Compile, name: []const u8) void {
785785
}
786786

787787
/// Handy when you have many non-Zig source files and want them all to have the same flags.
788-
pub fn addForeignSourceFiles(compile: *Compile, options: Module.AddForeignSourceFilesOptions) void {
789-
compile.root_module.addForeignSourceFiles(options);
790-
}
791-
/// Handy when you have many C/C++ source files and want them all to have the same flags.
792788
pub fn addCSourceFiles(compile: *Compile, options: Module.AddCSourceFilesOptions) void {
793789
compile.root_module.addCSourceFiles(options);
794790
}
795791

796-
pub fn addForeignSourceFile(compile: *Compile, source: Module.ForeignSourceFile) void {
797-
compile.root_module.addForeignSourceFile(source);
798-
}
799792
pub fn addCSourceFile(compile: *Compile, source: Module.CSourceFile) void {
800793
compile.root_module.addCSourceFile(source);
801794
}
@@ -1234,21 +1227,21 @@ fn getZigArgs(compile: *Compile) ![][]const u8 {
12341227
total_linker_objects += 1;
12351228
},
12361229

1237-
.foreign_source_file => |foreign_source_file| l: {
1230+
.c_source_file => |c_source_file| l: {
12381231
if (!my_responsibility) break :l;
12391232

1240-
if (prev_has_cflags or foreign_source_file.flags.len != 0) {
1233+
if (prev_has_cflags or c_source_file.flags.len != 0) {
12411234
try zig_args.append("-cflags");
1242-
for (foreign_source_file.flags) |arg| {
1235+
for (c_source_file.flags) |arg| {
12431236
try zig_args.append(arg);
12441237
}
12451238
try zig_args.append("--");
12461239
}
1247-
prev_has_cflags = (foreign_source_file.flags.len != 0);
1240+
prev_has_cflags = (c_source_file.flags.len != 0);
12481241

1249-
if (foreign_source_file.language != .find_by_file_extension) {
1242+
if (c_source_file.language != .find_by_file_extension) {
12501243
try zig_args.append("-x");
1251-
try zig_args.append(switch (foreign_source_file.language) {
1244+
try zig_args.append(switch (c_source_file.language) {
12521245
.find_by_file_extension => unreachable,
12531246
.c => "c",
12541247
.cpp => "c++",
@@ -1259,30 +1252,30 @@ fn getZigArgs(compile: *Compile) ![][]const u8 {
12591252
});
12601253
}
12611254

1262-
try zig_args.append(foreign_source_file.file.getPath2(dep.module.owner, step));
1255+
try zig_args.append(c_source_file.file.getPath2(dep.module.owner, step));
12631256

1264-
if (foreign_source_file.language != .find_by_file_extension) {
1257+
if (c_source_file.language != .find_by_file_extension) {
12651258
try zig_args.append("-x");
12661259
try zig_args.append("none");
12671260
}
12681261
total_linker_objects += 1;
12691262
},
12701263

1271-
.foreign_source_files => |foreign_source_files| l: {
1264+
.c_source_files => |c_source_files| l: {
12721265
if (!my_responsibility) break :l;
12731266

1274-
if (prev_has_cflags or foreign_source_files.flags.len != 0) {
1267+
if (prev_has_cflags or c_source_files.flags.len != 0) {
12751268
try zig_args.append("-cflags");
1276-
for (foreign_source_files.flags) |arg| {
1269+
for (c_source_files.flags) |arg| {
12771270
try zig_args.append(arg);
12781271
}
12791272
try zig_args.append("--");
12801273
}
1281-
prev_has_cflags = (foreign_source_files.flags.len != 0);
1274+
prev_has_cflags = (c_source_files.flags.len != 0);
12821275

1283-
if (foreign_source_files.language != .find_by_file_extension) {
1276+
if (c_source_files.language != .find_by_file_extension) {
12841277
try zig_args.append("-x");
1285-
try zig_args.append(switch (foreign_source_files.language) {
1278+
try zig_args.append(switch (c_source_files.language) {
12861279
.find_by_file_extension => unreachable,
12871280
.c => "c",
12881281
.cpp => "c++",
@@ -1293,17 +1286,17 @@ fn getZigArgs(compile: *Compile) ![][]const u8 {
12931286
});
12941287
}
12951288

1296-
const root_path = foreign_source_files.root.getPath2(dep.module.owner, step);
1297-
for (foreign_source_files.files) |file| {
1289+
const root_path = c_source_files.root.getPath2(dep.module.owner, step);
1290+
for (c_source_files.files) |file| {
12981291
try zig_args.append(b.pathJoin(&.{ root_path, file }));
12991292
}
13001293

1301-
if (foreign_source_files.language != .find_by_file_extension) {
1294+
if (c_source_files.language != .find_by_file_extension) {
13021295
try zig_args.append("-x");
13031296
try zig_args.append("none");
13041297
}
13051298

1306-
total_linker_objects += foreign_source_files.files.len;
1299+
total_linker_objects += c_source_files.files.len;
13071300
},
13081301

13091302
.win32_resource_file => |rc_source_file| l: {
@@ -2024,7 +2017,7 @@ pub fn rootModuleTarget(c: *Compile) std.Target {
20242017

20252018
fn moduleNeedsCliArg(mod: *const Module) bool {
20262019
return for (mod.link_objects.items) |o| switch (o) {
2027-
.foreign_source_file, .foreign_source_files, .assembly_file, .win32_resource_file => break true,
2020+
.c_source_file, .c_source_files, .assembly_file, .win32_resource_file => break true,
20282021
else => continue,
20292022
} else false;
20302023
}

0 commit comments

Comments
 (0)