Skip to content

Commit 25b60fa

Browse files
committed
std.Build: Deprecate Step.Compile APIs that mutate the root module
Not only are `Step.Compile` methods like `linkLibC()` redundant because `Module` exposes the same APIs, it also might not be immediately obvious to users that these methods modify the underlying root module, which can be a footgun and lead to unintended results if the module is exported to package consumers or shared by multiple compile steps. Using `compile.root_module.link_libc = true` makes it more clear to users which of the compile step and the module owns which options.
1 parent 869ef00 commit 25b60fa

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

lib/std/Build/Step/Compile.zig

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

684+
/// Deprecated; use `compile.root_module.link_libc = true` instead.
684685
pub fn linkLibC(compile: *Compile) void {
685686
compile.root_module.link_libc = true;
686687
}
687688

689+
/// Deprecated; use `compile.root_module.link_libcpp = true` instead.
688690
pub fn linkLibCpp(compile: *Compile) void {
689691
compile.root_module.link_libcpp = true;
690692
}
@@ -802,10 +804,12 @@ fn runPkgConfig(compile: *Compile, lib_name: []const u8) !PkgConfigResult {
802804
};
803805
}
804806

807+
/// Deprecated; use `compile.root_module.linkSystemLibrary(name, .{})` instead.
805808
pub fn linkSystemLibrary(compile: *Compile, name: []const u8) void {
806809
return compile.root_module.linkSystemLibrary(name, .{});
807810
}
808811

812+
/// Deprecated; use `compile.root_module.linkSystemLibrary(name, options)` instead.
809813
pub fn linkSystemLibrary2(
810814
compile: *Compile,
811815
name: []const u8,
@@ -814,22 +818,22 @@ pub fn linkSystemLibrary2(
814818
return compile.root_module.linkSystemLibrary(name, options);
815819
}
816820

821+
/// Deprecated; use `c.root_module.linkFramework(name, .{})` instead.
817822
pub fn linkFramework(c: *Compile, name: []const u8) void {
818823
c.root_module.linkFramework(name, .{});
819824
}
820825

821-
/// Handy when you have many C/C++ source files and want them all to have the same flags.
826+
/// Deprecated; use `compile.root_module.addCSourceFiles(options)` instead.
822827
pub fn addCSourceFiles(compile: *Compile, options: Module.AddCSourceFilesOptions) void {
823828
compile.root_module.addCSourceFiles(options);
824829
}
825830

831+
/// Deprecated; use `compile.root_module.addCSourceFile(source)` instead.
826832
pub fn addCSourceFile(compile: *Compile, source: Module.CSourceFile) void {
827833
compile.root_module.addCSourceFile(source);
828834
}
829835

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.
836+
/// Deprecated; use `compile.root_module.addWin32ResourceFile(source)` instead.
833837
pub fn addWin32ResourceFile(compile: *Compile, source: Module.RcSourceFile) void {
834838
compile.root_module.addWin32ResourceFile(source);
835839
}
@@ -915,54 +919,67 @@ pub fn getEmittedLlvmBc(compile: *Compile) LazyPath {
915919
return compile.getEmittedFileGeneric(&compile.generated_llvm_bc);
916920
}
917921

922+
/// Deprecated; use `compile.root_module.addAssemblyFile(source)` instead.
918923
pub fn addAssemblyFile(compile: *Compile, source: LazyPath) void {
919924
compile.root_module.addAssemblyFile(source);
920925
}
921926

927+
/// Deprecated; use `compile.root_module.addObjectFile(source)` instead.
922928
pub fn addObjectFile(compile: *Compile, source: LazyPath) void {
923929
compile.root_module.addObjectFile(source);
924930
}
925931

932+
/// Deprecated; use `compile.root_module.addObject(object)` instead.
926933
pub fn addObject(compile: *Compile, object: *Compile) void {
927934
compile.root_module.addObject(object);
928935
}
929936

937+
/// Deprecated; use `compile.root_module.linkLibrary(library)` instead.
930938
pub fn linkLibrary(compile: *Compile, library: *Compile) void {
931939
compile.root_module.linkLibrary(library);
932940
}
933941

942+
/// Deprecated; use `compile.root_module.addAfterIncludePath(lazy_path)` instead.
934943
pub fn addAfterIncludePath(compile: *Compile, lazy_path: LazyPath) void {
935944
compile.root_module.addAfterIncludePath(lazy_path);
936945
}
937946

947+
/// Deprecated; use `compile.root_module.addSystemIncludePath(lazy_path)` instead.
938948
pub fn addSystemIncludePath(compile: *Compile, lazy_path: LazyPath) void {
939949
compile.root_module.addSystemIncludePath(lazy_path);
940950
}
941951

952+
/// Deprecated; use `compile.root_module.addIncludePath(lazy_path)` instead.
942953
pub fn addIncludePath(compile: *Compile, lazy_path: LazyPath) void {
943954
compile.root_module.addIncludePath(lazy_path);
944955
}
945956

957+
/// Deprecated; use `compile.root_module.addConfigHeader(config_header)` instead.
946958
pub fn addConfigHeader(compile: *Compile, config_header: *Step.ConfigHeader) void {
947959
compile.root_module.addConfigHeader(config_header);
948960
}
949961

962+
/// Deprecated; use `compile.root_module.addEmbedPath(lazy_path)` instead.
950963
pub fn addEmbedPath(compile: *Compile, lazy_path: LazyPath) void {
951964
compile.root_module.addEmbedPath(lazy_path);
952965
}
953966

967+
/// Deprecated; use `compile.root_module.addLibraryPath(directory_path)` instead.
954968
pub fn addLibraryPath(compile: *Compile, directory_path: LazyPath) void {
955969
compile.root_module.addLibraryPath(directory_path);
956970
}
957971

972+
/// Deprecated; use `compile.root_module.addRPath(directory_path)` instead.
958973
pub fn addRPath(compile: *Compile, directory_path: LazyPath) void {
959974
compile.root_module.addRPath(directory_path);
960975
}
961976

977+
/// Deprecated; use `compile.root_module.addSystemFrameworkPath(directory_path)` instead.
962978
pub fn addSystemFrameworkPath(compile: *Compile, directory_path: LazyPath) void {
963979
compile.root_module.addSystemFrameworkPath(directory_path);
964980
}
965981

982+
/// Deprecated; use `compile.root_module.addFrameworkPath(directory_path)` instead.
966983
pub fn addFrameworkPath(compile: *Compile, directory_path: LazyPath) void {
967984
compile.root_module.addFrameworkPath(directory_path);
968985
}

0 commit comments

Comments
 (0)