Skip to content

Commit c4dfa85

Browse files
committed
revert naming
1 parent 31693e8 commit c4dfa85

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
@@ -51,8 +51,8 @@ pub const LinkObject = union(enum) {
5151
other_step: *Step.Compile,
5252
system_lib: SystemLib,
5353
assembly_file: LazyPath,
54-
foreign_source_file: *ForeignSourceFile,
55-
foreign_source_files: *ForeignSourceFiles,
54+
c_source_file: *CSourceFile,
55+
c_source_files: *CSourceFiles,
5656
win32_resource_file: *RcSourceFile,
5757
};
5858

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

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

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

320-
.foreign_source_file => |x| addLazyPathDependencies(m, dependee, x.file),
307+
.c_source_file => |x| addLazyPathDependencies(m, dependee, x.file),
321308
.win32_resource_file => |x| addLazyPathDependencies(m, dependee, x.file),
322309

323-
.foreign_source_files,
310+
.c_source_files,
324311
.system_lib,
325312
=> {},
326313
};
@@ -507,14 +494,6 @@ pub fn linkFramework(m: *Module, name: []const u8, options: LinkFrameworkOptions
507494
m.frameworks.put(b.allocator, b.dupe(name), options) catch @panic("OOM");
508495
}
509496

510-
pub const AddForeignSourceFilesOptions = struct {
511-
/// When provided, `files` are relative to `root` rather than the
512-
/// package that owns the `Compile` step.
513-
root: ?LazyPath = null,
514-
files: []const []const u8,
515-
flags: []const []const u8 = &.{},
516-
language: ForeignSourceLanguage,
517-
};
518497
pub const AddCSourceFilesOptions = struct {
519498
/// When provided, `files` are relative to `root` rather than the
520499
/// package that owns the `Compile` step.
@@ -525,57 +504,39 @@ pub const AddCSourceFilesOptions = struct {
525504
};
526505

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

532511
for (options.files) |path| {
533512
if (std.fs.path.isAbsolute(path)) {
534513
std.debug.panic(
535-
"file paths added with 'addForeignSourceFiles' must be relative, found absolute path '{s}'",
514+
"file paths added with 'addCSourceFiles' must be relative, found absolute path '{s}'",
536515
.{path},
537516
);
538517
}
539518
}
540519

541-
const source_files = allocator.create(ForeignSourceFiles) catch @panic("OOM");
542-
source_files.* = .{
520+
const c_source_files = allocator.create(CSourceFiles) catch @panic("OOM");
521+
c_source_files.* = .{
543522
.root = options.root orelse b.path(""),
544523
.files = b.dupeStrings(options.files),
545524
.flags = b.dupeStrings(options.flags),
546525
.language = options.language,
547526
};
548-
m.link_objects.append(allocator, .{ .foreign_source_files = source_files }) catch @panic("OOM");
549-
addLazyPathDependenciesOnly(m, source_files.root);
527+
m.link_objects.append(allocator, .{ .c_source_files = c_source_files }) catch @panic("OOM");
528+
addLazyPathDependenciesOnly(m, c_source_files.root);
550529
}
551530

552-
/// Handy when you have many C/C++ source files and want them all to have the same flags.
553-
pub fn addCSourceFiles(m: *Module, options: AddCSourceFilesOptions) void {
554-
addForeignSourceFiles(m, .{
555-
.root = options.root,
556-
.files = options.files,
557-
.flags = options.flags,
558-
.language = options.language,
559-
});
560-
}
561-
562-
pub fn addForeignSourceFile(m: *Module, source: ForeignSourceFile) void {
531+
pub fn addCSourceFile(m: *Module, source: CSourceFile) void {
563532
const b = m.owner;
564533
const allocator = b.allocator;
565-
const source_file = allocator.create(ForeignSourceFile) catch @panic("OOM");
566-
source_file.* = source.dupe(b);
567-
m.link_objects.append(allocator, .{ .foreign_source_file = source_file }) catch @panic("OOM");
534+
const c_source_file = allocator.create(CSourceFile) catch @panic("OOM");
535+
c_source_file.* = source.dupe(b);
536+
m.link_objects.append(allocator, .{ .c_source_file = c_source_file }) catch @panic("OOM");
568537
addLazyPathDependenciesOnly(m, source.file);
569538
}
570539

571-
pub fn addCSourceFile(m: *Module, source: CSourceFile) void {
572-
addForeignSourceFile(m, .{
573-
.file = source.file,
574-
.flags = source.flags,
575-
.language = source.language,
576-
});
577-
}
578-
579540
/// Resource files must have the extension `.rc`.
580541
/// Can be called regardless of target. The .rc file will be ignored
581542
/// 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
@@ -786,17 +786,10 @@ pub fn linkFrameworkWeak(c: *Compile, name: []const u8) void {
786786
}
787787

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

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

1238-
.foreign_source_file => |foreign_source_file| l: {
1231+
.c_source_file => |c_source_file| l: {
12391232
if (!my_responsibility) break :l;
12401233

1241-
if (prev_has_cflags or foreign_source_file.flags.len != 0) {
1234+
if (prev_has_cflags or c_source_file.flags.len != 0) {
12421235
try zig_args.append("-cflags");
1243-
for (foreign_source_file.flags) |arg| {
1236+
for (c_source_file.flags) |arg| {
12441237
try zig_args.append(arg);
12451238
}
12461239
try zig_args.append("--");
12471240
}
1248-
prev_has_cflags = (foreign_source_file.flags.len != 0);
1241+
prev_has_cflags = (c_source_file.flags.len != 0);
12491242

1250-
if (foreign_source_file.language != .find_by_file_extension) {
1243+
if (c_source_file.language != .find_by_file_extension) {
12511244
try zig_args.append("-x");
1252-
try zig_args.append(switch (foreign_source_file.language) {
1245+
try zig_args.append(switch (c_source_file.language) {
12531246
.find_by_file_extension => unreachable,
12541247
.c => "c",
12551248
.cpp => "c++",
@@ -1260,30 +1253,30 @@ fn getZigArgs(compile: *Compile) ![][]const u8 {
12601253
});
12611254
}
12621255

1263-
try zig_args.append(foreign_source_file.file.getPath2(dep.module.owner, step));
1256+
try zig_args.append(c_source_file.file.getPath2(dep.module.owner, step));
12641257

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

1272-
.foreign_source_files => |foreign_source_files| l: {
1265+
.c_source_files => |c_source_files| l: {
12731266
if (!my_responsibility) break :l;
12741267

1275-
if (prev_has_cflags or foreign_source_files.flags.len != 0) {
1268+
if (prev_has_cflags or c_source_files.flags.len != 0) {
12761269
try zig_args.append("-cflags");
1277-
for (foreign_source_files.flags) |arg| {
1270+
for (c_source_files.flags) |arg| {
12781271
try zig_args.append(arg);
12791272
}
12801273
try zig_args.append("--");
12811274
}
1282-
prev_has_cflags = (foreign_source_files.flags.len != 0);
1275+
prev_has_cflags = (c_source_files.flags.len != 0);
12831276

1284-
if (foreign_source_files.language != .find_by_file_extension) {
1277+
if (c_source_files.language != .find_by_file_extension) {
12851278
try zig_args.append("-x");
1286-
try zig_args.append(switch (foreign_source_files.language) {
1279+
try zig_args.append(switch (c_source_files.language) {
12871280
.find_by_file_extension => unreachable,
12881281
.c => "c",
12891282
.cpp => "c++",
@@ -1294,17 +1287,17 @@ fn getZigArgs(compile: *Compile) ![][]const u8 {
12941287
});
12951288
}
12961289

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

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

1307-
total_linker_objects += foreign_source_files.files.len;
1300+
total_linker_objects += c_source_files.files.len;
13081301
},
13091302

13101303
.win32_resource_file => |rc_source_file| l: {
@@ -2026,7 +2019,7 @@ pub fn rootModuleTarget(c: *Compile) std.Target {
20262019

20272020
fn moduleNeedsCliArg(mod: *const Module) bool {
20282021
return for (mod.link_objects.items) |o| switch (o) {
2029-
.foreign_source_file, .foreign_source_files, .assembly_file, .win32_resource_file => break true,
2022+
.c_source_file, .c_source_files, .assembly_file, .win32_resource_file => break true,
20302023
else => continue,
20312024
} else false;
20322025
}

0 commit comments

Comments
 (0)