Skip to content

Commit a51cdf3

Browse files
authored
Merge pull request #22587 from castholm/deprecate-compile-apis
std.Build: Deprecate `Step.Compile` APIs that mutate the root module
2 parents c9ce1de + 154bd2f commit a51cdf3

File tree

15 files changed

+569
-521
lines changed

15 files changed

+569
-521
lines changed

doc/langref/build.zig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ pub fn build(b: *std.Build) void {
44
const optimize = b.standardOptimizeOption(.{});
55
const exe = b.addExecutable(.{
66
.name = "example",
7-
.root_source_file = b.path("example.zig"),
8-
.optimize = optimize,
7+
.root_module = b.createModule(.{
8+
.root_source_file = b.path("example.zig"),
9+
.optimize = optimize,
10+
}),
911
});
1012
b.default_step.dependOn(&exe.step);
1113
}

doc/langref/build_c.zig

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@ pub fn build(b: *std.Build) void {
44
const lib = b.addLibrary(.{
55
.linkage = .dynamic,
66
.name = "mathtest",
7-
.root_source_file = b.path("mathtest.zig"),
7+
.root_module = b.createModule(.{
8+
.root_source_file = b.path("mathtest.zig"),
9+
}),
810
.version = .{ .major = 1, .minor = 0, .patch = 0 },
911
});
1012
const exe = b.addExecutable(.{
1113
.name = "test",
14+
.root_module = b.createModule(.{
15+
.link_libc = true,
16+
}),
1217
});
13-
exe.addCSourceFile(.{ .file = b.path("test.c"), .flags = &.{"-std=c99"} });
14-
exe.linkLibrary(lib);
15-
exe.linkSystemLibrary("c");
18+
exe.root_module.addCSourceFile(.{ .file = b.path("test.c"), .flags = &.{"-std=c99"} });
19+
exe.root_module.linkLibrary(lib);
1620

1721
b.default_step.dependOn(&exe.step);
1822

doc/langref/build_object.zig

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@ const std = @import("std");
33
pub fn build(b: *std.Build) void {
44
const obj = b.addObject(.{
55
.name = "base64",
6-
.root_source_file = b.path("base64.zig"),
6+
.root_module = b.createModule(.{
7+
.root_source_file = b.path("base64.zig"),
8+
}),
79
});
810

911
const exe = b.addExecutable(.{
1012
.name = "test",
13+
.root_module = b.createModule(.{
14+
.link_libc = true,
15+
}),
1116
});
12-
exe.addCSourceFile(.{ .file = b.path("test.c"), .flags = &.{"-std=c99"} });
13-
exe.addObject(obj);
14-
exe.linkSystemLibrary("c");
17+
exe.root_module.addCSourceFile(.{ .file = b.path("test.c"), .flags = &.{"-std=c99"} });
18+
exe.root_module.addObject(obj);
1519
b.installArtifact(exe);
1620
}
1721

lib/std/Build/Step/Compile.zig

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -681,10 +681,14 @@ pub fn producesImplib(compile: *Compile) bool {
681681
return compile.isDll();
682682
}
683683

684+
/// Deprecated; use `compile.root_module.link_libc = true` instead.
685+
/// To be removed after 0.15.0 is tagged.
684686
pub fn linkLibC(compile: *Compile) void {
685687
compile.root_module.link_libc = true;
686688
}
687689

690+
/// Deprecated; use `compile.root_module.link_libcpp = true` instead.
691+
/// To be removed after 0.15.0 is tagged.
688692
pub fn linkLibCpp(compile: *Compile) void {
689693
compile.root_module.link_libcpp = true;
690694
}
@@ -802,10 +806,14 @@ fn runPkgConfig(compile: *Compile, lib_name: []const u8) !PkgConfigResult {
802806
};
803807
}
804808

809+
/// Deprecated; use `compile.root_module.linkSystemLibrary(name, .{})` instead.
810+
/// To be removed after 0.15.0 is tagged.
805811
pub fn linkSystemLibrary(compile: *Compile, name: []const u8) void {
806812
return compile.root_module.linkSystemLibrary(name, .{});
807813
}
808814

815+
/// Deprecated; use `compile.root_module.linkSystemLibrary(name, options)` instead.
816+
/// To be removed after 0.15.0 is tagged.
809817
pub fn linkSystemLibrary2(
810818
compile: *Compile,
811819
name: []const u8,
@@ -814,22 +822,26 @@ pub fn linkSystemLibrary2(
814822
return compile.root_module.linkSystemLibrary(name, options);
815823
}
816824

825+
/// Deprecated; use `c.root_module.linkFramework(name, .{})` instead.
826+
/// To be removed after 0.15.0 is tagged.
817827
pub fn linkFramework(c: *Compile, name: []const u8) void {
818828
c.root_module.linkFramework(name, .{});
819829
}
820830

821-
/// Handy when you have many C/C++ source files and want them all to have the same flags.
831+
/// Deprecated; use `compile.root_module.addCSourceFiles(options)` instead.
832+
/// To be removed after 0.15.0 is tagged.
822833
pub fn addCSourceFiles(compile: *Compile, options: Module.AddCSourceFilesOptions) void {
823834
compile.root_module.addCSourceFiles(options);
824835
}
825836

837+
/// Deprecated; use `compile.root_module.addCSourceFile(source)` instead.
838+
/// To be removed after 0.15.0 is tagged.
826839
pub fn addCSourceFile(compile: *Compile, source: Module.CSourceFile) void {
827840
compile.root_module.addCSourceFile(source);
828841
}
829842

830-
/// Resource files must have the extension `.rc`.
831-
/// Can be called regardless of target. The .rc file will be ignored
832-
/// if the target object format does not support embedded resources.
843+
/// Deprecated; use `compile.root_module.addWin32ResourceFile(source)` instead.
844+
/// To be removed after 0.15.0 is tagged.
833845
pub fn addWin32ResourceFile(compile: *Compile, source: Module.RcSourceFile) void {
834846
compile.root_module.addWin32ResourceFile(source);
835847
}
@@ -915,54 +927,80 @@ pub fn getEmittedLlvmBc(compile: *Compile) LazyPath {
915927
return compile.getEmittedFileGeneric(&compile.generated_llvm_bc);
916928
}
917929

930+
/// Deprecated; use `compile.root_module.addAssemblyFile(source)` instead.
931+
/// To be removed after 0.15.0 is tagged.
918932
pub fn addAssemblyFile(compile: *Compile, source: LazyPath) void {
919933
compile.root_module.addAssemblyFile(source);
920934
}
921935

936+
/// Deprecated; use `compile.root_module.addObjectFile(source)` instead.
937+
/// To be removed after 0.15.0 is tagged.
922938
pub fn addObjectFile(compile: *Compile, source: LazyPath) void {
923939
compile.root_module.addObjectFile(source);
924940
}
925941

942+
/// Deprecated; use `compile.root_module.addObject(object)` instead.
943+
/// To be removed after 0.15.0 is tagged.
926944
pub fn addObject(compile: *Compile, object: *Compile) void {
927945
compile.root_module.addObject(object);
928946
}
929947

948+
/// Deprecated; use `compile.root_module.linkLibrary(library)` instead.
949+
/// To be removed after 0.15.0 is tagged.
930950
pub fn linkLibrary(compile: *Compile, library: *Compile) void {
931951
compile.root_module.linkLibrary(library);
932952
}
933953

954+
/// Deprecated; use `compile.root_module.addAfterIncludePath(lazy_path)` instead.
955+
/// To be removed after 0.15.0 is tagged.
934956
pub fn addAfterIncludePath(compile: *Compile, lazy_path: LazyPath) void {
935957
compile.root_module.addAfterIncludePath(lazy_path);
936958
}
937959

960+
/// Deprecated; use `compile.root_module.addSystemIncludePath(lazy_path)` instead.
961+
/// To be removed after 0.15.0 is tagged.
938962
pub fn addSystemIncludePath(compile: *Compile, lazy_path: LazyPath) void {
939963
compile.root_module.addSystemIncludePath(lazy_path);
940964
}
941965

966+
/// Deprecated; use `compile.root_module.addIncludePath(lazy_path)` instead.
967+
/// To be removed after 0.15.0 is tagged.
942968
pub fn addIncludePath(compile: *Compile, lazy_path: LazyPath) void {
943969
compile.root_module.addIncludePath(lazy_path);
944970
}
945971

972+
/// Deprecated; use `compile.root_module.addConfigHeader(config_header)` instead.
973+
/// To be removed after 0.15.0 is tagged.
946974
pub fn addConfigHeader(compile: *Compile, config_header: *Step.ConfigHeader) void {
947975
compile.root_module.addConfigHeader(config_header);
948976
}
949977

978+
/// Deprecated; use `compile.root_module.addEmbedPath(lazy_path)` instead.
979+
/// To be removed after 0.15.0 is tagged.
950980
pub fn addEmbedPath(compile: *Compile, lazy_path: LazyPath) void {
951981
compile.root_module.addEmbedPath(lazy_path);
952982
}
953983

984+
/// Deprecated; use `compile.root_module.addLibraryPath(directory_path)` instead.
985+
/// To be removed after 0.15.0 is tagged.
954986
pub fn addLibraryPath(compile: *Compile, directory_path: LazyPath) void {
955987
compile.root_module.addLibraryPath(directory_path);
956988
}
957989

990+
/// Deprecated; use `compile.root_module.addRPath(directory_path)` instead.
991+
/// To be removed after 0.15.0 is tagged.
958992
pub fn addRPath(compile: *Compile, directory_path: LazyPath) void {
959993
compile.root_module.addRPath(directory_path);
960994
}
961995

996+
/// Deprecated; use `compile.root_module.addSystemFrameworkPath(directory_path)` instead.
997+
/// To be removed after 0.15.0 is tagged.
962998
pub fn addSystemFrameworkPath(compile: *Compile, directory_path: LazyPath) void {
963999
compile.root_module.addSystemFrameworkPath(directory_path);
9641000
}
9651001

1002+
/// Deprecated; use `compile.root_module.addFrameworkPath(directory_path)` instead.
1003+
/// To be removed after 0.15.0 is tagged.
9661004
pub fn addFrameworkPath(compile: *Compile, directory_path: LazyPath) void {
9671005
compile.root_module.addFrameworkPath(directory_path);
9681006
}

0 commit comments

Comments
 (0)