Skip to content

Commit 5982441

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 6e8493d commit 5982441

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
@@ -677,10 +677,12 @@ pub fn producesImplib(compile: *Compile) bool {
677677
return compile.isDll();
678678
}
679679

680+
/// Deprecated; use `compile.root_module.link_libc = true` instead.
680681
pub fn linkLibC(compile: *Compile) void {
681682
compile.root_module.link_libc = true;
682683
}
683684

685+
/// Deprecated; use `compile.root_module.link_libcpp = true` instead.
684686
pub fn linkLibCpp(compile: *Compile) void {
685687
compile.root_module.link_libcpp = true;
686688
}
@@ -798,10 +800,12 @@ fn runPkgConfig(compile: *Compile, lib_name: []const u8) !PkgConfigResult {
798800
};
799801
}
800802

803+
/// Deprecated; use `compile.root_module.linkSystemLibrary(name, .{})` instead.
801804
pub fn linkSystemLibrary(compile: *Compile, name: []const u8) void {
802805
return compile.root_module.linkSystemLibrary(name, .{});
803806
}
804807

808+
/// Deprecated; use `compile.root_module.linkSystemLibrary(name, options)` instead.
805809
pub fn linkSystemLibrary2(
806810
compile: *Compile,
807811
name: []const u8,
@@ -810,22 +814,22 @@ pub fn linkSystemLibrary2(
810814
return compile.root_module.linkSystemLibrary(name, options);
811815
}
812816

817+
/// Deprecated; use `c.root_module.linkFramework(name, .{})` instead.
813818
pub fn linkFramework(c: *Compile, name: []const u8) void {
814819
c.root_module.linkFramework(name, .{});
815820
}
816821

817-
/// Handy when you have many C/C++ source files and want them all to have the same flags.
822+
/// Deprecated; use `compile.root_module.addCSourceFiles(options)` instead.
818823
pub fn addCSourceFiles(compile: *Compile, options: Module.AddCSourceFilesOptions) void {
819824
compile.root_module.addCSourceFiles(options);
820825
}
821826

827+
/// Deprecated; use `compile.root_module.addCSourceFile(source)` instead.
822828
pub fn addCSourceFile(compile: *Compile, source: Module.CSourceFile) void {
823829
compile.root_module.addCSourceFile(source);
824830
}
825831

826-
/// Resource files must have the extension `.rc`.
827-
/// Can be called regardless of target. The .rc file will be ignored
828-
/// if the target object format does not support embedded resources.
832+
/// Deprecated; use `compile.root_module.addWin32ResourceFile(source)` instead.
829833
pub fn addWin32ResourceFile(compile: *Compile, source: Module.RcSourceFile) void {
830834
compile.root_module.addWin32ResourceFile(source);
831835
}
@@ -911,54 +915,67 @@ pub fn getEmittedLlvmBc(compile: *Compile) LazyPath {
911915
return compile.getEmittedFileGeneric(&compile.generated_llvm_bc);
912916
}
913917

918+
/// Deprecated; use `compile.root_module.addAssemblyFile(source)` instead.
914919
pub fn addAssemblyFile(compile: *Compile, source: LazyPath) void {
915920
compile.root_module.addAssemblyFile(source);
916921
}
917922

923+
/// Deprecated; use `compile.root_module.addObjectFile(source)` instead.
918924
pub fn addObjectFile(compile: *Compile, source: LazyPath) void {
919925
compile.root_module.addObjectFile(source);
920926
}
921927

928+
/// Deprecated; use `compile.root_module.addObject(object)` instead.
922929
pub fn addObject(compile: *Compile, object: *Compile) void {
923930
compile.root_module.addObject(object);
924931
}
925932

933+
/// Deprecated; use `compile.root_module.linkLibrary(library)` instead.
926934
pub fn linkLibrary(compile: *Compile, library: *Compile) void {
927935
compile.root_module.linkLibrary(library);
928936
}
929937

938+
/// Deprecated; use `compile.root_module.addAfterIncludePath(lazy_path)` instead.
930939
pub fn addAfterIncludePath(compile: *Compile, lazy_path: LazyPath) void {
931940
compile.root_module.addAfterIncludePath(lazy_path);
932941
}
933942

943+
/// Deprecated; use `compile.root_module.addSystemIncludePath(lazy_path)` instead.
934944
pub fn addSystemIncludePath(compile: *Compile, lazy_path: LazyPath) void {
935945
compile.root_module.addSystemIncludePath(lazy_path);
936946
}
937947

948+
/// Deprecated; use `compile.root_module.addIncludePath(lazy_path)` instead.
938949
pub fn addIncludePath(compile: *Compile, lazy_path: LazyPath) void {
939950
compile.root_module.addIncludePath(lazy_path);
940951
}
941952

953+
/// Deprecated; use `compile.root_module.addConfigHeader(config_header)` instead.
942954
pub fn addConfigHeader(compile: *Compile, config_header: *Step.ConfigHeader) void {
943955
compile.root_module.addConfigHeader(config_header);
944956
}
945957

958+
/// Deprecated; use `compile.root_module.addEmbedPath(lazy_path)` instead.
946959
pub fn addEmbedPath(compile: *Compile, lazy_path: LazyPath) void {
947960
compile.root_module.addEmbedPath(lazy_path);
948961
}
949962

963+
/// Deprecated; use `compile.root_module.addLibraryPath(directory_path)` instead.
950964
pub fn addLibraryPath(compile: *Compile, directory_path: LazyPath) void {
951965
compile.root_module.addLibraryPath(directory_path);
952966
}
953967

968+
/// Deprecated; use `compile.root_module.addRPath(directory_path)` instead.
954969
pub fn addRPath(compile: *Compile, directory_path: LazyPath) void {
955970
compile.root_module.addRPath(directory_path);
956971
}
957972

973+
/// Deprecated; use `compile.root_module.addSystemFrameworkPath(directory_path)` instead.
958974
pub fn addSystemFrameworkPath(compile: *Compile, directory_path: LazyPath) void {
959975
compile.root_module.addSystemFrameworkPath(directory_path);
960976
}
961977

978+
/// Deprecated; use `compile.root_module.addFrameworkPath(directory_path)` instead.
962979
pub fn addFrameworkPath(compile: *Compile, directory_path: LazyPath) void {
963980
compile.root_module.addFrameworkPath(directory_path);
964981
}

0 commit comments

Comments
 (0)