Skip to content

Commit 0f3e60a

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 5c44934 commit 0f3e60a

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

lib/std/Build/Step/Compile.zig

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -677,10 +677,14 @@ pub fn producesImplib(compile: *Compile) bool {
677677
return compile.isDll();
678678
}
679679

680+
/// Deprecated; use `compile.root_module.link_libc = true` instead.
681+
/// To be removed after Zig 0.14.0 is released.
680682
pub fn linkLibC(compile: *Compile) void {
681683
compile.root_module.link_libc = true;
682684
}
683685

686+
/// Deprecated; use `compile.root_module.link_libcpp = true` instead.
687+
/// To be removed after Zig 0.14.0 is released.
684688
pub fn linkLibCpp(compile: *Compile) void {
685689
compile.root_module.link_libcpp = true;
686690
}
@@ -794,10 +798,14 @@ fn runPkgConfig(compile: *Compile, lib_name: []const u8) !PkgConfigResult {
794798
};
795799
}
796800

801+
/// Deprecated; use `compile.root_module.linkSystemLibrary(name, .{})` instead.
802+
/// To be removed after Zig 0.14.0 is released.
797803
pub fn linkSystemLibrary(compile: *Compile, name: []const u8) void {
798804
return compile.root_module.linkSystemLibrary(name, .{});
799805
}
800806

807+
/// Deprecated; use `compile.root_module.linkSystemLibrary(name, options)` instead.
808+
/// To be removed after Zig 0.14.0 is released.
801809
pub fn linkSystemLibrary2(
802810
compile: *Compile,
803811
name: []const u8,
@@ -806,22 +814,26 @@ pub fn linkSystemLibrary2(
806814
return compile.root_module.linkSystemLibrary(name, options);
807815
}
808816

817+
/// Deprecated; use `c.root_module.linkFramework(name, .{})` instead.
818+
/// To be removed after Zig 0.14.0 is released.
809819
pub fn linkFramework(c: *Compile, name: []const u8) void {
810820
c.root_module.linkFramework(name, .{});
811821
}
812822

813-
/// Handy when you have many C/C++ source files and want them all to have the same flags.
823+
/// Deprecated; use `compile.root_module.addCSourceFiles(options)` instead.
824+
/// To be removed after Zig 0.14.0 is released.
814825
pub fn addCSourceFiles(compile: *Compile, options: Module.AddCSourceFilesOptions) void {
815826
compile.root_module.addCSourceFiles(options);
816827
}
817828

829+
/// Deprecated; use `compile.root_module.addCSourceFile(source)` instead.
830+
/// To be removed after Zig 0.14.0 is released.
818831
pub fn addCSourceFile(compile: *Compile, source: Module.CSourceFile) void {
819832
compile.root_module.addCSourceFile(source);
820833
}
821834

822-
/// Resource files must have the extension `.rc`.
823-
/// Can be called regardless of target. The .rc file will be ignored
824-
/// if the target object format does not support embedded resources.
835+
/// Deprecated; use `compile.root_module.addWin32ResourceFile(source)` instead.
836+
/// To be removed after Zig 0.14.0 is released.
825837
pub fn addWin32ResourceFile(compile: *Compile, source: Module.RcSourceFile) void {
826838
compile.root_module.addWin32ResourceFile(source);
827839
}
@@ -907,50 +919,74 @@ pub fn getEmittedLlvmBc(compile: *Compile) LazyPath {
907919
return compile.getEmittedFileGeneric(&compile.generated_llvm_bc);
908920
}
909921

922+
/// Deprecated; use `compile.root_module.addAssemblyFile(source)` instead.
923+
/// To be removed after Zig 0.14.0 is released.
910924
pub fn addAssemblyFile(compile: *Compile, source: LazyPath) void {
911925
compile.root_module.addAssemblyFile(source);
912926
}
913927

928+
/// Deprecated; use `compile.root_module.addObjectFile(source)` instead.
929+
/// To be removed after Zig 0.14.0 is released.
914930
pub fn addObjectFile(compile: *Compile, source: LazyPath) void {
915931
compile.root_module.addObjectFile(source);
916932
}
917933

934+
/// Deprecated; use `compile.root_module.addObject(object)` instead.
935+
/// To be removed after Zig 0.14.0 is released.
918936
pub fn addObject(compile: *Compile, object: *Compile) void {
919937
compile.root_module.addObject(object);
920938
}
921939

940+
/// Deprecated; use `compile.root_module.linkLibrary(library)` instead.
941+
/// To be removed after Zig 0.14.0 is released.
922942
pub fn linkLibrary(compile: *Compile, library: *Compile) void {
923943
compile.root_module.linkLibrary(library);
924944
}
925945

946+
/// Deprecated; use `compile.root_module.addAfterIncludePath(lazy_path)` instead.
947+
/// To be removed after Zig 0.14.0 is released.
926948
pub fn addAfterIncludePath(compile: *Compile, lazy_path: LazyPath) void {
927949
compile.root_module.addAfterIncludePath(lazy_path);
928950
}
929951

952+
/// Deprecated; use `compile.root_module.addSystemIncludePath(lazy_path)` instead.
953+
/// To be removed after Zig 0.14.0 is released.
930954
pub fn addSystemIncludePath(compile: *Compile, lazy_path: LazyPath) void {
931955
compile.root_module.addSystemIncludePath(lazy_path);
932956
}
933957

958+
/// Deprecated; use `compile.root_module.addIncludePath(lazy_path)` instead.
959+
/// To be removed after Zig 0.14.0 is released.
934960
pub fn addIncludePath(compile: *Compile, lazy_path: LazyPath) void {
935961
compile.root_module.addIncludePath(lazy_path);
936962
}
937963

964+
/// Deprecated; use `compile.root_module.addConfigHeader(config_header)` instead.
965+
/// To be removed after Zig 0.14.0 is released.
938966
pub fn addConfigHeader(compile: *Compile, config_header: *Step.ConfigHeader) void {
939967
compile.root_module.addConfigHeader(config_header);
940968
}
941969

970+
/// Deprecated; use `compile.root_module.addLibraryPath(directory_path)` instead.
971+
/// To be removed after Zig 0.14.0 is released.
942972
pub fn addLibraryPath(compile: *Compile, directory_path: LazyPath) void {
943973
compile.root_module.addLibraryPath(directory_path);
944974
}
945975

976+
/// Deprecated; use `compile.root_module.addRPath(directory_path)` instead.
977+
/// To be removed after Zig 0.14.0 is released.
946978
pub fn addRPath(compile: *Compile, directory_path: LazyPath) void {
947979
compile.root_module.addRPath(directory_path);
948980
}
949981

982+
/// Deprecated; use `compile.root_module.addSystemFrameworkPath(directory_path)` instead.
983+
/// To be removed after Zig 0.14.0 is released.
950984
pub fn addSystemFrameworkPath(compile: *Compile, directory_path: LazyPath) void {
951985
compile.root_module.addSystemFrameworkPath(directory_path);
952986
}
953987

988+
/// Deprecated; use `compile.root_module.addFrameworkPath(directory_path)` instead.
989+
/// To be removed after Zig 0.14.0 is released.
954990
pub fn addFrameworkPath(compile: *Compile, directory_path: LazyPath) void {
955991
compile.root_module.addFrameworkPath(directory_path);
956992
}

0 commit comments

Comments
 (0)