Skip to content

Commit

Permalink
std.Build: remove deprecated APIs
Browse files Browse the repository at this point in the history
These APIs were all deprecated prior to the release of 0.13.0, so can be
safety removed in the current release cycle.

`std.Build`:
* `host` -> `graph.host`

`std.Build.Step.Compile`:
* `setLinkerScriptPath` -> `setLinkerScript`
* `defineCMacro` -> `root_module.addCMacro`
* `linkFrameworkNeeded`-> `root_module.linkFramework`
* `linkFrameworkWeak`-> `root_module.linkFramework`

`std.Build.Step.ObjCopy`:
* `getOutputSource` -> `getOutput`

`std.Build.Step.Options`:
* `addOptionArtifact` -> `addOptionPath`
* `getSource` -> `getOutput`

`std.Build.Step.Run`:
* `extra_file_dependencies` -> `addFileInput`
* `addDirectorySourceArg` -> `addDirectoryArg`
* `addPrefixedDirectorySourceArg` -> `addPrefixedDirectoryArg`
  • Loading branch information
BratishkaErik committed Dec 17, 2024
1 parent debba65 commit 3d393db
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 56 deletions.
5 changes: 0 additions & 5 deletions lib/std/Build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ enable_wine: bool = false,
/// that contains the path `aarch64-linux-gnu/lib/ld-linux-aarch64.so.1`.
glibc_runtimes_dir: ?[]const u8 = null,

/// Deprecated. Use `b.graph.host`.
host: ResolvedTarget,

dep_prefix: []const u8 = "",

modules: std.StringArrayHashMap(*Module),
Expand Down Expand Up @@ -301,7 +298,6 @@ pub fn create(
},
.install_path = undefined,
.args = null,
.host = graph.host,
.modules = .init(arena),
.named_writefiles = .init(arena),
.named_lazy_paths = .init(arena),
Expand Down Expand Up @@ -393,7 +389,6 @@ fn createChildOnly(
.enable_wasmtime = parent.enable_wasmtime,
.enable_wine = parent.enable_wine,
.glibc_runtimes_dir = parent.glibc_runtimes_dir,
.host = parent.host,
.dep_prefix = parent.fmt("{s}{s}.", .{ parent.dep_prefix, dep_name }),
.modules = .init(allocator),
.named_writefiles = .init(allocator),
Expand Down
18 changes: 0 additions & 18 deletions lib/std/Build/Step/Compile.zig
Original file line number Diff line number Diff line change
Expand Up @@ -583,9 +583,6 @@ pub fn checkObject(compile: *Compile) *Step.CheckObject {
return Step.CheckObject.create(compile.step.owner, compile.getEmittedBin(), compile.rootModuleTarget().ofmt);
}

/// deprecated: use `setLinkerScript`
pub const setLinkerScriptPath = setLinkerScript;

pub fn setLinkerScript(compile: *Compile, source: LazyPath) void {
const b = compile.step.owner;
compile.linker_script = source.dupe(b);
Expand Down Expand Up @@ -675,11 +672,6 @@ pub fn linkLibCpp(compile: *Compile) void {
compile.root_module.link_libcpp = true;
}

/// Deprecated. Use `c.root_module.addCMacro`.
pub fn defineCMacro(c: *Compile, name: []const u8, value: ?[]const u8) void {
c.root_module.addCMacro(name, value orelse "1");
}

const PkgConfigResult = struct {
cflags: []const []const u8,
libs: []const []const u8,
Expand Down Expand Up @@ -805,16 +797,6 @@ pub fn linkFramework(c: *Compile, name: []const u8) void {
c.root_module.linkFramework(name, .{});
}

/// Deprecated. Use `c.root_module.linkFramework`.
pub fn linkFrameworkNeeded(c: *Compile, name: []const u8) void {
c.root_module.linkFramework(name, .{ .needed = true });
}

/// Deprecated. Use `c.root_module.linkFramework`.
pub fn linkFrameworkWeak(c: *Compile, name: []const u8) void {
c.root_module.linkFramework(name, .{ .weak = true });
}

/// Handy when you have many C/C++ source files and want them all to have the same flags.
pub fn addCSourceFiles(compile: *Compile, options: Module.AddCSourceFilesOptions) void {
compile.root_module.addCSourceFiles(options);
Expand Down
3 changes: 0 additions & 3 deletions lib/std/Build/Step/ObjCopy.zig
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ pub fn create(
return objcopy;
}

/// deprecated: use getOutput
pub const getOutputSource = getOutput;

pub fn getOutput(objcopy: *const ObjCopy) std.Build.LazyPath {
return .{ .generated = .{ .file = &objcopy.output_file } };
}
Expand Down
8 changes: 0 additions & 8 deletions lib/std/Build/Step/Options.zig
Original file line number Diff line number Diff line change
Expand Up @@ -390,20 +390,12 @@ pub fn addOptionPath(
path.addStepDependencies(&options.step);
}

/// Deprecated: use `addOptionPath(options, name, artifact.getEmittedBin())` instead.
pub fn addOptionArtifact(options: *Options, name: []const u8, artifact: *Step.Compile) void {
return addOptionPath(options, name, artifact.getEmittedBin());
}

pub fn createModule(options: *Options) *std.Build.Module {
return options.step.owner.createModule(.{
.root_source_file = options.getOutput(),
});
}

/// deprecated: use `getOutput`
pub const getSource = getOutput;

/// Returns the main artifact of this Build Step which is a Zig source file
/// generated from the key-value pairs of the Options.
pub fn getOutput(options: *Options) LazyPath {
Expand Down
13 changes: 0 additions & 13 deletions lib/std/Build/Step/Run.zig
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ stdio: StdIo,
/// It should be only set using `setStdIn`.
stdin: StdIn,

/// Deprecated: use `addFileInput`
extra_file_dependencies: []const []const u8,

/// Additional input files that, when modified, indicate that the Run step
/// should be re-executed.
/// If the Run step is determined to have side-effects, the Run step is always
Expand Down Expand Up @@ -178,7 +175,6 @@ pub fn create(owner: *std.Build, name: []const u8) *Run {
.disable_zig_progress = false,
.stdio = .infer_from_args,
.stdin = .none,
.extra_file_dependencies = &.{},
.file_inputs = .{},
.rename_step_with_output_arg = true,
.skip_foreign_checks = false,
Expand Down Expand Up @@ -364,16 +360,10 @@ pub fn addPrefixedOutputDirectoryArg(
return .{ .generated = .{ .file = &output.generated_file } };
}

/// deprecated: use `addDirectoryArg`
pub const addDirectorySourceArg = addDirectoryArg;

pub fn addDirectoryArg(run: *Run, directory_source: std.Build.LazyPath) void {
run.addPrefixedDirectoryArg("", directory_source);
}

// deprecated: use `addPrefixedDirectoryArg`
pub const addPrefixedDirectorySourceArg = addPrefixedDirectoryArg;

pub fn addPrefixedDirectoryArg(run: *Run, prefix: []const u8, directory_source: std.Build.LazyPath) void {
const b = run.step.owner;

Expand Down Expand Up @@ -698,9 +688,6 @@ fn make(step: *Step, options: Step.MakeOptions) !void {

hashStdIo(&man.hash, run.stdio);

for (run.extra_file_dependencies) |file_path| {
_ = try man.addFile(b.pathFromRoot(file_path), null);
}
for (run.file_inputs.items) |lazy_path| {
_ = try man.addFile(lazy_path.getPath2(b, step), null);
}
Expand Down
2 changes: 1 addition & 1 deletion test/standalone/extern/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
.link_libc = true,
});
if (b.graph.host.result.abi == .msvc) shared.defineCMacro("API", "__declspec(dllexport)");
if (b.graph.host.result.abi == .msvc) shared.root_module.addCMacro("API", "__declspec(dllexport)");
shared.addCSourceFile(.{ .file = b.path("shared.c"), .flags = &.{} });
const test_exe = b.addTest(.{
.root_source_file = b.path("main.zig"),
Expand Down
12 changes: 6 additions & 6 deletions test/standalone/issue_11595/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ pub fn build(b: *std.Build) void {

var i: i32 = 0;
while (i < 1000) : (i += 1) {
exe.defineCMacro("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
exe.root_module.addCMacro("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
}

exe.defineCMacro("FOO", "42");
exe.defineCMacro("BAR", "\"BAR\"");
exe.defineCMacro("BAZ",
exe.root_module.addCMacro("FOO", "42");
exe.root_module.addCMacro("BAR", "\"BAR\"");
exe.root_module.addCMacro("BAZ",
\\"\"BAZ\""
);
exe.defineCMacro("QUX", "\"Q\" \"UX\"");
exe.defineCMacro("QUUX", "\"QU\\\"UX\"");
exe.root_module.addCMacro("QUX", "\"Q\" \"UX\"");
exe.root_module.addCMacro("QUUX", "\"QU\\\"UX\"");

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

Expand Down
2 changes: 1 addition & 1 deletion test/standalone/stack_iterator/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn build(b: *std.Build) void {
});

if (target.result.os.tag == .windows)
c_shared_lib.defineCMacro("LIB_API", "__declspec(dllexport)");
c_shared_lib.root_module.addCMacro("LIB_API", "__declspec(dllexport)");

c_shared_lib.addCSourceFile(.{
.file = b.path("shared_lib.c"),
Expand Down
2 changes: 1 addition & 1 deletion test/tests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1704,7 +1704,7 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step {
.file = b.path("test/c_abi/cfuncs.c"),
.flags = &.{"-std=c99"},
});
for (c_abi_target.c_defines) |define| test_step.defineCMacro(define, null);
for (c_abi_target.c_defines) |define| test_step.root_module.addCMacro(define, "1");

// This test is intentionally trying to check if the external ABI is
// done properly. LTO would be a hindrance to this.
Expand Down

0 comments on commit 3d393db

Please sign in to comment.