2019-03-02 13:46:04 -08:00
|
|
|
const std = @import("std.zig");
|
2020-02-25 22:18:23 -08:00
|
|
|
const builtin = std.builtin;
|
2017-10-31 01:47:55 -07:00
|
|
|
const io = std.io;
|
2019-05-26 10:17:34 -07:00
|
|
|
const fs = std.fs;
|
2017-10-31 01:47:55 -07:00
|
|
|
const mem = std.mem;
|
|
|
|
const debug = std.debug;
|
2019-09-03 13:19:10 -07:00
|
|
|
const panic = std.debug.panic;
|
2017-04-13 14:21:00 -07:00
|
|
|
const assert = debug.assert;
|
2017-10-31 01:47:55 -07:00
|
|
|
const warn = std.debug.warn;
|
|
|
|
const ArrayList = std.ArrayList;
|
2019-09-03 14:53:05 -07:00
|
|
|
const StringHashMap = std.StringHashMap;
|
2017-10-31 01:47:55 -07:00
|
|
|
const Allocator = mem.Allocator;
|
2019-05-26 10:17:34 -07:00
|
|
|
const process = std.process;
|
2017-10-31 01:47:55 -07:00
|
|
|
const BufSet = std.BufSet;
|
|
|
|
const BufMap = std.BufMap;
|
|
|
|
const fmt_lib = std.fmt;
|
2019-05-24 19:52:07 -07:00
|
|
|
const File = std.fs.File;
|
2020-02-25 22:18:23 -08:00
|
|
|
const CrossTarget = std.zig.CrossTarget;
|
2017-03-31 02:48:15 -07:00
|
|
|
|
2019-02-26 15:10:40 -08:00
|
|
|
pub const FmtStep = @import("build/fmt.zig").FmtStep;
|
2020-01-04 23:01:28 -08:00
|
|
|
pub const TranslateCStep = @import("build/translate_c.zig").TranslateCStep;
|
|
|
|
pub const WriteFileStep = @import("build/write_file.zig").WriteFileStep;
|
|
|
|
pub const RunStep = @import("build/run.zig").RunStep;
|
|
|
|
pub const CheckFileStep = @import("build/check_file.zig").CheckFileStep;
|
2020-01-21 14:32:00 -08:00
|
|
|
pub const InstallRawStep = @import("build/emit_raw.zig").InstallRawStep;
|
2019-02-26 15:10:40 -08:00
|
|
|
|
2018-11-13 05:08:37 -08:00
|
|
|
pub const Builder = struct {
|
2017-04-30 18:03:23 -07:00
|
|
|
install_tls: TopLevelStep,
|
2019-07-04 12:32:44 -07:00
|
|
|
uninstall_tls: TopLevelStep,
|
2018-05-31 07:56:59 -07:00
|
|
|
allocator: *Allocator,
|
2017-04-06 02:34:04 -07:00
|
|
|
user_input_options: UserInputOptionsMap,
|
|
|
|
available_options_map: AvailableOptionsMap,
|
2017-05-04 11:05:06 -07:00
|
|
|
available_options_list: ArrayList(AvailableOption),
|
2017-04-06 02:34:04 -07:00
|
|
|
verbose: bool,
|
2017-10-25 20:10:41 -07:00
|
|
|
verbose_tokenize: bool,
|
|
|
|
verbose_ast: bool,
|
|
|
|
verbose_link: bool,
|
2019-02-25 08:37:54 -08:00
|
|
|
verbose_cc: bool,
|
2017-10-25 20:10:41 -07:00
|
|
|
verbose_ir: bool,
|
|
|
|
verbose_llvm_ir: bool,
|
|
|
|
verbose_cimport: bool,
|
2020-02-24 17:11:33 -08:00
|
|
|
verbose_llvm_cpu_features: bool,
|
2017-04-06 02:34:04 -07:00
|
|
|
invalid_user_input: bool,
|
2017-04-13 14:21:00 -07:00
|
|
|
zig_exe: []const u8,
|
2018-05-31 07:56:59 -07:00
|
|
|
default_step: *Step,
|
2018-11-07 18:22:42 -08:00
|
|
|
env_map: *BufMap,
|
2018-05-31 07:56:59 -07:00
|
|
|
top_level_steps: ArrayList(*TopLevelStep),
|
2019-07-04 12:32:44 -07:00
|
|
|
install_prefix: ?[]const u8,
|
2019-07-21 15:04:23 -07:00
|
|
|
dest_dir: ?[]const u8,
|
2019-09-03 13:19:10 -07:00
|
|
|
lib_dir: []const u8,
|
|
|
|
exe_dir: []const u8,
|
2019-12-18 19:10:17 -08:00
|
|
|
h_dir: []const u8,
|
2019-07-22 07:45:59 -07:00
|
|
|
install_path: []const u8,
|
2019-07-21 15:04:23 -07:00
|
|
|
search_prefixes: ArrayList([]const u8),
|
2019-07-04 12:32:44 -07:00
|
|
|
installed_files: ArrayList(InstalledFile),
|
2017-04-18 22:13:15 -07:00
|
|
|
build_root: []const u8,
|
2017-04-27 23:22:12 -07:00
|
|
|
cache_root: []const u8,
|
2017-05-09 18:20:09 -07:00
|
|
|
release_mode: ?builtin.Mode,
|
2019-07-04 12:32:44 -07:00
|
|
|
is_release: bool,
|
stage1 is now a hybrid of C++ and Zig
This modifies the build process of Zig to put all of the source files
into libcompiler.a, except main.cpp and userland.cpp.
Next, the build process links main.cpp, userland.cpp, and libcompiler.a
into zig1. userland.cpp is a shim for functions that will later be
replaced with self-hosted implementations.
Next, the build process uses zig1 to build src-self-hosted/stage1.zig
into libuserland.a, which does not depend on any of the things that
are shimmed in userland.cpp, such as translate-c.
Finally, the build process re-links main.cpp and libcompiler.a, except
with libuserland.a instead of userland.cpp. Now the shims are replaced
with .zig code. This provides all of the Zig standard library to the
stage1 C++ compiler, and enables us to move certain things to userland,
such as translate-c.
As a proof of concept I have made the `zig zen` command use text defined
in userland. I added `zig translate-c-2` which is a work-in-progress
reimplementation of translate-c in userland, which currently calls
`std.debug.panic("unimplemented")` and you can see the stack trace makes
it all the way back into the C++ main() function (Thanks LemonBoy for
improving that!).
This could potentially let us move other things into userland, such as
hashing algorithms, the entire cache system, .d file parsing, pretty
much anything that libuserland.a itself doesn't need to depend on.
This can also let us have `zig fmt` in stage1 without the overhead
of child process execution, and without the initial compilation delay
before it gets cached.
See #1964
2019-04-16 13:47:47 -07:00
|
|
|
override_lib_dir: ?[]const u8,
|
2019-10-10 12:58:47 -07:00
|
|
|
vcpkg_root: VcpkgRoot,
|
2019-09-23 10:33:43 -07:00
|
|
|
pkg_config_pkg_list: ?(PkgConfigError![]const PkgConfigPkg) = null,
|
2019-12-16 14:14:16 -08:00
|
|
|
args: ?[][]const u8 = null,
|
2019-09-23 10:33:43 -07:00
|
|
|
|
|
|
|
const PkgConfigError = error{
|
|
|
|
PkgConfigCrashed,
|
|
|
|
PkgConfigFailed,
|
|
|
|
PkgConfigNotInstalled,
|
|
|
|
PkgConfigInvalidOutput,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub const PkgConfigPkg = struct {
|
|
|
|
name: []const u8,
|
|
|
|
desc: []const u8,
|
|
|
|
};
|
|
|
|
|
2018-11-13 05:08:37 -08:00
|
|
|
pub const CStd = enum {
|
2018-09-06 13:29:35 -07:00
|
|
|
C89,
|
|
|
|
C99,
|
|
|
|
C11,
|
|
|
|
};
|
|
|
|
|
2019-09-03 14:53:05 -07:00
|
|
|
const UserInputOptionsMap = StringHashMap(UserInputOption);
|
|
|
|
const AvailableOptionsMap = StringHashMap(AvailableOption);
|
2017-04-06 02:34:04 -07:00
|
|
|
|
2018-11-13 05:08:37 -08:00
|
|
|
const AvailableOption = struct {
|
2017-04-06 02:34:04 -07:00
|
|
|
name: []const u8,
|
|
|
|
type_id: TypeId,
|
|
|
|
description: []const u8,
|
|
|
|
};
|
|
|
|
|
2018-11-13 05:08:37 -08:00
|
|
|
const UserInputOption = struct {
|
2017-04-06 02:34:04 -07:00
|
|
|
name: []const u8,
|
|
|
|
value: UserValue,
|
|
|
|
used: bool,
|
|
|
|
};
|
|
|
|
|
2018-11-13 05:08:37 -08:00
|
|
|
const UserValue = union(enum) {
|
2017-12-03 17:43:56 -08:00
|
|
|
Flag: void,
|
2017-04-06 02:34:04 -07:00
|
|
|
Scalar: []const u8,
|
2017-05-04 11:05:06 -07:00
|
|
|
List: ArrayList([]const u8),
|
2017-04-06 02:34:04 -07:00
|
|
|
};
|
|
|
|
|
2018-11-13 05:08:37 -08:00
|
|
|
const TypeId = enum {
|
2017-04-06 02:34:04 -07:00
|
|
|
Bool,
|
|
|
|
Int,
|
|
|
|
Float,
|
2020-05-16 07:36:18 -07:00
|
|
|
Enum,
|
2017-04-06 02:34:04 -07:00
|
|
|
String,
|
|
|
|
List,
|
|
|
|
};
|
2017-03-31 02:48:15 -07:00
|
|
|
|
2018-11-13 05:08:37 -08:00
|
|
|
const TopLevelStep = struct {
|
2017-04-13 14:21:00 -07:00
|
|
|
step: Step,
|
|
|
|
description: []const u8,
|
|
|
|
};
|
|
|
|
|
2019-07-04 12:32:44 -07:00
|
|
|
pub fn create(
|
|
|
|
allocator: *Allocator,
|
|
|
|
zig_exe: []const u8,
|
|
|
|
build_root: []const u8,
|
|
|
|
cache_root: []const u8,
|
|
|
|
) !*Builder {
|
|
|
|
const env_map = try allocator.create(BufMap);
|
|
|
|
env_map.* = try process.getEnvMap(allocator);
|
|
|
|
|
|
|
|
const self = try allocator.create(Builder);
|
|
|
|
self.* = Builder{
|
2017-04-18 22:13:15 -07:00
|
|
|
.zig_exe = zig_exe,
|
|
|
|
.build_root = build_root,
|
2019-07-04 12:32:44 -07:00
|
|
|
.cache_root = try fs.path.relative(allocator, build_root, cache_root),
|
2017-04-06 02:34:04 -07:00
|
|
|
.verbose = false,
|
2017-10-25 20:10:41 -07:00
|
|
|
.verbose_tokenize = false,
|
|
|
|
.verbose_ast = false,
|
|
|
|
.verbose_link = false,
|
2019-02-25 08:37:54 -08:00
|
|
|
.verbose_cc = false,
|
2017-10-25 20:10:41 -07:00
|
|
|
.verbose_ir = false,
|
|
|
|
.verbose_llvm_ir = false,
|
|
|
|
.verbose_cimport = false,
|
2020-02-24 17:11:33 -08:00
|
|
|
.verbose_llvm_cpu_features = false,
|
2017-04-06 02:34:04 -07:00
|
|
|
.invalid_user_input = false,
|
2017-03-31 02:48:15 -07:00
|
|
|
.allocator = allocator,
|
2017-04-06 02:34:04 -07:00
|
|
|
.user_input_options = UserInputOptionsMap.init(allocator),
|
|
|
|
.available_options_map = AvailableOptionsMap.init(allocator),
|
2017-05-04 11:05:06 -07:00
|
|
|
.available_options_list = ArrayList(AvailableOption).init(allocator),
|
2018-05-31 07:56:59 -07:00
|
|
|
.top_level_steps = ArrayList(*TopLevelStep).init(allocator),
|
2017-04-13 14:21:00 -07:00
|
|
|
.default_step = undefined,
|
2018-10-15 15:23:47 -07:00
|
|
|
.env_map = env_map,
|
2017-12-23 17:21:57 -08:00
|
|
|
.search_prefixes = ArrayList([]const u8).init(allocator),
|
2019-07-21 15:04:23 -07:00
|
|
|
.install_prefix = null,
|
2019-09-03 13:19:10 -07:00
|
|
|
.lib_dir = undefined,
|
|
|
|
.exe_dir = undefined,
|
2019-12-18 19:10:17 -08:00
|
|
|
.h_dir = undefined,
|
2019-07-21 15:04:23 -07:00
|
|
|
.dest_dir = env_map.get("DESTDIR"),
|
2019-07-04 12:32:44 -07:00
|
|
|
.installed_files = ArrayList(InstalledFile).init(allocator),
|
2018-11-13 05:08:37 -08:00
|
|
|
.install_tls = TopLevelStep{
|
2017-04-30 18:03:23 -07:00
|
|
|
.step = Step.initNoOp("install", allocator),
|
|
|
|
.description = "Copy build artifacts to prefix path",
|
|
|
|
},
|
2019-07-04 12:32:44 -07:00
|
|
|
.uninstall_tls = TopLevelStep{
|
|
|
|
.step = Step.init("uninstall", allocator, makeUninstall),
|
|
|
|
.description = "Remove build artifacts from prefix path",
|
|
|
|
},
|
2017-05-09 18:20:09 -07:00
|
|
|
.release_mode = null,
|
2019-07-04 12:32:44 -07:00
|
|
|
.is_release = false,
|
stage1 is now a hybrid of C++ and Zig
This modifies the build process of Zig to put all of the source files
into libcompiler.a, except main.cpp and userland.cpp.
Next, the build process links main.cpp, userland.cpp, and libcompiler.a
into zig1. userland.cpp is a shim for functions that will later be
replaced with self-hosted implementations.
Next, the build process uses zig1 to build src-self-hosted/stage1.zig
into libuserland.a, which does not depend on any of the things that
are shimmed in userland.cpp, such as translate-c.
Finally, the build process re-links main.cpp and libcompiler.a, except
with libuserland.a instead of userland.cpp. Now the shims are replaced
with .zig code. This provides all of the Zig standard library to the
stage1 C++ compiler, and enables us to move certain things to userland,
such as translate-c.
As a proof of concept I have made the `zig zen` command use text defined
in userland. I added `zig translate-c-2` which is a work-in-progress
reimplementation of translate-c in userland, which currently calls
`std.debug.panic("unimplemented")` and you can see the stack trace makes
it all the way back into the C++ main() function (Thanks LemonBoy for
improving that!).
This could potentially let us move other things into userland, such as
hashing algorithms, the entire cache system, .d file parsing, pretty
much anything that libuserland.a itself doesn't need to depend on.
This can also let us have `zig fmt` in stage1 without the overhead
of child process execution, and without the initial compilation delay
before it gets cached.
See #1964
2019-04-16 13:47:47 -07:00
|
|
|
.override_lib_dir = null,
|
2019-07-22 07:45:59 -07:00
|
|
|
.install_path = undefined,
|
2019-10-10 12:58:47 -07:00
|
|
|
.vcpkg_root = VcpkgRoot{ .Unattempted = {} },
|
2019-12-16 14:14:16 -08:00
|
|
|
.args = null,
|
2017-04-03 22:52:20 -07:00
|
|
|
};
|
2019-07-04 12:32:44 -07:00
|
|
|
try self.top_level_steps.append(&self.install_tls);
|
|
|
|
try self.top_level_steps.append(&self.uninstall_tls);
|
|
|
|
self.default_step = &self.install_tls.step;
|
2017-04-03 22:52:20 -07:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2019-07-04 12:32:44 -07:00
|
|
|
pub fn destroy(self: *Builder) void {
|
2017-04-13 14:21:00 -07:00
|
|
|
self.env_map.deinit();
|
|
|
|
self.top_level_steps.deinit();
|
2019-07-04 12:32:44 -07:00
|
|
|
self.allocator.destroy(self);
|
2017-03-31 02:48:15 -07:00
|
|
|
}
|
|
|
|
|
2019-09-03 13:19:10 -07:00
|
|
|
/// This function is intended to be called by std/special/build_runner.zig, not a build.zig file.
|
2019-07-04 12:32:44 -07:00
|
|
|
pub fn setInstallPrefix(self: *Builder, optional_prefix: ?[]const u8) void {
|
|
|
|
self.install_prefix = optional_prefix;
|
|
|
|
}
|
|
|
|
|
2019-09-03 13:19:10 -07:00
|
|
|
/// This function is intended to be called by std/special/build_runner.zig, not a build.zig file.
|
|
|
|
pub fn resolveInstallPrefix(self: *Builder) void {
|
2019-07-22 07:45:59 -07:00
|
|
|
if (self.dest_dir) |dest_dir| {
|
|
|
|
const install_prefix = self.install_prefix orelse "/usr";
|
2019-11-27 00:30:39 -08:00
|
|
|
self.install_path = fs.path.join(self.allocator, &[_][]const u8{ dest_dir, install_prefix }) catch unreachable;
|
2019-07-22 07:45:59 -07:00
|
|
|
} else {
|
|
|
|
const install_prefix = self.install_prefix orelse blk: {
|
|
|
|
const p = self.cache_root;
|
|
|
|
self.install_prefix = p;
|
|
|
|
break :blk p;
|
|
|
|
};
|
|
|
|
self.install_path = install_prefix;
|
|
|
|
}
|
2019-11-27 00:30:39 -08:00
|
|
|
self.lib_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "lib" }) catch unreachable;
|
|
|
|
self.exe_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "bin" }) catch unreachable;
|
2019-12-18 19:10:17 -08:00
|
|
|
self.h_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "include" }) catch unreachable;
|
2017-03-31 02:48:15 -07:00
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
|
2020-01-04 23:01:28 -08:00
|
|
|
return LibExeObjStep.createExecutable(
|
|
|
|
self,
|
|
|
|
name,
|
|
|
|
if (root_src) |p| FileSource{ .path = p } else null,
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn addExecutableFromWriteFileStep(
|
|
|
|
self: *Builder,
|
|
|
|
name: []const u8,
|
|
|
|
wfs: *WriteFileStep,
|
|
|
|
basename: []const u8,
|
|
|
|
) *LibExeObjStep {
|
|
|
|
return LibExeObjStep.createExecutable(self, name, @as(FileSource, .{
|
|
|
|
.write_file = .{
|
|
|
|
.step = wfs,
|
|
|
|
.basename = basename,
|
|
|
|
},
|
|
|
|
}), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn addExecutableSource(
|
|
|
|
self: *Builder,
|
|
|
|
name: []const u8,
|
|
|
|
root_src: ?FileSource,
|
|
|
|
) *LibExeObjStep {
|
2018-11-30 22:21:59 -08:00
|
|
|
return LibExeObjStep.createExecutable(self, name, root_src, false);
|
|
|
|
}
|
|
|
|
|
2019-02-25 08:37:54 -08:00
|
|
|
pub fn addObject(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
|
2020-01-04 23:01:28 -08:00
|
|
|
const root_src_param = if (root_src) |p| @as(FileSource, .{ .path = p }) else null;
|
|
|
|
return LibExeObjStep.createObject(self, name, root_src_param);
|
2017-04-20 22:56:12 -07:00
|
|
|
}
|
|
|
|
|
2020-01-05 10:08:18 -08:00
|
|
|
pub fn addObjectFromWriteFileStep(
|
|
|
|
self: *Builder,
|
|
|
|
name: []const u8,
|
|
|
|
wfs: *WriteFileStep,
|
|
|
|
basename: []const u8,
|
|
|
|
) *LibExeObjStep {
|
|
|
|
return LibExeObjStep.createObject(self, name, @as(FileSource, .{
|
|
|
|
.write_file = .{
|
|
|
|
.step = wfs,
|
|
|
|
.basename = basename,
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2018-10-15 15:23:47 -07:00
|
|
|
pub fn addSharedLibrary(self: *Builder, name: []const u8, root_src: ?[]const u8, ver: Version) *LibExeObjStep {
|
2020-01-04 23:01:28 -08:00
|
|
|
const root_src_param = if (root_src) |p| @as(FileSource, .{ .path = p }) else null;
|
|
|
|
return LibExeObjStep.createSharedLibrary(self, name, root_src_param, ver);
|
2017-04-20 22:56:12 -07:00
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn addStaticLibrary(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
|
2020-01-04 23:01:28 -08:00
|
|
|
const root_src_param = if (root_src) |p| @as(FileSource, .{ .path = p }) else null;
|
|
|
|
return LibExeObjStep.createStaticLibrary(self, name, root_src_param);
|
2017-04-20 22:56:12 -07:00
|
|
|
}
|
|
|
|
|
2019-02-25 08:37:54 -08:00
|
|
|
pub fn addTest(self: *Builder, root_src: []const u8) *LibExeObjStep {
|
2020-01-04 23:01:28 -08:00
|
|
|
return LibExeObjStep.createTest(self, "test", .{ .path = root_src });
|
2017-04-18 22:13:15 -07:00
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn addAssemble(self: *Builder, name: []const u8, src: []const u8) *LibExeObjStep {
|
2017-04-26 16:17:05 -07:00
|
|
|
const obj_step = LibExeObjStep.createObject(self, name, null);
|
|
|
|
obj_step.addAssemblyFile(src);
|
|
|
|
return obj_step;
|
2017-04-19 11:00:12 -07:00
|
|
|
}
|
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
/// Initializes a RunStep with argv, which must at least have the path to the
|
|
|
|
/// executable. More command line arguments can be added with `addArg`,
|
|
|
|
/// `addArgs`, and `addArtifactArg`.
|
|
|
|
/// Be careful using this function, as it introduces a system dependency.
|
|
|
|
/// To run an executable built with zig build, see `LibExeObjStep.run`.
|
|
|
|
pub fn addSystemCommand(self: *Builder, argv: []const []const u8) *RunStep {
|
|
|
|
assert(argv.len >= 1);
|
2019-12-08 19:53:51 -08:00
|
|
|
const run_step = RunStep.create(self, self.fmt("run {}", .{argv[0]}));
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
run_step.addArgs(argv);
|
|
|
|
return run_step;
|
|
|
|
}
|
|
|
|
|
2020-04-03 19:04:40 -07:00
|
|
|
pub fn dupe(self: *Builder, bytes: []const u8) []u8 {
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
return mem.dupe(self.allocator, u8, bytes) catch unreachable;
|
2017-04-13 14:21:00 -07:00
|
|
|
}
|
|
|
|
|
2020-04-03 19:04:40 -07:00
|
|
|
pub fn dupePath(self: *Builder, bytes: []const u8) []u8 {
|
2019-07-14 22:41:06 -07:00
|
|
|
const the_copy = self.dupe(bytes);
|
|
|
|
for (the_copy) |*byte| {
|
|
|
|
switch (byte.*) {
|
|
|
|
'/', '\\' => byte.* = fs.path.sep,
|
|
|
|
else => {},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return the_copy;
|
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn addWriteFile(self: *Builder, file_path: []const u8, data: []const u8) *WriteFileStep {
|
2020-01-04 23:01:28 -08:00
|
|
|
const write_file_step = self.addWriteFiles();
|
|
|
|
write_file_step.add(file_path, data);
|
|
|
|
return write_file_step;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn addWriteFiles(self: *Builder) *WriteFileStep {
|
2019-02-03 13:13:28 -08:00
|
|
|
const write_file_step = self.allocator.create(WriteFileStep) catch unreachable;
|
2020-01-04 23:01:28 -08:00
|
|
|
write_file_step.* = WriteFileStep.init(self);
|
2017-04-18 22:13:15 -07:00
|
|
|
return write_file_step;
|
|
|
|
}
|
|
|
|
|
2019-12-08 19:53:51 -08:00
|
|
|
pub fn addLog(self: *Builder, comptime format: []const u8, args: var) *LogStep {
|
2017-04-19 12:38:12 -07:00
|
|
|
const data = self.fmt(format, args);
|
2019-02-03 13:13:28 -08:00
|
|
|
const log_step = self.allocator.create(LogStep) catch unreachable;
|
|
|
|
log_step.* = LogStep.init(self, data);
|
2017-04-18 22:13:15 -07:00
|
|
|
return log_step;
|
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn addRemoveDirTree(self: *Builder, dir_path: []const u8) *RemoveDirStep {
|
2019-02-03 13:13:28 -08:00
|
|
|
const remove_dir_step = self.allocator.create(RemoveDirStep) catch unreachable;
|
|
|
|
remove_dir_step.* = RemoveDirStep.init(self, dir_path);
|
2017-04-19 23:26:36 -07:00
|
|
|
return remove_dir_step;
|
|
|
|
}
|
|
|
|
|
2019-02-26 15:10:40 -08:00
|
|
|
pub fn addFmt(self: *Builder, paths: []const []const u8) *FmtStep {
|
|
|
|
return FmtStep.create(self, paths);
|
|
|
|
}
|
|
|
|
|
2020-01-04 23:01:28 -08:00
|
|
|
pub fn addTranslateC(self: *Builder, source: FileSource) *TranslateCStep {
|
|
|
|
return TranslateCStep.create(self, source);
|
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn version(self: *const Builder, major: u32, minor: u32, patch: u32) Version {
|
2018-11-13 05:08:37 -08:00
|
|
|
return Version{
|
2017-04-13 14:21:00 -07:00
|
|
|
.major = major,
|
|
|
|
.minor = minor,
|
|
|
|
.patch = patch,
|
2017-12-21 21:50:30 -08:00
|
|
|
};
|
2017-04-13 14:21:00 -07:00
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn make(self: *Builder, step_names: []const []const u8) !void {
|
2018-09-11 15:15:08 -07:00
|
|
|
try self.makePath(self.cache_root);
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
var wanted_steps = ArrayList(*Step).init(self.allocator);
|
2017-04-13 14:21:00 -07:00
|
|
|
defer wanted_steps.deinit();
|
2017-04-03 01:58:19 -07:00
|
|
|
|
2017-04-13 14:21:00 -07:00
|
|
|
if (step_names.len == 0) {
|
2018-06-15 10:49:39 -07:00
|
|
|
try wanted_steps.append(self.default_step);
|
2017-04-13 14:21:00 -07:00
|
|
|
} else {
|
|
|
|
for (step_names) |step_name| {
|
2018-01-07 13:51:46 -08:00
|
|
|
const s = try self.getTopLevelStepByName(step_name);
|
2018-01-14 21:01:02 -08:00
|
|
|
try wanted_steps.append(s);
|
2017-04-06 02:34:04 -07:00
|
|
|
}
|
2017-04-13 14:21:00 -07:00
|
|
|
}
|
2017-04-06 02:34:04 -07:00
|
|
|
|
2020-03-30 11:23:22 -07:00
|
|
|
for (wanted_steps.span()) |s| {
|
2018-01-07 13:51:46 -08:00
|
|
|
try self.makeOneStep(s);
|
2017-04-13 14:21:00 -07:00
|
|
|
}
|
|
|
|
}
|
2017-04-03 01:58:19 -07:00
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn getInstallStep(self: *Builder) *Step {
|
2017-04-30 18:03:23 -07:00
|
|
|
return &self.install_tls.step;
|
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn getUninstallStep(self: *Builder) *Step {
|
2017-04-17 03:45:44 -07:00
|
|
|
return &self.uninstall_tls.step;
|
|
|
|
}
|
|
|
|
|
2018-11-13 05:08:37 -08:00
|
|
|
fn makeUninstall(uninstall_step: *Step) anyerror!void {
|
2017-04-18 22:13:15 -07:00
|
|
|
const uninstall_tls = @fieldParentPtr(TopLevelStep, "step", uninstall_step);
|
|
|
|
const self = @fieldParentPtr(Builder, "uninstall_tls", uninstall_tls);
|
2017-04-17 03:45:44 -07:00
|
|
|
|
2020-03-30 11:23:22 -07:00
|
|
|
for (self.installed_files.span()) |installed_file| {
|
2019-07-04 12:32:44 -07:00
|
|
|
const full_path = self.getInstallPath(installed_file.dir, installed_file.path);
|
2017-04-30 18:03:23 -07:00
|
|
|
if (self.verbose) {
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("rm {}\n", .{full_path});
|
2017-04-30 18:03:23 -07:00
|
|
|
}
|
2020-03-18 13:09:06 -07:00
|
|
|
fs.cwd().deleteTree(full_path) catch {};
|
2017-04-17 03:45:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO remove empty directories
|
|
|
|
}
|
|
|
|
|
2018-11-13 05:08:37 -08:00
|
|
|
fn makeOneStep(self: *Builder, s: *Step) anyerror!void {
|
2017-04-13 14:21:00 -07:00
|
|
|
if (s.loop_flag) {
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("Dependency loop detected:\n {}\n", .{s.name});
|
2017-04-13 14:21:00 -07:00
|
|
|
return error.DependencyLoopDetected;
|
|
|
|
}
|
|
|
|
s.loop_flag = true;
|
2017-04-03 01:58:19 -07:00
|
|
|
|
2020-03-30 11:23:22 -07:00
|
|
|
for (s.dependencies.span()) |dep| {
|
2018-01-07 14:28:20 -08:00
|
|
|
self.makeOneStep(dep) catch |err| {
|
2017-04-13 14:21:00 -07:00
|
|
|
if (err == error.DependencyLoopDetected) {
|
2019-12-08 19:53:51 -08:00
|
|
|
warn(" {}\n", .{s.name});
|
2017-04-03 22:52:20 -07:00
|
|
|
}
|
2017-04-13 14:21:00 -07:00
|
|
|
return err;
|
|
|
|
};
|
|
|
|
}
|
2017-04-03 22:52:20 -07:00
|
|
|
|
2017-04-13 14:21:00 -07:00
|
|
|
s.loop_flag = false;
|
2017-04-03 22:52:20 -07:00
|
|
|
|
2018-01-07 13:51:46 -08:00
|
|
|
try s.make();
|
2017-04-13 14:21:00 -07:00
|
|
|
}
|
2017-04-03 22:52:20 -07:00
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
fn getTopLevelStepByName(self: *Builder, name: []const u8) !*Step {
|
2020-03-30 11:23:22 -07:00
|
|
|
for (self.top_level_steps.span()) |top_level_step| {
|
2017-04-13 14:21:00 -07:00
|
|
|
if (mem.eql(u8, top_level_step.step.name, name)) {
|
|
|
|
return &top_level_step.step;
|
2017-04-06 02:34:04 -07:00
|
|
|
}
|
2017-04-03 22:52:20 -07:00
|
|
|
}
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("Cannot run step '{}' because it does not exist\n", .{name});
|
2017-04-13 14:21:00 -07:00
|
|
|
return error.InvalidStepName;
|
2017-04-03 22:52:20 -07:00
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn option(self: *Builder, comptime T: type, name: []const u8, description: []const u8) ?T {
|
2017-04-18 22:13:15 -07:00
|
|
|
const type_id = comptime typeToEnum(T);
|
2018-11-13 05:08:37 -08:00
|
|
|
const available_option = AvailableOption{
|
2017-04-06 02:34:04 -07:00
|
|
|
.name = name,
|
|
|
|
.type_id = type_id,
|
|
|
|
.description = description,
|
|
|
|
};
|
2018-01-08 21:07:01 -08:00
|
|
|
if ((self.available_options_map.put(name, available_option) catch unreachable) != null) {
|
2019-12-08 19:53:51 -08:00
|
|
|
panic("Option '{}' declared twice", .{name});
|
2017-04-06 02:34:04 -07:00
|
|
|
}
|
2018-01-08 21:07:01 -08:00
|
|
|
self.available_options_list.append(available_option) catch unreachable;
|
2017-04-06 02:34:04 -07:00
|
|
|
|
2018-06-09 22:13:51 -07:00
|
|
|
const entry = self.user_input_options.get(name) orelse return null;
|
2017-04-06 02:34:04 -07:00
|
|
|
entry.value.used = true;
|
|
|
|
switch (type_id) {
|
|
|
|
TypeId.Bool => switch (entry.value.value) {
|
|
|
|
UserValue.Flag => return true,
|
|
|
|
UserValue.Scalar => |s| {
|
|
|
|
if (mem.eql(u8, s, "true")) {
|
|
|
|
return true;
|
|
|
|
} else if (mem.eql(u8, s, "false")) {
|
|
|
|
return false;
|
|
|
|
} else {
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("Expected -D{} to be a boolean, but received '{}'\n", .{ name, s });
|
2017-04-06 02:34:04 -07:00
|
|
|
self.markInvalidUserInput();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
UserValue.List => {
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("Expected -D{} to be a boolean, but received a list.\n", .{name});
|
2017-04-06 02:34:04 -07:00
|
|
|
self.markInvalidUserInput();
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
},
|
2019-12-08 19:53:51 -08:00
|
|
|
TypeId.Int => panic("TODO integer options to build script", .{}),
|
|
|
|
TypeId.Float => panic("TODO float options to build script", .{}),
|
2020-05-16 07:36:18 -07:00
|
|
|
TypeId.Enum => switch (entry.value.value) {
|
|
|
|
UserValue.Flag => {
|
|
|
|
warn("Expected -D{} to be a string, but received a boolean.\n", .{name});
|
|
|
|
self.markInvalidUserInput();
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
UserValue.Scalar => |s| {
|
|
|
|
if (std.meta.stringToEnum(T, s)) |enum_lit| {
|
|
|
|
return enum_lit;
|
|
|
|
} else {
|
|
|
|
warn("Expected -D{} to be of type {}.\n", .{ name, @typeName(T) });
|
|
|
|
self.markInvalidUserInput();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
UserValue.List => {
|
|
|
|
warn("Expected -D{} to be a string, but received a list.\n", .{name});
|
|
|
|
self.markInvalidUserInput();
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
},
|
2017-04-18 22:13:15 -07:00
|
|
|
TypeId.String => switch (entry.value.value) {
|
|
|
|
UserValue.Flag => {
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("Expected -D{} to be a string, but received a boolean.\n", .{name});
|
2017-04-18 22:13:15 -07:00
|
|
|
self.markInvalidUserInput();
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
UserValue.List => {
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("Expected -D{} to be a string, but received a list.\n", .{name});
|
2017-04-18 22:13:15 -07:00
|
|
|
self.markInvalidUserInput();
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
UserValue.Scalar => |s| return s,
|
|
|
|
},
|
2019-12-19 05:34:38 -08:00
|
|
|
TypeId.List => switch (entry.value.value) {
|
|
|
|
UserValue.Flag => {
|
|
|
|
warn("Expected -D{} to be a list, but received a boolean.\n", .{name});
|
|
|
|
self.markInvalidUserInput();
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
UserValue.Scalar => |s| return &[_][]const u8{s},
|
2020-03-30 11:23:22 -07:00
|
|
|
UserValue.List => |lst| return lst.span(),
|
2019-12-19 05:34:38 -08:00
|
|
|
},
|
2017-04-06 02:34:04 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn step(self: *Builder, name: []const u8, description: []const u8) *Step {
|
2019-02-03 13:13:28 -08:00
|
|
|
const step_info = self.allocator.create(TopLevelStep) catch unreachable;
|
|
|
|
step_info.* = TopLevelStep{
|
2017-04-13 14:21:00 -07:00
|
|
|
.step = Step.initNoOp(name, self.allocator),
|
|
|
|
.description = description,
|
2019-02-03 13:13:28 -08:00
|
|
|
};
|
2018-01-08 21:07:01 -08:00
|
|
|
self.top_level_steps.append(step_info) catch unreachable;
|
2017-04-13 14:21:00 -07:00
|
|
|
return &step_info.step;
|
|
|
|
}
|
|
|
|
|
2019-07-04 12:32:44 -07:00
|
|
|
/// This provides the -Drelease option to the build user and does not give them the choice.
|
|
|
|
pub fn setPreferredReleaseMode(self: *Builder, mode: builtin.Mode) void {
|
|
|
|
if (self.release_mode != null) {
|
|
|
|
@panic("setPreferredReleaseMode must be called before standardReleaseOptions and may not be called twice");
|
|
|
|
}
|
2019-12-08 19:53:51 -08:00
|
|
|
const description = self.fmt("create a release build ({})", .{@tagName(mode)});
|
2019-07-04 12:32:44 -07:00
|
|
|
self.is_release = self.option(bool, "release", description) orelse false;
|
2019-07-04 14:43:56 -07:00
|
|
|
self.release_mode = if (self.is_release) mode else builtin.Mode.Debug;
|
2019-07-04 12:32:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// If you call this without first calling `setPreferredReleaseMode` then it gives the build user
|
|
|
|
/// the choice of what kind of release.
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn standardReleaseOptions(self: *Builder) builtin.Mode {
|
2017-05-09 18:20:09 -07:00
|
|
|
if (self.release_mode) |mode| return mode;
|
|
|
|
|
2018-06-09 22:13:51 -07:00
|
|
|
const release_safe = self.option(bool, "release-safe", "optimizations on and safety on") orelse false;
|
|
|
|
const release_fast = self.option(bool, "release-fast", "optimizations on and safety off") orelse false;
|
|
|
|
const release_small = self.option(bool, "release-small", "size optimizations on and safety off") orelse false;
|
2017-05-02 14:34:21 -07:00
|
|
|
|
2019-07-04 12:32:44 -07:00
|
|
|
const mode = if (release_safe and !release_fast and !release_small)
|
|
|
|
builtin.Mode.ReleaseSafe
|
|
|
|
else if (release_fast and !release_safe and !release_small)
|
|
|
|
builtin.Mode.ReleaseFast
|
|
|
|
else if (release_small and !release_fast and !release_safe)
|
|
|
|
builtin.Mode.ReleaseSmall
|
|
|
|
else if (!release_fast and !release_safe and !release_small)
|
|
|
|
builtin.Mode.Debug
|
|
|
|
else x: {
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("Multiple release modes (of -Drelease-safe, -Drelease-fast and -Drelease-small)", .{});
|
2017-05-02 14:34:21 -07:00
|
|
|
self.markInvalidUserInput();
|
2017-12-21 21:50:30 -08:00
|
|
|
break :x builtin.Mode.Debug;
|
2017-05-09 18:20:09 -07:00
|
|
|
};
|
2019-07-04 12:32:44 -07:00
|
|
|
self.is_release = mode != .Debug;
|
2017-05-09 18:20:09 -07:00
|
|
|
self.release_mode = mode;
|
|
|
|
return mode;
|
2017-05-02 14:34:21 -07:00
|
|
|
}
|
|
|
|
|
2020-02-25 22:18:23 -08:00
|
|
|
pub const StandardTargetOptionsArgs = struct {
|
|
|
|
whitelist: ?[]const CrossTarget = null,
|
|
|
|
|
2020-02-26 11:33:36 -08:00
|
|
|
default_target: CrossTarget = CrossTarget{},
|
2020-02-25 22:18:23 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Exposes standard `zig build` options for choosing a target.
|
|
|
|
pub fn standardTargetOptions(self: *Builder, args: StandardTargetOptionsArgs) CrossTarget {
|
|
|
|
const triple = self.option(
|
|
|
|
[]const u8,
|
|
|
|
"target",
|
2020-02-26 11:33:36 -08:00
|
|
|
"The CPU architecture, OS, and ABI to build for.",
|
2020-02-25 22:18:23 -08:00
|
|
|
) orelse return args.default_target;
|
|
|
|
|
|
|
|
// TODO add cpu and features as part of the target triple
|
|
|
|
|
2020-02-26 11:33:36 -08:00
|
|
|
var diags: CrossTarget.ParseOptions.Diagnostics = .{};
|
2020-02-25 22:18:23 -08:00
|
|
|
const selected_target = CrossTarget.parse(.{
|
|
|
|
.arch_os_abi = triple,
|
|
|
|
.diagnostics = &diags,
|
|
|
|
}) catch |err| switch (err) {
|
|
|
|
error.UnknownCpuModel => {
|
|
|
|
std.debug.warn("Unknown CPU: '{}'\nAvailable CPUs for architecture '{}':\n", .{
|
|
|
|
diags.cpu_name.?,
|
|
|
|
@tagName(diags.arch.?),
|
|
|
|
});
|
|
|
|
for (diags.arch.?.allCpuModels()) |cpu| {
|
|
|
|
std.debug.warn(" {}\n", .{cpu.name});
|
|
|
|
}
|
|
|
|
process.exit(1);
|
|
|
|
},
|
|
|
|
error.UnknownCpuFeature => {
|
|
|
|
std.debug.warn(
|
|
|
|
\\Unknown CPU feature: '{}'
|
|
|
|
\\Available CPU features for architecture '{}':
|
|
|
|
\\
|
|
|
|
, .{
|
|
|
|
diags.unknown_feature_name,
|
|
|
|
@tagName(diags.arch.?),
|
|
|
|
});
|
|
|
|
for (diags.arch.?.allFeaturesList()) |feature| {
|
|
|
|
std.debug.warn(" {}: {}\n", .{ feature.name, feature.description });
|
|
|
|
}
|
|
|
|
process.exit(1);
|
|
|
|
},
|
2020-02-26 11:33:36 -08:00
|
|
|
error.UnknownOperatingSystem => {
|
|
|
|
std.debug.warn(
|
|
|
|
\\Unknown OS: '{}'
|
|
|
|
\\Available operating systems:
|
|
|
|
\\
|
|
|
|
, .{diags.os_name});
|
|
|
|
inline for (std.meta.fields(std.Target.Os.Tag)) |field| {
|
|
|
|
std.debug.warn(" {}\n", .{field.name});
|
|
|
|
}
|
|
|
|
process.exit(1);
|
|
|
|
},
|
|
|
|
else => |e| {
|
|
|
|
std.debug.warn("Unable to parse target '{}': {}\n", .{ triple, @errorName(e) });
|
|
|
|
process.exit(1);
|
|
|
|
},
|
2020-02-25 22:18:23 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
const selected_canonicalized_triple = selected_target.zigTriple(self.allocator) catch unreachable;
|
|
|
|
|
|
|
|
if (args.whitelist) |list| whitelist_check: {
|
|
|
|
// Make sure it's a match of one of the list.
|
|
|
|
for (list) |t| {
|
|
|
|
const t_triple = t.zigTriple(self.allocator) catch unreachable;
|
|
|
|
if (mem.eql(u8, t_triple, selected_canonicalized_triple)) {
|
|
|
|
break :whitelist_check;
|
2019-07-09 10:31:42 -07:00
|
|
|
}
|
|
|
|
}
|
2020-02-25 22:18:23 -08:00
|
|
|
std.debug.warn("Chosen target '{}' does not match one of the supported targets:\n", .{
|
|
|
|
selected_canonicalized_triple,
|
|
|
|
});
|
|
|
|
for (list) |t| {
|
|
|
|
const t_triple = t.zigTriple(self.allocator) catch unreachable;
|
2020-02-26 11:33:36 -08:00
|
|
|
std.debug.warn(" {}\n", .{t_triple});
|
2020-02-25 22:18:23 -08:00
|
|
|
}
|
|
|
|
// TODO instead of process exit, return error and have a zig build flag implemented by
|
|
|
|
// the build runner that turns process exits into error return traces
|
|
|
|
process.exit(1);
|
2019-07-09 10:31:42 -07:00
|
|
|
}
|
2020-02-25 22:18:23 -08:00
|
|
|
|
|
|
|
return selected_target;
|
2019-07-09 10:31:42 -07:00
|
|
|
}
|
|
|
|
|
2018-08-03 14:22:17 -07:00
|
|
|
pub fn addUserInputOption(self: *Builder, name: []const u8, value: []const u8) !bool {
|
|
|
|
const gop = try self.user_input_options.getOrPut(name);
|
|
|
|
if (!gop.found_existing) {
|
2018-11-13 05:08:37 -08:00
|
|
|
gop.kv.value = UserInputOption{
|
2018-08-03 14:22:17 -07:00
|
|
|
.name = name,
|
2018-11-13 05:08:37 -08:00
|
|
|
.value = UserValue{ .Scalar = value },
|
2018-08-03 14:22:17 -07:00
|
|
|
.used = false,
|
|
|
|
};
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// option already exists
|
|
|
|
switch (gop.kv.value.value) {
|
|
|
|
UserValue.Scalar => |s| {
|
|
|
|
// turn it into a list
|
|
|
|
var list = ArrayList([]const u8).init(self.allocator);
|
|
|
|
list.append(s) catch unreachable;
|
|
|
|
list.append(value) catch unreachable;
|
2018-11-13 05:08:37 -08:00
|
|
|
_ = self.user_input_options.put(name, UserInputOption{
|
2018-08-03 14:22:17 -07:00
|
|
|
.name = name,
|
2018-11-13 05:08:37 -08:00
|
|
|
.value = UserValue{ .List = list },
|
2018-08-03 14:22:17 -07:00
|
|
|
.used = false,
|
|
|
|
}) catch unreachable;
|
|
|
|
},
|
|
|
|
UserValue.List => |*list| {
|
|
|
|
// append to the list
|
|
|
|
list.append(value) catch unreachable;
|
2018-11-13 05:08:37 -08:00
|
|
|
_ = self.user_input_options.put(name, UserInputOption{
|
2018-08-03 14:22:17 -07:00
|
|
|
.name = name,
|
2018-11-13 05:08:37 -08:00
|
|
|
.value = UserValue{ .List = list.* },
|
2018-08-03 14:22:17 -07:00
|
|
|
.used = false,
|
|
|
|
}) catch unreachable;
|
|
|
|
},
|
|
|
|
UserValue.Flag => {
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("Option '-D{}={}' conflicts with flag '-D{}'.\n", .{ name, value, name });
|
2018-08-03 14:22:17 -07:00
|
|
|
return true;
|
|
|
|
},
|
2017-04-06 02:34:04 -07:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-08-03 14:22:17 -07:00
|
|
|
pub fn addUserInputFlag(self: *Builder, name: []const u8) !bool {
|
|
|
|
const gop = try self.user_input_options.getOrPut(name);
|
|
|
|
if (!gop.found_existing) {
|
2018-11-13 05:08:37 -08:00
|
|
|
gop.kv.value = UserInputOption{
|
2018-08-03 14:22:17 -07:00
|
|
|
.name = name,
|
2018-11-13 05:08:37 -08:00
|
|
|
.value = UserValue{ .Flag = {} },
|
2018-08-03 14:22:17 -07:00
|
|
|
.used = false,
|
|
|
|
};
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// option already exists
|
|
|
|
switch (gop.kv.value.value) {
|
|
|
|
UserValue.Scalar => |s| {
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("Flag '-D{}' conflicts with option '-D{}={}'.\n", .{ name, name, s });
|
2018-08-03 14:22:17 -07:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
UserValue.List => {
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("Flag '-D{}' conflicts with multiple options of the same name.\n", .{name});
|
2018-08-03 14:22:17 -07:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
UserValue.Flag => {},
|
2017-04-06 02:34:04 -07:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-25 01:10:11 -08:00
|
|
|
fn typeToEnum(comptime T: type) TypeId {
|
2020-02-24 13:03:30 -08:00
|
|
|
return switch (@typeInfo(T)) {
|
|
|
|
.Int => .Int,
|
|
|
|
.Float => .Float,
|
|
|
|
.Bool => .Bool,
|
2020-05-16 07:36:18 -07:00
|
|
|
.Enum => .Enum,
|
2017-05-17 09:26:35 -07:00
|
|
|
else => switch (T) {
|
2020-02-24 13:03:30 -08:00
|
|
|
[]const u8 => .String,
|
|
|
|
[]const []const u8 => .List,
|
2017-05-17 09:26:35 -07:00
|
|
|
else => @compileError("Unsupported type: " ++ @typeName(T)),
|
|
|
|
},
|
2017-12-21 21:50:30 -08:00
|
|
|
};
|
2017-04-06 02:34:04 -07:00
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
fn markInvalidUserInput(self: *Builder) void {
|
2017-04-06 02:34:04 -07:00
|
|
|
self.invalid_user_input = true;
|
|
|
|
}
|
|
|
|
|
2018-01-25 01:10:11 -08:00
|
|
|
pub fn typeIdName(id: TypeId) []const u8 {
|
2017-04-06 02:34:04 -07:00
|
|
|
return switch (id) {
|
2020-02-24 13:03:30 -08:00
|
|
|
.Bool => "bool",
|
|
|
|
.Int => "int",
|
|
|
|
.Float => "float",
|
2020-05-16 07:36:18 -07:00
|
|
|
.Enum => "enum",
|
2020-02-24 13:03:30 -08:00
|
|
|
.String => "string",
|
|
|
|
.List => "list",
|
2017-04-06 02:34:04 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn validateUserInputDidItFail(self: *Builder) bool {
|
2017-04-06 02:34:04 -07:00
|
|
|
// make sure all args are used
|
|
|
|
var it = self.user_input_options.iterator();
|
|
|
|
while (true) {
|
2018-06-09 22:13:51 -07:00
|
|
|
const entry = it.next() orelse break;
|
2017-04-06 02:34:04 -07:00
|
|
|
if (!entry.value.used) {
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("Invalid option: -D{}\n\n", .{entry.key});
|
2017-04-06 02:34:04 -07:00
|
|
|
self.markInvalidUserInput();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return self.invalid_user_input;
|
|
|
|
}
|
2017-04-16 23:58:42 -07:00
|
|
|
|
2020-04-03 19:04:40 -07:00
|
|
|
pub fn spawnChild(self: *Builder, argv: []const []const u8) !void {
|
2018-10-15 15:23:47 -07:00
|
|
|
return self.spawnChildEnvMap(null, self.env_map, argv);
|
2017-04-17 00:20:56 -07:00
|
|
|
}
|
|
|
|
|
2018-01-25 01:10:11 -08:00
|
|
|
fn printCmd(cwd: ?[]const u8, argv: []const []const u8) void {
|
2019-12-08 19:53:51 -08:00
|
|
|
if (cwd) |yes_cwd| warn("cd {} && ", .{yes_cwd});
|
2017-10-25 20:10:41 -07:00
|
|
|
for (argv) |arg| {
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("{} ", .{arg});
|
2017-10-25 20:10:41 -07:00
|
|
|
}
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("\n", .{});
|
2017-10-25 20:10:41 -07:00
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
fn spawnChildEnvMap(self: *Builder, cwd: ?[]const u8, env_map: *const BufMap, argv: []const []const u8) !void {
|
2017-04-16 23:58:42 -07:00
|
|
|
if (self.verbose) {
|
2017-10-25 20:10:41 -07:00
|
|
|
printCmd(cwd, argv);
|
2017-04-16 23:58:42 -07:00
|
|
|
}
|
|
|
|
|
2019-05-26 10:17:34 -07:00
|
|
|
const child = std.ChildProcess.init(argv, self.allocator) catch unreachable;
|
2017-09-25 22:01:49 -07:00
|
|
|
defer child.deinit();
|
2017-04-16 23:58:42 -07:00
|
|
|
|
2017-09-25 22:01:49 -07:00
|
|
|
child.cwd = cwd;
|
|
|
|
child.env_map = env_map;
|
|
|
|
|
2018-01-07 14:28:20 -08:00
|
|
|
const term = child.spawnAndWait() catch |err| {
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("Unable to spawn {}: {}\n", .{ argv[0], @errorName(err) });
|
2017-04-20 22:56:12 -07:00
|
|
|
return err;
|
|
|
|
};
|
2017-09-25 22:01:49 -07:00
|
|
|
|
2017-04-16 23:58:42 -07:00
|
|
|
switch (term) {
|
2019-05-26 10:17:34 -07:00
|
|
|
.Exited => |code| {
|
2017-04-16 23:58:42 -07:00
|
|
|
if (code != 0) {
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("The following command exited with error code {}:\n", .{code});
|
2017-10-25 20:10:41 -07:00
|
|
|
printCmd(cwd, argv);
|
2017-04-20 22:56:12 -07:00
|
|
|
return error.UncleanExit;
|
2017-04-16 23:58:42 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
else => {
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("The following command terminated unexpectedly:\n", .{});
|
2017-10-25 20:10:41 -07:00
|
|
|
printCmd(cwd, argv);
|
|
|
|
|
2017-04-20 22:56:12 -07:00
|
|
|
return error.UncleanExit;
|
2017-04-16 23:58:42 -07:00
|
|
|
},
|
2017-12-21 21:50:30 -08:00
|
|
|
}
|
2017-04-16 23:58:42 -07:00
|
|
|
}
|
2017-04-17 03:45:44 -07:00
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn makePath(self: *Builder, path: []const u8) !void {
|
2020-01-15 18:21:00 -08:00
|
|
|
fs.cwd().makePath(self.pathFromRoot(path)) catch |err| {
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("Unable to create path {}: {}\n", .{ path, @errorName(err) });
|
2017-04-30 10:01:35 -07:00
|
|
|
return err;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn installArtifact(self: *Builder, artifact: *LibExeObjStep) void {
|
2017-04-30 19:09:44 -07:00
|
|
|
self.getInstallStep().dependOn(&self.addInstallArtifact(artifact).step);
|
2017-04-17 03:45:44 -07:00
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn addInstallArtifact(self: *Builder, artifact: *LibExeObjStep) *InstallArtifactStep {
|
2017-09-17 23:50:51 -07:00
|
|
|
return InstallArtifactStep.create(self, artifact);
|
2017-04-30 18:03:23 -07:00
|
|
|
}
|
|
|
|
|
2019-07-04 12:32:44 -07:00
|
|
|
///`dest_rel_path` is relative to prefix path
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn installFile(self: *Builder, src_path: []const u8, dest_rel_path: []const u8) void {
|
2019-07-04 12:32:44 -07:00
|
|
|
self.getInstallStep().dependOn(&self.addInstallFileWithDir(src_path, .Prefix, dest_rel_path).step);
|
|
|
|
}
|
|
|
|
|
2019-07-14 00:06:20 -07:00
|
|
|
pub fn installDirectory(self: *Builder, options: InstallDirectoryOptions) void {
|
|
|
|
self.getInstallStep().dependOn(&self.addInstallDirectory(options).step);
|
|
|
|
}
|
|
|
|
|
2019-07-04 12:32:44 -07:00
|
|
|
///`dest_rel_path` is relative to bin path
|
|
|
|
pub fn installBinFile(self: *Builder, src_path: []const u8, dest_rel_path: []const u8) void {
|
|
|
|
self.getInstallStep().dependOn(&self.addInstallFileWithDir(src_path, .Bin, dest_rel_path).step);
|
2017-04-30 18:03:23 -07:00
|
|
|
}
|
|
|
|
|
2019-07-04 12:32:44 -07:00
|
|
|
///`dest_rel_path` is relative to lib path
|
|
|
|
pub fn installLibFile(self: *Builder, src_path: []const u8, dest_rel_path: []const u8) void {
|
|
|
|
self.getInstallStep().dependOn(&self.addInstallFileWithDir(src_path, .Lib, dest_rel_path).step);
|
|
|
|
}
|
|
|
|
|
2020-01-21 14:32:00 -08:00
|
|
|
pub fn installRaw(self: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8) void {
|
|
|
|
self.getInstallStep().dependOn(&self.addInstallRaw(artifact, dest_filename).step);
|
|
|
|
}
|
|
|
|
|
2019-07-04 12:32:44 -07:00
|
|
|
///`dest_rel_path` is relative to install prefix path
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn addInstallFile(self: *Builder, src_path: []const u8, dest_rel_path: []const u8) *InstallFileStep {
|
2019-07-04 12:32:44 -07:00
|
|
|
return self.addInstallFileWithDir(src_path, .Prefix, dest_rel_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
///`dest_rel_path` is relative to bin path
|
|
|
|
pub fn addInstallBinFile(self: *Builder, src_path: []const u8, dest_rel_path: []const u8) *InstallFileStep {
|
|
|
|
return self.addInstallFileWithDir(src_path, .Bin, dest_rel_path);
|
|
|
|
}
|
2017-04-17 03:45:44 -07:00
|
|
|
|
2019-07-04 12:32:44 -07:00
|
|
|
///`dest_rel_path` is relative to lib path
|
|
|
|
pub fn addInstallLibFile(self: *Builder, src_path: []const u8, dest_rel_path: []const u8) *InstallFileStep {
|
|
|
|
return self.addInstallFileWithDir(src_path, .Lib, dest_rel_path);
|
|
|
|
}
|
|
|
|
|
2020-01-21 14:32:00 -08:00
|
|
|
pub fn addInstallRaw(self: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8) *InstallRawStep {
|
|
|
|
return InstallRawStep.create(self, artifact, dest_filename);
|
|
|
|
}
|
|
|
|
|
2019-07-04 12:32:44 -07:00
|
|
|
pub fn addInstallFileWithDir(
|
|
|
|
self: *Builder,
|
|
|
|
src_path: []const u8,
|
|
|
|
install_dir: InstallDir,
|
|
|
|
dest_rel_path: []const u8,
|
|
|
|
) *InstallFileStep {
|
2019-02-03 13:13:28 -08:00
|
|
|
const install_step = self.allocator.create(InstallFileStep) catch unreachable;
|
2019-07-04 12:32:44 -07:00
|
|
|
install_step.* = InstallFileStep.init(self, src_path, install_dir, dest_rel_path);
|
2017-04-17 03:45:44 -07:00
|
|
|
return install_step;
|
|
|
|
}
|
|
|
|
|
2019-07-14 00:06:20 -07:00
|
|
|
pub fn addInstallDirectory(self: *Builder, options: InstallDirectoryOptions) *InstallDirStep {
|
|
|
|
const install_step = self.allocator.create(InstallDirStep) catch unreachable;
|
|
|
|
install_step.* = InstallDirStep.init(self, options);
|
|
|
|
return install_step;
|
|
|
|
}
|
|
|
|
|
2019-07-04 12:32:44 -07:00
|
|
|
pub fn pushInstalledFile(self: *Builder, dir: InstallDir, dest_rel_path: []const u8) void {
|
|
|
|
self.installed_files.append(InstalledFile{
|
|
|
|
.dir = dir,
|
|
|
|
.path = dest_rel_path,
|
|
|
|
}) catch unreachable;
|
2017-04-17 03:45:44 -07:00
|
|
|
}
|
|
|
|
|
2020-04-03 19:04:40 -07:00
|
|
|
pub fn updateFile(self: *Builder, source_path: []const u8, dest_path: []const u8) !void {
|
2017-04-30 19:09:44 -07:00
|
|
|
if (self.verbose) {
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("cp {} {} ", .{ source_path, dest_path });
|
2017-04-30 19:09:44 -07:00
|
|
|
}
|
2020-03-19 11:38:21 -07:00
|
|
|
const cwd = fs.cwd();
|
|
|
|
const prev_status = try fs.Dir.updateFile(cwd, source_path, cwd, dest_path, .{});
|
2019-07-14 00:06:20 -07:00
|
|
|
if (self.verbose) switch (prev_status) {
|
2019-12-08 19:53:51 -08:00
|
|
|
.stale => warn("# installed\n", .{}),
|
|
|
|
.fresh => warn("# up-to-date\n", .{}),
|
2017-04-17 03:45:44 -07:00
|
|
|
};
|
|
|
|
}
|
2017-04-18 22:13:15 -07:00
|
|
|
|
2020-04-03 19:04:40 -07:00
|
|
|
pub fn pathFromRoot(self: *Builder, rel_path: []const u8) []u8 {
|
2019-11-27 00:30:39 -08:00
|
|
|
return fs.path.resolve(self.allocator, &[_][]const u8{ self.build_root, rel_path }) catch unreachable;
|
2017-04-18 22:13:15 -07:00
|
|
|
}
|
2017-04-19 12:38:12 -07:00
|
|
|
|
2019-12-08 19:53:51 -08:00
|
|
|
pub fn fmt(self: *Builder, comptime format: []const u8, args: var) []u8 {
|
2018-01-08 21:07:01 -08:00
|
|
|
return fmt_lib.allocPrint(self.allocator, format, args) catch unreachable;
|
2017-04-19 12:38:12 -07:00
|
|
|
}
|
2017-10-15 22:14:28 -07:00
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn findProgram(self: *Builder, names: []const []const u8, paths: []const []const u8) ![]const u8 {
|
2017-12-23 17:21:57 -08:00
|
|
|
// TODO report error for ambiguous situations
|
2020-02-25 22:18:23 -08:00
|
|
|
const exe_extension = @as(CrossTarget, .{}).exeFileExt();
|
2020-03-30 11:23:22 -07:00
|
|
|
for (self.search_prefixes.span()) |search_prefix| {
|
2017-12-23 17:21:57 -08:00
|
|
|
for (names) |name| {
|
2019-05-26 10:17:34 -07:00
|
|
|
if (fs.path.isAbsolute(name)) {
|
2017-12-23 17:21:57 -08:00
|
|
|
return name;
|
|
|
|
}
|
2019-12-08 19:53:51 -08:00
|
|
|
const full_path = try fs.path.join(self.allocator, &[_][]const u8{
|
|
|
|
search_prefix,
|
|
|
|
"bin",
|
|
|
|
self.fmt("{}{}", .{ name, exe_extension }),
|
|
|
|
});
|
2019-07-31 19:28:25 -07:00
|
|
|
return fs.realpathAlloc(self.allocator, full_path) catch continue;
|
2017-12-23 17:21:57 -08:00
|
|
|
}
|
|
|
|
}
|
2017-12-12 13:03:20 -08:00
|
|
|
if (self.env_map.get("PATH")) |PATH| {
|
|
|
|
for (names) |name| {
|
2019-05-26 10:17:34 -07:00
|
|
|
if (fs.path.isAbsolute(name)) {
|
2017-12-12 13:03:20 -08:00
|
|
|
return name;
|
|
|
|
}
|
2019-11-27 00:30:39 -08:00
|
|
|
var it = mem.tokenize(PATH, &[_]u8{fs.path.delimiter});
|
2017-12-12 13:03:20 -08:00
|
|
|
while (it.next()) |path| {
|
2019-12-08 19:53:51 -08:00
|
|
|
const full_path = try fs.path.join(self.allocator, &[_][]const u8{
|
|
|
|
path,
|
|
|
|
self.fmt("{}{}", .{ name, exe_extension }),
|
|
|
|
});
|
2019-07-31 19:28:25 -07:00
|
|
|
return fs.realpathAlloc(self.allocator, full_path) catch continue;
|
2017-12-12 13:03:20 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (names) |name| {
|
2019-05-26 10:17:34 -07:00
|
|
|
if (fs.path.isAbsolute(name)) {
|
2017-12-12 13:03:20 -08:00
|
|
|
return name;
|
|
|
|
}
|
|
|
|
for (paths) |path| {
|
2019-12-08 19:53:51 -08:00
|
|
|
const full_path = try fs.path.join(self.allocator, &[_][]const u8{
|
|
|
|
path,
|
|
|
|
self.fmt("{}{}", .{ name, exe_extension }),
|
|
|
|
});
|
2019-07-31 19:28:25 -07:00
|
|
|
return fs.realpathAlloc(self.allocator, full_path) catch continue;
|
2017-12-12 13:03:20 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return error.FileNotFound;
|
|
|
|
}
|
|
|
|
|
2019-09-23 10:33:43 -07:00
|
|
|
pub fn execAllowFail(
|
|
|
|
self: *Builder,
|
|
|
|
argv: []const []const u8,
|
|
|
|
out_code: *u8,
|
|
|
|
stderr_behavior: std.ChildProcess.StdIo,
|
|
|
|
) ![]u8 {
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
assert(argv.len != 0);
|
|
|
|
|
2019-10-09 12:23:50 -07:00
|
|
|
const max_output_size = 400 * 1024;
|
2019-05-26 10:17:34 -07:00
|
|
|
const child = try std.ChildProcess.init(argv, self.allocator);
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
defer child.deinit();
|
|
|
|
|
2019-05-26 10:17:34 -07:00
|
|
|
child.stdin_behavior = .Ignore;
|
|
|
|
child.stdout_behavior = .Pipe;
|
2019-09-23 10:33:43 -07:00
|
|
|
child.stderr_behavior = stderr_behavior;
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
|
|
|
|
try child.spawn();
|
|
|
|
|
2020-03-10 17:22:30 -07:00
|
|
|
const stdout = try child.stdout.?.inStream().readAllAlloc(self.allocator, max_output_size);
|
2020-02-06 21:11:57 -08:00
|
|
|
errdefer self.allocator.free(stdout);
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
|
2019-09-23 10:33:43 -07:00
|
|
|
const term = try child.wait();
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
switch (term) {
|
2019-05-26 10:17:34 -07:00
|
|
|
.Exited => |code| {
|
2017-12-12 13:03:20 -08:00
|
|
|
if (code != 0) {
|
2019-09-23 10:33:43 -07:00
|
|
|
out_code.* = @truncate(u8, code);
|
|
|
|
return error.ExitCodeFailure;
|
2017-12-12 13:03:20 -08:00
|
|
|
}
|
2020-02-06 21:11:57 -08:00
|
|
|
return stdout;
|
2017-12-12 13:03:20 -08:00
|
|
|
},
|
2019-07-03 11:17:43 -07:00
|
|
|
.Signal, .Stopped, .Unknown => |code| {
|
2019-09-23 10:33:43 -07:00
|
|
|
out_code.* = @truncate(u8, code);
|
|
|
|
return error.ProcessTerminated;
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-07 10:40:17 -08:00
|
|
|
pub fn execFromStep(self: *Builder, argv: []const []const u8, src_step: ?*Step) ![]u8 {
|
2019-09-23 10:33:43 -07:00
|
|
|
assert(argv.len != 0);
|
|
|
|
|
|
|
|
if (self.verbose) {
|
|
|
|
printCmd(null, argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
var code: u8 = undefined;
|
|
|
|
return self.execAllowFail(argv, &code, .Inherit) catch |err| switch (err) {
|
|
|
|
error.FileNotFound => {
|
2020-01-07 10:40:17 -08:00
|
|
|
if (src_step) |s| warn("{}...", .{s.name});
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("Unable to spawn the following command: file not found\n", .{});
|
2019-09-23 10:33:43 -07:00
|
|
|
printCmd(null, argv);
|
|
|
|
std.os.exit(@truncate(u8, code));
|
|
|
|
},
|
|
|
|
error.ExitCodeFailure => {
|
2020-01-07 10:40:17 -08:00
|
|
|
if (src_step) |s| warn("{}...", .{s.name});
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("The following command exited with error code {}:\n", .{code});
|
2019-09-23 10:33:43 -07:00
|
|
|
printCmd(null, argv);
|
|
|
|
std.os.exit(@truncate(u8, code));
|
|
|
|
},
|
|
|
|
error.ProcessTerminated => {
|
2020-01-07 10:40:17 -08:00
|
|
|
if (src_step) |s| warn("{}...", .{s.name});
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("The following command terminated unexpectedly:\n", .{});
|
2017-12-12 13:03:20 -08:00
|
|
|
printCmd(null, argv);
|
2019-07-03 11:17:43 -07:00
|
|
|
std.os.exit(@truncate(u8, code));
|
2017-12-12 13:03:20 -08:00
|
|
|
},
|
2019-09-23 10:33:43 -07:00
|
|
|
else => |e| return e,
|
|
|
|
};
|
2017-12-12 13:03:20 -08:00
|
|
|
}
|
2017-12-23 17:21:57 -08:00
|
|
|
|
2020-01-07 10:40:17 -08:00
|
|
|
pub fn exec(self: *Builder, argv: []const []const u8) ![]u8 {
|
|
|
|
return self.execFromStep(argv, null);
|
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn addSearchPrefix(self: *Builder, search_prefix: []const u8) void {
|
2018-01-08 21:07:01 -08:00
|
|
|
self.search_prefixes.append(search_prefix) catch unreachable;
|
2017-12-23 17:21:57 -08:00
|
|
|
}
|
2019-07-04 12:32:44 -07:00
|
|
|
|
2020-05-08 14:31:11 -07:00
|
|
|
pub fn getInstallPath(self: *Builder, dir: InstallDir, dest_rel_path: []const u8) []const u8 {
|
2019-07-04 12:32:44 -07:00
|
|
|
const base_dir = switch (dir) {
|
2019-07-22 07:45:59 -07:00
|
|
|
.Prefix => self.install_path,
|
2019-09-03 13:19:10 -07:00
|
|
|
.Bin => self.exe_dir,
|
|
|
|
.Lib => self.lib_dir,
|
2019-12-18 19:10:17 -08:00
|
|
|
.Header => self.h_dir,
|
2019-07-04 12:32:44 -07:00
|
|
|
};
|
|
|
|
return fs.path.resolve(
|
|
|
|
self.allocator,
|
2019-11-27 00:30:39 -08:00
|
|
|
&[_][]const u8{ base_dir, dest_rel_path },
|
2019-07-04 12:32:44 -07:00
|
|
|
) catch unreachable;
|
|
|
|
}
|
2019-09-23 10:33:43 -07:00
|
|
|
|
|
|
|
fn execPkgConfigList(self: *Builder, out_code: *u8) ![]const PkgConfigPkg {
|
2019-11-27 00:30:39 -08:00
|
|
|
const stdout = try self.execAllowFail(&[_][]const u8{ "pkg-config", "--list-all" }, out_code, .Ignore);
|
2019-09-23 10:33:43 -07:00
|
|
|
var list = ArrayList(PkgConfigPkg).init(self.allocator);
|
|
|
|
var line_it = mem.tokenize(stdout, "\r\n");
|
|
|
|
while (line_it.next()) |line| {
|
|
|
|
if (mem.trim(u8, line, " \t").len == 0) continue;
|
|
|
|
var tok_it = mem.tokenize(line, " \t");
|
|
|
|
try list.append(PkgConfigPkg{
|
|
|
|
.name = tok_it.next() orelse return error.PkgConfigInvalidOutput,
|
|
|
|
.desc = tok_it.rest(),
|
|
|
|
});
|
|
|
|
}
|
2020-03-30 11:23:22 -07:00
|
|
|
return list.span();
|
2019-09-23 10:33:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn getPkgConfigList(self: *Builder) ![]const PkgConfigPkg {
|
|
|
|
if (self.pkg_config_pkg_list) |res| {
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
var code: u8 = undefined;
|
|
|
|
if (self.execPkgConfigList(&code)) |list| {
|
|
|
|
self.pkg_config_pkg_list = list;
|
|
|
|
return list;
|
|
|
|
} else |err| {
|
|
|
|
const result = switch (err) {
|
|
|
|
error.ProcessTerminated => error.PkgConfigCrashed,
|
|
|
|
error.ExitCodeFailure => error.PkgConfigFailed,
|
|
|
|
error.FileNotFound => error.PkgConfigNotInstalled,
|
2019-11-10 11:58:24 -08:00
|
|
|
error.InvalidName => error.PkgConfigNotInstalled,
|
2019-09-23 10:33:43 -07:00
|
|
|
error.PkgConfigInvalidOutput => error.PkgConfigInvalidOutput,
|
|
|
|
else => return err,
|
|
|
|
};
|
|
|
|
self.pkg_config_pkg_list = result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
2017-04-13 14:21:00 -07:00
|
|
|
};
|
2017-04-06 02:34:04 -07:00
|
|
|
|
2019-07-31 19:26:39 -07:00
|
|
|
test "builder.findProgram compiles" {
|
2020-02-26 18:29:31 -08:00
|
|
|
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
|
|
|
defer arena.deinit();
|
|
|
|
|
|
|
|
const builder = try Builder.create(&arena.allocator, "zig", "zig-cache", "zig-cache");
|
2020-01-29 20:06:26 -08:00
|
|
|
defer builder.destroy();
|
2019-11-27 00:30:39 -08:00
|
|
|
_ = builder.findProgram(&[_][]const u8{}, &[_][]const u8{}) catch null;
|
2019-07-31 19:26:39 -07:00
|
|
|
}
|
|
|
|
|
2020-02-25 22:18:23 -08:00
|
|
|
/// Deprecated. Use `std.builtin.Version`.
|
move types from builtin to std
* All the data types from `@import("builtin")` are moved to
`@import("std").builtin`. The target-related types are moved
to `std.Target`. This allows the data types to have methods, such as
`std.Target.current.isDarwin()`.
* `std.os.windows.subsystem` is moved to
`std.Target.current.subsystem`.
* Remove the concept of the panic package from the compiler
implementation. Instead, `std.builtin.panic` is always the panic
function. It checks for `@hasDecl(@import("root"), "panic")`,
or else provides a default implementation.
This is an important step for multibuilds (#3028). Without this change,
the types inside the builtin namespace look like different types, when
trying to merge builds with different target settings. With this change,
Zig can figure out that, e.g., `std.builtin.Os` (the enum type) from one
compilation and `std.builtin.Os` from another compilation are the same
type, even if the target OS value differs.
2019-10-23 15:43:24 -07:00
|
|
|
pub const Version = builtin.Version;
|
2017-09-23 14:59:30 -07:00
|
|
|
|
2020-02-25 22:18:23 -08:00
|
|
|
/// Deprecated. Use `std.zig.CrossTarget`.
|
|
|
|
pub const Target = std.zig.CrossTarget;
|
2017-04-03 01:58:19 -07:00
|
|
|
|
2020-01-31 10:02:12 -08:00
|
|
|
pub const Pkg = struct {
|
2018-12-05 05:10:09 -08:00
|
|
|
name: []const u8,
|
|
|
|
path: []const u8,
|
2020-04-27 09:26:12 -07:00
|
|
|
dependencies: ?[]const Pkg = null,
|
2018-12-05 05:10:09 -08:00
|
|
|
};
|
|
|
|
|
2019-02-25 08:37:54 -08:00
|
|
|
const CSourceFile = struct {
|
2020-01-04 23:01:28 -08:00
|
|
|
source: FileSource,
|
2019-02-25 08:37:54 -08:00
|
|
|
args: []const []const u8,
|
|
|
|
};
|
|
|
|
|
2019-03-11 12:22:05 -07:00
|
|
|
fn isLibCLibrary(name: []const u8) bool {
|
2019-06-09 16:24:24 -07:00
|
|
|
const libc_libraries = [_][]const u8{ "c", "m", "dl", "rt", "pthread" };
|
2019-03-11 12:22:05 -07:00
|
|
|
for (libc_libraries) |libc_lib_name| {
|
|
|
|
if (mem.eql(u8, name, libc_lib_name))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-01-04 23:01:28 -08:00
|
|
|
pub const FileSource = union(enum) {
|
|
|
|
/// Relative to build root
|
|
|
|
path: []const u8,
|
|
|
|
write_file: struct {
|
|
|
|
step: *WriteFileStep,
|
|
|
|
basename: []const u8,
|
|
|
|
},
|
|
|
|
translate_c: *TranslateCStep,
|
|
|
|
|
|
|
|
pub fn addStepDependencies(self: FileSource, step: *Step) void {
|
|
|
|
switch (self) {
|
|
|
|
.path => {},
|
|
|
|
.write_file => |wf| step.dependOn(&wf.step.step),
|
|
|
|
.translate_c => |tc| step.dependOn(&tc.step),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Should only be called during make()
|
|
|
|
pub fn getPath(self: FileSource, builder: *Builder) []const u8 {
|
|
|
|
return switch (self) {
|
|
|
|
.path => |p| builder.pathFromRoot(p),
|
|
|
|
.write_file => |wf| wf.step.getOutputPath(wf.basename),
|
|
|
|
.translate_c => |tc| tc.getOutputPath(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-11-13 05:08:37 -08:00
|
|
|
pub const LibExeObjStep = struct {
|
2017-04-13 14:21:00 -07:00
|
|
|
step: Step,
|
2018-05-31 07:56:59 -07:00
|
|
|
builder: *Builder,
|
2017-03-31 02:48:15 -07:00
|
|
|
name: []const u8,
|
2020-02-25 22:18:23 -08:00
|
|
|
target: CrossTarget = CrossTarget{},
|
2019-07-07 14:55:25 -07:00
|
|
|
linker_script: ?[]const u8 = null,
|
|
|
|
version_script: ?[]const u8 = null,
|
2017-09-17 23:50:51 -07:00
|
|
|
out_filename: []const u8,
|
2019-03-13 16:33:19 -07:00
|
|
|
is_dynamic: bool,
|
2017-04-20 22:56:12 -07:00
|
|
|
version: Version,
|
2017-09-17 23:50:51 -07:00
|
|
|
build_mode: builtin.Mode,
|
|
|
|
kind: Kind,
|
2017-04-30 19:09:44 -07:00
|
|
|
major_only_filename: []const u8,
|
|
|
|
name_only_filename: []const u8,
|
2017-09-17 23:50:51 -07:00
|
|
|
strip: bool,
|
2017-12-11 20:34:59 -08:00
|
|
|
lib_paths: ArrayList([]const u8),
|
2019-09-02 08:32:22 -07:00
|
|
|
framework_dirs: ArrayList([]const u8),
|
2017-09-23 14:59:30 -07:00
|
|
|
frameworks: BufSet,
|
2018-01-04 20:43:46 -08:00
|
|
|
verbose_link: bool,
|
2019-02-25 08:37:54 -08:00
|
|
|
verbose_cc: bool,
|
2020-02-18 18:59:43 -08:00
|
|
|
emit_llvm_ir: bool = false,
|
|
|
|
emit_asm: bool = false,
|
|
|
|
emit_bin: bool = true,
|
2020-03-20 15:33:36 -07:00
|
|
|
emit_h: bool = false,
|
2019-05-08 17:49:07 -07:00
|
|
|
bundle_compiler_rt: bool,
|
2019-05-08 19:43:11 -07:00
|
|
|
disable_stack_probing: bool,
|
2019-12-16 10:51:21 -08:00
|
|
|
disable_sanitize_c: bool,
|
2018-09-06 13:29:35 -07:00
|
|
|
c_std: Builder.CStd,
|
stage1 is now a hybrid of C++ and Zig
This modifies the build process of Zig to put all of the source files
into libcompiler.a, except main.cpp and userland.cpp.
Next, the build process links main.cpp, userland.cpp, and libcompiler.a
into zig1. userland.cpp is a shim for functions that will later be
replaced with self-hosted implementations.
Next, the build process uses zig1 to build src-self-hosted/stage1.zig
into libuserland.a, which does not depend on any of the things that
are shimmed in userland.cpp, such as translate-c.
Finally, the build process re-links main.cpp and libcompiler.a, except
with libuserland.a instead of userland.cpp. Now the shims are replaced
with .zig code. This provides all of the Zig standard library to the
stage1 C++ compiler, and enables us to move certain things to userland,
such as translate-c.
As a proof of concept I have made the `zig zen` command use text defined
in userland. I added `zig translate-c-2` which is a work-in-progress
reimplementation of translate-c in userland, which currently calls
`std.debug.panic("unimplemented")` and you can see the stack trace makes
it all the way back into the C++ main() function (Thanks LemonBoy for
improving that!).
This could potentially let us move other things into userland, such as
hashing algorithms, the entire cache system, .d file parsing, pretty
much anything that libuserland.a itself doesn't need to depend on.
This can also let us have `zig fmt` in stage1 without the overhead
of child process execution, and without the initial compilation delay
before it gets cached.
See #1964
2019-04-16 13:47:47 -07:00
|
|
|
override_lib_dir: ?[]const u8,
|
2019-03-02 07:38:27 -08:00
|
|
|
main_pkg_path: ?[]const u8,
|
2019-02-25 08:37:54 -08:00
|
|
|
exec_cmd_args: ?[]const ?[]const u8,
|
|
|
|
name_prefix: []const u8,
|
|
|
|
filter: ?[]const u8,
|
2019-04-05 11:54:37 -07:00
|
|
|
single_threaded: bool,
|
2020-05-05 12:18:04 -07:00
|
|
|
test_evented_io: bool = false,
|
2020-01-29 04:22:11 -08:00
|
|
|
code_model: builtin.CodeModel = .default,
|
2017-09-17 23:50:51 -07:00
|
|
|
|
2020-01-04 23:01:28 -08:00
|
|
|
root_src: ?FileSource,
|
2017-09-17 23:50:51 -07:00
|
|
|
out_h_filename: []const u8,
|
2019-02-25 10:34:25 -08:00
|
|
|
out_lib_filename: []const u8,
|
2019-07-08 15:48:03 -07:00
|
|
|
out_pdb_filename: []const u8,
|
2017-05-04 11:05:06 -07:00
|
|
|
packages: ArrayList(Pkg),
|
2020-03-06 20:35:06 -08:00
|
|
|
build_options_contents: std.ArrayList(u8),
|
2020-02-26 12:35:48 -08:00
|
|
|
system_linker_hack: bool = false,
|
2017-05-01 13:35:10 -07:00
|
|
|
|
2017-09-17 23:50:51 -07:00
|
|
|
object_src: []const u8,
|
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
link_objects: ArrayList(LinkObject),
|
|
|
|
include_dirs: ArrayList(IncludeDir),
|
2019-09-23 10:33:43 -07:00
|
|
|
c_macros: ArrayList([]const u8),
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
output_dir: ?[]const u8,
|
2019-09-21 20:55:56 -07:00
|
|
|
is_linking_libc: bool = false,
|
2019-10-10 12:58:47 -07:00
|
|
|
vcpkg_bin_path: ?[]const u8 = null,
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
|
2019-07-04 12:32:44 -07:00
|
|
|
installed_path: ?[]const u8,
|
|
|
|
install_step: ?*InstallArtifactStep,
|
|
|
|
|
2019-07-07 14:24:49 -07:00
|
|
|
libc_file: ?[]const u8 = null,
|
2019-07-07 08:31:07 -07:00
|
|
|
|
2019-07-18 17:03:38 -07:00
|
|
|
valgrind_support: ?bool = null,
|
|
|
|
|
2020-03-16 01:54:11 -07:00
|
|
|
/// Create a .eh_frame_hdr section and a PT_GNU_EH_FRAME segment in the ELF
|
|
|
|
/// file.
|
2020-01-03 21:28:58 -08:00
|
|
|
link_eh_frame_hdr: bool = false,
|
|
|
|
|
2020-03-16 01:54:11 -07:00
|
|
|
/// Place every function in its own section so that unused ones may be
|
|
|
|
/// safely garbage-collected during the linking phase.
|
|
|
|
link_function_sections: bool = false,
|
|
|
|
|
2019-09-21 20:55:56 -07:00
|
|
|
/// Uses system Wine installation to run cross compiled Windows build artifacts.
|
|
|
|
enable_wine: bool = false,
|
|
|
|
|
|
|
|
/// Uses system QEMU installation to run cross compiled foreign architecture build artifacts.
|
|
|
|
enable_qemu: bool = false,
|
|
|
|
|
2019-11-19 22:56:34 -08:00
|
|
|
/// Uses system Wasmtime installation to run cross compiled wasm/wasi build artifacts.
|
|
|
|
enable_wasmtime: bool = false,
|
|
|
|
|
2019-09-21 20:55:56 -07:00
|
|
|
/// After following the steps in https://github.com/ziglang/zig/wiki/Updating-libc#glibc,
|
|
|
|
/// this will be the directory $glibc-build-dir/install/glibcs
|
|
|
|
/// Given the example of the aarch64 target, this is the directory
|
|
|
|
/// that contains the path `aarch64-linux-gnu/lib/ld-linux-aarch64.so.1`.
|
|
|
|
glibc_multi_install_dir: ?[]const u8 = null,
|
|
|
|
|
2019-10-07 14:22:28 -07:00
|
|
|
/// Position Independent Code
|
|
|
|
force_pic: ?bool = null,
|
|
|
|
|
2019-10-18 11:11:28 -07:00
|
|
|
subsystem: ?builtin.SubSystem = null,
|
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
const LinkObject = union(enum) {
|
|
|
|
StaticPath: []const u8,
|
|
|
|
OtherStep: *LibExeObjStep,
|
|
|
|
SystemLib: []const u8,
|
2020-01-04 23:01:28 -08:00
|
|
|
AssemblyFile: FileSource,
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
CSourceFile: *CSourceFile,
|
|
|
|
};
|
|
|
|
|
|
|
|
const IncludeDir = union(enum) {
|
|
|
|
RawPath: []const u8,
|
2019-11-05 11:32:17 -08:00
|
|
|
RawPathSystem: []const u8,
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
OtherStep: *LibExeObjStep,
|
|
|
|
};
|
|
|
|
|
2018-11-13 05:08:37 -08:00
|
|
|
const Kind = enum {
|
2017-04-20 22:56:12 -07:00
|
|
|
Exe,
|
|
|
|
Lib,
|
2017-04-26 16:17:05 -07:00
|
|
|
Obj,
|
2019-02-25 08:37:54 -08:00
|
|
|
Test,
|
2017-04-20 22:56:12 -07:00
|
|
|
};
|
|
|
|
|
2020-01-04 23:01:28 -08:00
|
|
|
pub fn createSharedLibrary(builder: *Builder, name: []const u8, root_src: ?FileSource, ver: Version) *LibExeObjStep {
|
2019-02-03 13:13:28 -08:00
|
|
|
const self = builder.allocator.create(LibExeObjStep) catch unreachable;
|
2019-03-13 16:33:19 -07:00
|
|
|
self.* = initExtraArgs(builder, name, root_src, Kind.Lib, true, ver);
|
2017-04-26 16:17:05 -07:00
|
|
|
return self;
|
2017-04-20 22:56:12 -07:00
|
|
|
}
|
|
|
|
|
2020-01-04 23:01:28 -08:00
|
|
|
pub fn createStaticLibrary(builder: *Builder, name: []const u8, root_src: ?FileSource) *LibExeObjStep {
|
2019-02-03 13:13:28 -08:00
|
|
|
const self = builder.allocator.create(LibExeObjStep) catch unreachable;
|
2019-03-13 16:33:19 -07:00
|
|
|
self.* = initExtraArgs(builder, name, root_src, Kind.Lib, false, builder.version(0, 0, 0));
|
2017-04-26 16:17:05 -07:00
|
|
|
return self;
|
2017-04-20 22:56:12 -07:00
|
|
|
}
|
|
|
|
|
2020-01-04 23:01:28 -08:00
|
|
|
pub fn createObject(builder: *Builder, name: []const u8, root_src: ?FileSource) *LibExeObjStep {
|
2019-02-03 13:13:28 -08:00
|
|
|
const self = builder.allocator.create(LibExeObjStep) catch unreachable;
|
|
|
|
self.* = initExtraArgs(builder, name, root_src, Kind.Obj, false, builder.version(0, 0, 0));
|
2017-04-26 16:17:05 -07:00
|
|
|
return self;
|
2017-04-20 22:56:12 -07:00
|
|
|
}
|
2017-04-03 22:52:20 -07:00
|
|
|
|
2020-01-04 23:01:28 -08:00
|
|
|
pub fn createExecutable(builder: *Builder, name: []const u8, root_src: ?FileSource, is_dynamic: bool) *LibExeObjStep {
|
2019-02-03 13:13:28 -08:00
|
|
|
const self = builder.allocator.create(LibExeObjStep) catch unreachable;
|
2019-03-13 16:33:19 -07:00
|
|
|
self.* = initExtraArgs(builder, name, root_src, Kind.Exe, is_dynamic, builder.version(0, 0, 0));
|
2017-04-26 16:17:05 -07:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-01-04 23:01:28 -08:00
|
|
|
pub fn createTest(builder: *Builder, name: []const u8, root_src: FileSource) *LibExeObjStep {
|
2019-02-03 13:13:28 -08:00
|
|
|
const self = builder.allocator.create(LibExeObjStep) catch unreachable;
|
2019-02-25 08:37:54 -08:00
|
|
|
self.* = initExtraArgs(builder, name, root_src, Kind.Test, false, builder.version(0, 0, 0));
|
2017-09-17 23:50:51 -07:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-01-04 23:01:28 -08:00
|
|
|
fn initExtraArgs(
|
|
|
|
builder: *Builder,
|
|
|
|
name: []const u8,
|
|
|
|
root_src: ?FileSource,
|
|
|
|
kind: Kind,
|
|
|
|
is_dynamic: bool,
|
|
|
|
ver: Version,
|
|
|
|
) LibExeObjStep {
|
2019-09-03 13:19:10 -07:00
|
|
|
if (mem.indexOf(u8, name, "/") != null or mem.indexOf(u8, name, "\\") != null) {
|
2019-12-08 19:53:51 -08:00
|
|
|
panic("invalid name: '{}'. It looks like a file path, but it is supposed to be the library or application name.", .{name});
|
2019-09-03 13:19:10 -07:00
|
|
|
}
|
2018-11-13 05:08:37 -08:00
|
|
|
var self = LibExeObjStep{
|
2017-09-17 23:50:51 -07:00
|
|
|
.strip = false,
|
2017-04-13 14:21:00 -07:00
|
|
|
.builder = builder,
|
2018-01-04 20:43:46 -08:00
|
|
|
.verbose_link = false,
|
2019-02-25 08:37:54 -08:00
|
|
|
.verbose_cc = false,
|
2017-05-02 14:34:21 -07:00
|
|
|
.build_mode = builtin.Mode.Debug,
|
2019-03-13 16:33:19 -07:00
|
|
|
.is_dynamic = is_dynamic,
|
2017-04-20 22:56:12 -07:00
|
|
|
.kind = kind,
|
2017-04-13 14:21:00 -07:00
|
|
|
.root_src = root_src,
|
|
|
|
.name = name,
|
2017-09-23 14:59:30 -07:00
|
|
|
.frameworks = BufSet.init(builder.allocator),
|
2017-04-13 14:21:00 -07:00
|
|
|
.step = Step.init(name, builder.allocator, make),
|
2018-10-15 15:23:47 -07:00
|
|
|
.version = ver,
|
2017-04-20 22:56:12 -07:00
|
|
|
.out_filename = undefined,
|
2019-12-08 19:53:51 -08:00
|
|
|
.out_h_filename = builder.fmt("{}.h", .{name}),
|
2019-02-25 10:34:25 -08:00
|
|
|
.out_lib_filename = undefined,
|
2019-12-08 19:53:51 -08:00
|
|
|
.out_pdb_filename = builder.fmt("{}.pdb", .{name}),
|
2017-04-30 19:09:44 -07:00
|
|
|
.major_only_filename = undefined,
|
|
|
|
.name_only_filename = undefined,
|
2017-05-04 11:05:06 -07:00
|
|
|
.packages = ArrayList(Pkg).init(builder.allocator),
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
.include_dirs = ArrayList(IncludeDir).init(builder.allocator),
|
|
|
|
.link_objects = ArrayList(LinkObject).init(builder.allocator),
|
2019-09-23 10:33:43 -07:00
|
|
|
.c_macros = ArrayList([]const u8).init(builder.allocator),
|
2017-12-11 20:34:59 -08:00
|
|
|
.lib_paths = ArrayList([]const u8).init(builder.allocator),
|
2019-09-02 08:32:22 -07:00
|
|
|
.framework_dirs = ArrayList([]const u8).init(builder.allocator),
|
2017-09-17 23:50:51 -07:00
|
|
|
.object_src = undefined,
|
2020-03-06 20:35:06 -08:00
|
|
|
.build_options_contents = std.ArrayList(u8).init(builder.allocator),
|
2018-09-06 13:29:35 -07:00
|
|
|
.c_std = Builder.CStd.C99,
|
stage1 is now a hybrid of C++ and Zig
This modifies the build process of Zig to put all of the source files
into libcompiler.a, except main.cpp and userland.cpp.
Next, the build process links main.cpp, userland.cpp, and libcompiler.a
into zig1. userland.cpp is a shim for functions that will later be
replaced with self-hosted implementations.
Next, the build process uses zig1 to build src-self-hosted/stage1.zig
into libuserland.a, which does not depend on any of the things that
are shimmed in userland.cpp, such as translate-c.
Finally, the build process re-links main.cpp and libcompiler.a, except
with libuserland.a instead of userland.cpp. Now the shims are replaced
with .zig code. This provides all of the Zig standard library to the
stage1 C++ compiler, and enables us to move certain things to userland,
such as translate-c.
As a proof of concept I have made the `zig zen` command use text defined
in userland. I added `zig translate-c-2` which is a work-in-progress
reimplementation of translate-c in userland, which currently calls
`std.debug.panic("unimplemented")` and you can see the stack trace makes
it all the way back into the C++ main() function (Thanks LemonBoy for
improving that!).
This could potentially let us move other things into userland, such as
hashing algorithms, the entire cache system, .d file parsing, pretty
much anything that libuserland.a itself doesn't need to depend on.
This can also let us have `zig fmt` in stage1 without the overhead
of child process execution, and without the initial compilation delay
before it gets cached.
See #1964
2019-04-16 13:47:47 -07:00
|
|
|
.override_lib_dir = null,
|
2019-03-02 07:38:27 -08:00
|
|
|
.main_pkg_path = null,
|
2019-02-25 08:37:54 -08:00
|
|
|
.exec_cmd_args = null,
|
|
|
|
.name_prefix = "",
|
|
|
|
.filter = null,
|
2019-05-08 17:49:07 -07:00
|
|
|
.bundle_compiler_rt = false,
|
2019-05-08 19:43:11 -07:00
|
|
|
.disable_stack_probing = false,
|
2019-12-16 10:51:21 -08:00
|
|
|
.disable_sanitize_c = false,
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
.output_dir = null,
|
2019-04-05 11:54:37 -07:00
|
|
|
.single_threaded = false,
|
2019-07-04 12:32:44 -07:00
|
|
|
.installed_path = null,
|
|
|
|
.install_step = null,
|
2017-04-20 22:56:12 -07:00
|
|
|
};
|
|
|
|
self.computeOutFileNames();
|
2020-01-04 23:01:28 -08:00
|
|
|
if (root_src) |rs| rs.addStepDependencies(&self.step);
|
2017-04-20 22:56:12 -07:00
|
|
|
return self;
|
2017-04-13 14:21:00 -07:00
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
fn computeOutFileNames(self: *LibExeObjStep) void {
|
2017-04-20 22:56:12 -07:00
|
|
|
switch (self.kind) {
|
2019-05-26 10:17:34 -07:00
|
|
|
.Obj => {
|
2019-12-08 19:53:51 -08:00
|
|
|
self.out_filename = self.builder.fmt("{}{}", .{ self.name, self.target.oFileExt() });
|
2017-04-26 16:17:05 -07:00
|
|
|
},
|
2019-05-26 10:17:34 -07:00
|
|
|
.Exe => {
|
2019-12-08 19:53:51 -08:00
|
|
|
self.out_filename = self.builder.fmt("{}{}", .{ self.name, self.target.exeFileExt() });
|
2017-04-20 22:56:12 -07:00
|
|
|
},
|
2019-05-26 10:17:34 -07:00
|
|
|
.Test => {
|
2019-12-08 19:53:51 -08:00
|
|
|
self.out_filename = self.builder.fmt("test{}", .{self.target.exeFileExt()});
|
2019-02-25 08:37:54 -08:00
|
|
|
},
|
2019-05-26 10:17:34 -07:00
|
|
|
.Lib => {
|
2019-03-13 16:33:19 -07:00
|
|
|
if (!self.is_dynamic) {
|
2019-12-08 19:53:51 -08:00
|
|
|
self.out_filename = self.builder.fmt("{}{}{}", .{
|
2019-07-12 12:10:32 -07:00
|
|
|
self.target.libPrefix(),
|
|
|
|
self.name,
|
|
|
|
self.target.staticLibSuffix(),
|
2019-12-08 19:53:51 -08:00
|
|
|
});
|
2019-02-25 10:34:25 -08:00
|
|
|
self.out_lib_filename = self.out_filename;
|
2017-04-20 22:56:12 -07:00
|
|
|
} else {
|
2019-07-12 12:10:32 -07:00
|
|
|
if (self.target.isDarwin()) {
|
2019-12-08 19:53:51 -08:00
|
|
|
self.out_filename = self.builder.fmt("lib{}.{d}.{d}.{d}.dylib", .{
|
|
|
|
self.name,
|
|
|
|
self.version.major,
|
|
|
|
self.version.minor,
|
|
|
|
self.version.patch,
|
|
|
|
});
|
|
|
|
self.major_only_filename = self.builder.fmt("lib{}.{d}.dylib", .{
|
|
|
|
self.name,
|
|
|
|
self.version.major,
|
|
|
|
});
|
|
|
|
self.name_only_filename = self.builder.fmt("lib{}.dylib", .{self.name});
|
2019-07-12 12:10:32 -07:00
|
|
|
self.out_lib_filename = self.out_filename;
|
|
|
|
} else if (self.target.isWindows()) {
|
2019-12-08 19:53:51 -08:00
|
|
|
self.out_filename = self.builder.fmt("{}.dll", .{self.name});
|
|
|
|
self.out_lib_filename = self.builder.fmt("{}.lib", .{self.name});
|
2019-07-12 12:10:32 -07:00
|
|
|
} else {
|
2019-12-08 19:53:51 -08:00
|
|
|
self.out_filename = self.builder.fmt("lib{}.so.{d}.{d}.{d}", .{
|
|
|
|
self.name,
|
|
|
|
self.version.major,
|
|
|
|
self.version.minor,
|
|
|
|
self.version.patch,
|
|
|
|
});
|
|
|
|
self.major_only_filename = self.builder.fmt("lib{}.so.{d}", .{ self.name, self.version.major });
|
|
|
|
self.name_only_filename = self.builder.fmt("lib{}.so", .{self.name});
|
2019-07-12 12:10:32 -07:00
|
|
|
self.out_lib_filename = self.out_filename;
|
2017-08-27 14:16:42 -07:00
|
|
|
}
|
2017-04-20 22:56:12 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
2017-04-03 22:52:20 -07:00
|
|
|
}
|
2017-04-03 01:58:19 -07:00
|
|
|
|
2020-02-25 22:18:23 -08:00
|
|
|
pub fn setTarget(self: *LibExeObjStep, target: CrossTarget) void {
|
2019-07-09 10:31:42 -07:00
|
|
|
self.target = target;
|
2017-04-26 16:17:05 -07:00
|
|
|
self.computeOutFileNames();
|
2017-04-03 01:58:19 -07:00
|
|
|
}
|
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
pub fn setOutputDir(self: *LibExeObjStep, dir: []const u8) void {
|
2019-07-14 22:41:06 -07:00
|
|
|
self.output_dir = self.builder.dupePath(dir);
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
}
|
|
|
|
|
2019-07-04 12:32:44 -07:00
|
|
|
pub fn install(self: *LibExeObjStep) void {
|
|
|
|
self.builder.installArtifact(self);
|
|
|
|
}
|
2020-01-21 14:32:00 -08:00
|
|
|
|
2020-02-06 10:46:59 -08:00
|
|
|
pub fn installRaw(self: *LibExeObjStep, dest_filename: []const u8) void {
|
2020-01-21 14:32:00 -08:00
|
|
|
self.builder.installRaw(self, dest_filename);
|
|
|
|
}
|
2019-07-04 12:32:44 -07:00
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
/// Creates a `RunStep` with an executable built with `addExecutable`.
|
|
|
|
/// Add command line arguments with `addArg`.
|
|
|
|
pub fn run(exe: *LibExeObjStep) *RunStep {
|
|
|
|
assert(exe.kind == Kind.Exe);
|
2019-07-04 12:32:44 -07:00
|
|
|
|
2019-03-19 14:08:50 -07:00
|
|
|
// It doesn't have to be native. We catch that if you actually try to run it.
|
|
|
|
// Consider that this is declarative; the run step may not be run unless a user
|
|
|
|
// option is supplied.
|
2019-12-08 19:53:51 -08:00
|
|
|
const run_step = RunStep.create(exe.builder, exe.builder.fmt("run {}", .{exe.step.name}));
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
run_step.addArtifactArg(exe);
|
2019-10-10 12:58:47 -07:00
|
|
|
|
|
|
|
if (exe.vcpkg_bin_path) |path| {
|
|
|
|
run_step.addPathDir(path);
|
|
|
|
}
|
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
return run_step;
|
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn setLinkerScriptPath(self: *LibExeObjStep, path: []const u8) void {
|
2017-04-28 07:46:01 -07:00
|
|
|
self.linker_script = path;
|
2017-04-03 01:58:19 -07:00
|
|
|
}
|
2017-04-03 22:52:20 -07:00
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn linkFramework(self: *LibExeObjStep, framework_name: []const u8) void {
|
2017-09-23 14:59:30 -07:00
|
|
|
assert(self.target.isDarwin());
|
2018-01-08 21:07:01 -08:00
|
|
|
self.frameworks.put(framework_name) catch unreachable;
|
2017-09-23 14:59:30 -07:00
|
|
|
}
|
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
/// Returns whether the library, executable, or object depends on a particular system library.
|
|
|
|
pub fn dependsOnSystemLibrary(self: LibExeObjStep, name: []const u8) bool {
|
2019-09-23 10:33:43 -07:00
|
|
|
if (isLibCLibrary(name)) {
|
|
|
|
return self.is_linking_libc;
|
|
|
|
}
|
2020-03-30 11:23:22 -07:00
|
|
|
for (self.link_objects.span()) |link_object| {
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
switch (link_object) {
|
|
|
|
LinkObject.SystemLib => |n| if (mem.eql(u8, n, name)) return true,
|
|
|
|
else => continue,
|
|
|
|
}
|
2019-02-25 11:27:03 -08:00
|
|
|
}
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
return false;
|
|
|
|
}
|
2019-02-25 11:27:03 -08:00
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
pub fn linkLibrary(self: *LibExeObjStep, lib: *LibExeObjStep) void {
|
|
|
|
assert(lib.kind == Kind.Lib);
|
|
|
|
self.linkLibraryOrObject(lib);
|
|
|
|
}
|
2017-09-23 14:59:30 -07:00
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
pub fn isDynamicLibrary(self: *LibExeObjStep) bool {
|
2019-03-13 16:33:19 -07:00
|
|
|
return self.kind == Kind.Lib and self.is_dynamic;
|
2017-09-17 23:50:51 -07:00
|
|
|
}
|
|
|
|
|
2019-07-10 16:40:46 -07:00
|
|
|
pub fn producesPdbFile(self: *LibExeObjStep) bool {
|
2019-07-26 06:42:50 -07:00
|
|
|
if (!self.target.isWindows() and !self.target.isUefi()) return false;
|
2019-07-10 16:40:46 -07:00
|
|
|
if (self.strip) return false;
|
|
|
|
return self.isDynamicLibrary() or self.kind == .Exe;
|
|
|
|
}
|
|
|
|
|
2019-09-23 10:33:43 -07:00
|
|
|
pub fn linkLibC(self: *LibExeObjStep) void {
|
|
|
|
if (!self.is_linking_libc) {
|
|
|
|
self.is_linking_libc = true;
|
|
|
|
self.link_objects.append(LinkObject{ .SystemLib = "c" }) catch unreachable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// name_and_value looks like [name]=[value]. If the value is omitted, it is set to 1.
|
|
|
|
pub fn defineCMacro(self: *LibExeObjStep, name_and_value: []const u8) void {
|
|
|
|
self.c_macros.append(self.builder.dupe(name_and_value)) catch unreachable;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This one has no integration with anything, it just puts -lname on the command line.
|
|
|
|
/// Prefer to use `linkSystemLibrary` instead.
|
|
|
|
pub fn linkSystemLibraryName(self: *LibExeObjStep, name: []const u8) void {
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
self.link_objects.append(LinkObject{ .SystemLib = self.builder.dupe(name) }) catch unreachable;
|
2019-09-23 10:33:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// This links against a system library, exclusively using pkg-config to find the library.
|
|
|
|
/// Prefer to use `linkSystemLibrary` instead.
|
|
|
|
pub fn linkSystemLibraryPkgConfigOnly(self: *LibExeObjStep, lib_name: []const u8) !void {
|
|
|
|
const pkg_name = match: {
|
|
|
|
// First we have to map the library name to pkg config name. Unfortunately,
|
|
|
|
// there are several examples where this is not straightforward:
|
|
|
|
// -lSDL2 -> pkg-config sdl2
|
|
|
|
// -lgdk-3 -> pkg-config gdk-3.0
|
|
|
|
// -latk-1.0 -> pkg-config atk
|
|
|
|
const pkgs = try self.builder.getPkgConfigList();
|
|
|
|
|
|
|
|
// Exact match means instant winner.
|
|
|
|
for (pkgs) |pkg| {
|
|
|
|
if (mem.eql(u8, pkg.name, lib_name)) {
|
|
|
|
break :match pkg.name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Next we'll try ignoring case.
|
|
|
|
for (pkgs) |pkg| {
|
|
|
|
if (std.ascii.eqlIgnoreCase(pkg.name, lib_name)) {
|
|
|
|
break :match pkg.name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now try appending ".0".
|
|
|
|
for (pkgs) |pkg| {
|
|
|
|
if (std.ascii.indexOfIgnoreCase(pkg.name, lib_name)) |pos| {
|
|
|
|
if (pos != 0) continue;
|
|
|
|
if (mem.eql(u8, pkg.name[lib_name.len..], ".0")) {
|
|
|
|
break :match pkg.name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Trimming "-1.0".
|
|
|
|
if (mem.endsWith(u8, lib_name, "-1.0")) {
|
|
|
|
const trimmed_lib_name = lib_name[0 .. lib_name.len - "-1.0".len];
|
|
|
|
for (pkgs) |pkg| {
|
|
|
|
if (std.ascii.eqlIgnoreCase(pkg.name, trimmed_lib_name)) {
|
|
|
|
break :match pkg.name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return error.PackageNotFound;
|
|
|
|
};
|
|
|
|
|
|
|
|
var code: u8 = undefined;
|
2019-11-27 00:30:39 -08:00
|
|
|
const stdout = if (self.builder.execAllowFail(&[_][]const u8{
|
2019-09-23 10:33:43 -07:00
|
|
|
"pkg-config",
|
|
|
|
pkg_name,
|
|
|
|
"--cflags",
|
|
|
|
"--libs",
|
|
|
|
}, &code, .Ignore)) |stdout| stdout else |err| switch (err) {
|
|
|
|
error.ProcessTerminated => return error.PkgConfigCrashed,
|
|
|
|
error.ExitCodeFailure => return error.PkgConfigFailed,
|
|
|
|
error.FileNotFound => return error.PkgConfigNotInstalled,
|
|
|
|
else => return err,
|
|
|
|
};
|
|
|
|
var it = mem.tokenize(stdout, " \r\n\t");
|
|
|
|
while (it.next()) |tok| {
|
|
|
|
if (mem.eql(u8, tok, "-I")) {
|
|
|
|
const dir = it.next() orelse return error.PkgConfigInvalidOutput;
|
|
|
|
self.addIncludeDir(dir);
|
|
|
|
} else if (mem.startsWith(u8, tok, "-I")) {
|
|
|
|
self.addIncludeDir(tok["-I".len..]);
|
|
|
|
} else if (mem.eql(u8, tok, "-L")) {
|
|
|
|
const dir = it.next() orelse return error.PkgConfigInvalidOutput;
|
|
|
|
self.addLibPath(dir);
|
|
|
|
} else if (mem.startsWith(u8, tok, "-L")) {
|
|
|
|
self.addLibPath(tok["-L".len..]);
|
|
|
|
} else if (mem.eql(u8, tok, "-l")) {
|
|
|
|
const lib = it.next() orelse return error.PkgConfigInvalidOutput;
|
|
|
|
self.linkSystemLibraryName(lib);
|
|
|
|
} else if (mem.startsWith(u8, tok, "-l")) {
|
|
|
|
self.linkSystemLibraryName(tok["-l".len..]);
|
|
|
|
} else if (mem.eql(u8, tok, "-D")) {
|
|
|
|
const macro = it.next() orelse return error.PkgConfigInvalidOutput;
|
|
|
|
self.defineCMacro(macro);
|
|
|
|
} else if (mem.startsWith(u8, tok, "-D")) {
|
|
|
|
self.defineCMacro(tok["-D".len..]);
|
|
|
|
} else if (mem.eql(u8, tok, "-pthread")) {
|
|
|
|
self.linkLibC();
|
|
|
|
} else if (self.builder.verbose) {
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("Ignoring pkg-config flag '{}'\n", .{tok});
|
2019-09-23 10:33:43 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn linkSystemLibrary(self: *LibExeObjStep, name: []const u8) void {
|
2019-09-21 20:55:56 -07:00
|
|
|
if (isLibCLibrary(name)) {
|
2019-09-23 10:33:43 -07:00
|
|
|
self.linkLibC();
|
|
|
|
return;
|
2019-03-11 12:22:05 -07:00
|
|
|
}
|
2019-09-23 10:33:43 -07:00
|
|
|
if (self.linkSystemLibraryPkgConfigOnly(name)) |_| {
|
|
|
|
// pkg-config worked, so nothing further needed to do.
|
|
|
|
return;
|
|
|
|
} else |err| switch (err) {
|
|
|
|
error.PkgConfigInvalidOutput,
|
|
|
|
error.PkgConfigCrashed,
|
|
|
|
error.PkgConfigFailed,
|
|
|
|
error.PkgConfigNotInstalled,
|
|
|
|
error.PackageNotFound,
|
|
|
|
=> {},
|
|
|
|
|
|
|
|
else => unreachable,
|
|
|
|
}
|
|
|
|
|
|
|
|
self.linkSystemLibraryName(name);
|
2017-04-03 22:52:20 -07:00
|
|
|
}
|
2017-04-06 02:34:04 -07:00
|
|
|
|
2019-02-25 08:37:54 -08:00
|
|
|
pub fn setNamePrefix(self: *LibExeObjStep, text: []const u8) void {
|
|
|
|
assert(self.kind == Kind.Test);
|
|
|
|
self.name_prefix = text;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn setFilter(self: *LibExeObjStep, text: ?[]const u8) void {
|
|
|
|
assert(self.kind == Kind.Test);
|
|
|
|
self.filter = text;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn addCSourceFile(self: *LibExeObjStep, file: []const u8, args: []const []const u8) void {
|
2020-01-04 23:01:28 -08:00
|
|
|
self.addCSourceFileSource(.{
|
|
|
|
.args = args,
|
|
|
|
.source = .{ .path = file },
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn addCSourceFileSource(self: *LibExeObjStep, source: CSourceFile) void {
|
2019-02-25 08:37:54 -08:00
|
|
|
const c_source_file = self.builder.allocator.create(CSourceFile) catch unreachable;
|
2020-01-04 23:01:28 -08:00
|
|
|
|
|
|
|
const args_copy = self.builder.allocator.alloc([]u8, source.args.len) catch unreachable;
|
|
|
|
for (source.args) |arg, i| {
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
args_copy[i] = self.builder.dupe(arg);
|
|
|
|
}
|
2020-01-04 23:01:28 -08:00
|
|
|
|
|
|
|
c_source_file.* = source;
|
|
|
|
c_source_file.args = args_copy;
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
self.link_objects.append(LinkObject{ .CSourceFile = c_source_file }) catch unreachable;
|
2017-09-17 23:50:51 -07:00
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn setVerboseLink(self: *LibExeObjStep, value: bool) void {
|
2018-01-04 20:43:46 -08:00
|
|
|
self.verbose_link = value;
|
2017-04-19 11:00:12 -07:00
|
|
|
}
|
|
|
|
|
2019-02-25 08:37:54 -08:00
|
|
|
pub fn setVerboseCC(self: *LibExeObjStep, value: bool) void {
|
|
|
|
self.verbose_cc = value;
|
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn setBuildMode(self: *LibExeObjStep, mode: builtin.Mode) void {
|
2017-05-02 14:34:21 -07:00
|
|
|
self.build_mode = mode;
|
2017-04-19 11:00:12 -07:00
|
|
|
}
|
|
|
|
|
2019-09-25 20:57:47 -07:00
|
|
|
pub fn overrideZigLibDir(self: *LibExeObjStep, dir_path: []const u8) void {
|
|
|
|
self.override_lib_dir = self.builder.dupe(dir_path);
|
2019-02-25 08:37:54 -08:00
|
|
|
}
|
|
|
|
|
2019-03-02 07:38:27 -08:00
|
|
|
pub fn setMainPkgPath(self: *LibExeObjStep, dir_path: []const u8) void {
|
|
|
|
self.main_pkg_path = dir_path;
|
|
|
|
}
|
2019-04-05 11:54:37 -07:00
|
|
|
|
2020-03-30 11:23:22 -07:00
|
|
|
pub const setDisableGenH = @compileError("deprecated; set the emit_h field directly");
|
2019-03-02 07:38:27 -08:00
|
|
|
|
2019-07-07 08:31:07 -07:00
|
|
|
pub fn setLibCFile(self: *LibExeObjStep, libc_file: ?[]const u8) void {
|
|
|
|
self.libc_file = libc_file;
|
|
|
|
}
|
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
/// Unless setOutputDir was called, this function must be called only in
|
|
|
|
/// the make step, from a step that has declared a dependency on this one.
|
|
|
|
/// To run an executable built with zig build, use `run`, or create an install step and invoke it.
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn getOutputPath(self: *LibExeObjStep) []const u8 {
|
2019-05-26 10:17:34 -07:00
|
|
|
return fs.path.join(
|
2019-02-06 21:42:41 -08:00
|
|
|
self.builder.allocator,
|
2019-11-27 00:30:39 -08:00
|
|
|
&[_][]const u8{ self.output_dir.?, self.out_filename },
|
2019-02-06 21:42:41 -08:00
|
|
|
) catch unreachable;
|
2017-04-30 15:56:24 -07:00
|
|
|
}
|
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
/// Unless setOutputDir was called, this function must be called only in
|
|
|
|
/// the make step, from a step that has declared a dependency on this one.
|
2019-02-25 10:34:25 -08:00
|
|
|
pub fn getOutputLibPath(self: *LibExeObjStep) []const u8 {
|
|
|
|
assert(self.kind == Kind.Lib);
|
2019-05-26 10:17:34 -07:00
|
|
|
return fs.path.join(
|
2019-02-25 10:34:25 -08:00
|
|
|
self.builder.allocator,
|
2019-11-27 00:30:39 -08:00
|
|
|
&[_][]const u8{ self.output_dir.?, self.out_lib_filename },
|
2019-02-25 10:34:25 -08:00
|
|
|
) catch unreachable;
|
|
|
|
}
|
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
/// Unless setOutputDir was called, this function must be called only in
|
|
|
|
/// the make step, from a step that has declared a dependency on this one.
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn getOutputHPath(self: *LibExeObjStep) []const u8 {
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
assert(self.kind != Kind.Exe);
|
2020-03-20 15:33:36 -07:00
|
|
|
assert(self.emit_h);
|
2019-05-26 10:17:34 -07:00
|
|
|
return fs.path.join(
|
2019-02-06 21:42:41 -08:00
|
|
|
self.builder.allocator,
|
2019-11-27 00:30:39 -08:00
|
|
|
&[_][]const u8{ self.output_dir.?, self.out_h_filename },
|
2019-02-06 21:42:41 -08:00
|
|
|
) catch unreachable;
|
2017-04-30 15:56:24 -07:00
|
|
|
}
|
|
|
|
|
2019-07-08 15:48:03 -07:00
|
|
|
/// Unless setOutputDir was called, this function must be called only in
|
|
|
|
/// the make step, from a step that has declared a dependency on this one.
|
|
|
|
pub fn getOutputPdbPath(self: *LibExeObjStep) []const u8 {
|
2019-07-26 06:42:50 -07:00
|
|
|
assert(self.target.isWindows() or self.target.isUefi());
|
2019-07-08 15:48:03 -07:00
|
|
|
return fs.path.join(
|
|
|
|
self.builder.allocator,
|
2019-11-27 00:30:39 -08:00
|
|
|
&[_][]const u8{ self.output_dir.?, self.out_pdb_filename },
|
2019-07-08 15:48:03 -07:00
|
|
|
) catch unreachable;
|
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn addAssemblyFile(self: *LibExeObjStep, path: []const u8) void {
|
2020-01-20 07:27:18 -08:00
|
|
|
self.link_objects.append(LinkObject{
|
|
|
|
.AssemblyFile = .{ .path = self.builder.dupe(path) },
|
|
|
|
}) catch unreachable;
|
2017-04-19 11:00:12 -07:00
|
|
|
}
|
|
|
|
|
2020-01-04 23:01:28 -08:00
|
|
|
pub fn addAssemblyFileFromWriteFileStep(self: *LibExeObjStep, wfs: *WriteFileStep, basename: []const u8) void {
|
|
|
|
self.addAssemblyFileSource(.{
|
|
|
|
.write_file = .{
|
|
|
|
.step = wfs,
|
|
|
|
.basename = self.builder.dupe(basename),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn addAssemblyFileSource(self: *LibExeObjStep, source: FileSource) void {
|
|
|
|
self.link_objects.append(LinkObject{ .AssemblyFile = source }) catch unreachable;
|
|
|
|
source.addStepDependencies(&self.step);
|
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn addObjectFile(self: *LibExeObjStep, path: []const u8) void {
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
self.link_objects.append(LinkObject{ .StaticPath = self.builder.dupe(path) }) catch unreachable;
|
2017-04-19 11:00:12 -07:00
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn addObject(self: *LibExeObjStep, obj: *LibExeObjStep) void {
|
2017-04-26 16:17:05 -07:00
|
|
|
assert(obj.kind == Kind.Obj);
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
self.linkLibraryOrObject(obj);
|
2017-09-17 23:50:51 -07:00
|
|
|
}
|
|
|
|
|
2018-07-07 21:00:05 -07:00
|
|
|
pub fn addBuildOption(self: *LibExeObjStep, comptime T: type, name: []const u8, value: T) void {
|
2020-03-21 19:53:05 -07:00
|
|
|
const out = self.build_options_contents.outStream();
|
2020-05-15 16:12:22 -07:00
|
|
|
switch (@typeInfo(T)) {
|
|
|
|
.Enum => |enum_info| {
|
|
|
|
out.print("const {} = enum {{\n", .{@typeName(T)}) catch unreachable;
|
|
|
|
inline for (enum_info.fields) |field| {
|
|
|
|
out.print(" {},\n", .{ field.name }) catch unreachable;
|
|
|
|
}
|
|
|
|
out.print("}};\n", .{}) catch unreachable;
|
|
|
|
},
|
|
|
|
else => {},
|
|
|
|
}
|
2019-12-09 19:21:28 -08:00
|
|
|
out.print("pub const {} = {};\n", .{ name, value }) catch unreachable;
|
2018-07-07 21:00:05 -07:00
|
|
|
}
|
|
|
|
|
2019-11-05 11:32:17 -08:00
|
|
|
pub fn addSystemIncludeDir(self: *LibExeObjStep, path: []const u8) void {
|
|
|
|
self.include_dirs.append(IncludeDir{ .RawPathSystem = self.builder.dupe(path) }) catch unreachable;
|
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn addIncludeDir(self: *LibExeObjStep, path: []const u8) void {
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
self.include_dirs.append(IncludeDir{ .RawPath = self.builder.dupe(path) }) catch unreachable;
|
2017-04-26 09:56:10 -07:00
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn addLibPath(self: *LibExeObjStep, path: []const u8) void {
|
2020-01-30 17:00:05 -08:00
|
|
|
self.lib_paths.append(self.builder.dupe(path)) catch unreachable;
|
2017-12-11 20:34:59 -08:00
|
|
|
}
|
|
|
|
|
2019-09-02 08:32:22 -07:00
|
|
|
pub fn addFrameworkDir(self: *LibExeObjStep, dir_path: []const u8) void {
|
2020-01-30 17:00:05 -08:00
|
|
|
self.framework_dirs.append(self.builder.dupe(dir_path)) catch unreachable;
|
2019-09-02 08:32:22 -07:00
|
|
|
}
|
|
|
|
|
2020-01-31 10:02:12 -08:00
|
|
|
pub fn addPackage(self: *LibExeObjStep, package: Pkg) void {
|
|
|
|
self.packages.append(package) catch unreachable;
|
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn addPackagePath(self: *LibExeObjStep, name: []const u8, pkg_index_path: []const u8) void {
|
2018-11-13 05:08:37 -08:00
|
|
|
self.packages.append(Pkg{
|
2020-01-30 17:00:05 -08:00
|
|
|
.name = self.builder.dupe(name),
|
|
|
|
.path = self.builder.dupe(pkg_index_path),
|
2018-01-08 21:07:01 -08:00
|
|
|
}) catch unreachable;
|
2017-05-01 13:35:10 -07:00
|
|
|
}
|
|
|
|
|
2019-10-10 12:58:47 -07:00
|
|
|
/// If Vcpkg was found on the system, it will be added to include and lib
|
|
|
|
/// paths for the specified target.
|
|
|
|
pub fn addVcpkgPaths(self: *LibExeObjStep, linkage: VcpkgLinkage) !void {
|
|
|
|
// Ideally in the Unattempted case we would call the function recursively
|
|
|
|
// after findVcpkgRoot and have only one switch statement, but the compiler
|
|
|
|
// cannot resolve the error set.
|
|
|
|
switch (self.builder.vcpkg_root) {
|
|
|
|
.Unattempted => {
|
|
|
|
self.builder.vcpkg_root = if (try findVcpkgRoot(self.builder.allocator)) |root|
|
|
|
|
VcpkgRoot{ .Found = root }
|
|
|
|
else
|
|
|
|
.NotFound;
|
|
|
|
},
|
|
|
|
.NotFound => return error.VcpkgNotFound,
|
|
|
|
.Found => {},
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (self.builder.vcpkg_root) {
|
|
|
|
.Unattempted => unreachable,
|
|
|
|
.NotFound => return error.VcpkgNotFound,
|
|
|
|
.Found => |root| {
|
|
|
|
const allocator = self.builder.allocator;
|
2020-02-25 00:43:21 -08:00
|
|
|
const triplet = try self.target.vcpkgTriplet(allocator, linkage);
|
2019-10-10 12:58:47 -07:00
|
|
|
defer self.builder.allocator.free(triplet);
|
|
|
|
|
2019-11-27 00:30:39 -08:00
|
|
|
const include_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "include" });
|
2019-10-10 12:58:47 -07:00
|
|
|
errdefer allocator.free(include_path);
|
|
|
|
try self.include_dirs.append(IncludeDir{ .RawPath = include_path });
|
|
|
|
|
2019-11-27 00:30:39 -08:00
|
|
|
const lib_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "lib" });
|
2019-10-10 12:58:47 -07:00
|
|
|
try self.lib_paths.append(lib_path);
|
|
|
|
|
2019-11-27 00:30:39 -08:00
|
|
|
self.vcpkg_bin_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "bin" });
|
2019-10-10 12:58:47 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-25 08:37:54 -08:00
|
|
|
pub fn setExecCmd(self: *LibExeObjStep, args: []const ?[]const u8) void {
|
|
|
|
assert(self.kind == Kind.Test);
|
|
|
|
self.exec_cmd_args = args;
|
2017-09-17 23:50:51 -07:00
|
|
|
}
|
|
|
|
|
2018-11-01 21:07:43 -07:00
|
|
|
pub fn enableSystemLinkerHack(self: *LibExeObjStep) void {
|
|
|
|
self.system_linker_hack = true;
|
|
|
|
}
|
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
fn linkLibraryOrObject(self: *LibExeObjStep, other: *LibExeObjStep) void {
|
|
|
|
self.step.dependOn(&other.step);
|
|
|
|
self.link_objects.append(LinkObject{ .OtherStep = other }) catch unreachable;
|
|
|
|
self.include_dirs.append(IncludeDir{ .OtherStep = other }) catch unreachable;
|
|
|
|
|
2019-07-12 14:25:25 -07:00
|
|
|
// Inherit dependency on system libraries
|
2020-03-30 11:23:22 -07:00
|
|
|
for (other.link_objects.span()) |link_object| {
|
2019-07-12 14:25:25 -07:00
|
|
|
switch (link_object) {
|
|
|
|
.SystemLib => |name| self.linkSystemLibrary(name),
|
|
|
|
else => continue,
|
|
|
|
}
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Inherit dependencies on darwin frameworks
|
|
|
|
if (self.target.isDarwin() and !other.isDynamicLibrary()) {
|
|
|
|
var it = other.frameworks.iterator();
|
|
|
|
while (it.next()) |entry| {
|
|
|
|
self.frameworks.put(entry.key) catch unreachable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-30 09:14:17 -07:00
|
|
|
fn makePackageCmd(self: *LibExeObjStep, pkg: Pkg, zig_args: *ArrayList([]const u8)) error{OutOfMemory}!void {
|
2020-04-29 09:54:06 -07:00
|
|
|
const builder = self.builder;
|
|
|
|
|
|
|
|
try zig_args.append("--pkg-begin");
|
|
|
|
try zig_args.append(pkg.name);
|
|
|
|
try zig_args.append(builder.pathFromRoot(pkg.path));
|
|
|
|
|
|
|
|
if (pkg.dependencies) |dependencies| {
|
|
|
|
for (dependencies) |sub_pkg| {
|
|
|
|
try self.makePackageCmd(sub_pkg, zig_args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try zig_args.append("--pkg-end");
|
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
fn make(step: *Step) !void {
|
2017-04-26 16:17:05 -07:00
|
|
|
const self = @fieldParentPtr(LibExeObjStep, "step", step);
|
2017-04-19 11:00:12 -07:00
|
|
|
const builder = self.builder;
|
|
|
|
|
2020-04-01 15:00:42 -07:00
|
|
|
if (self.root_src == null and self.link_objects.items.len == 0) {
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("{}: linker needs 1 or more objects to link\n", .{self.step.name});
|
2017-04-19 11:00:12 -07:00
|
|
|
return error.NeedAnObject;
|
|
|
|
}
|
|
|
|
|
2017-05-04 11:05:06 -07:00
|
|
|
var zig_args = ArrayList([]const u8).init(builder.allocator);
|
2017-04-19 11:00:12 -07:00
|
|
|
defer zig_args.deinit();
|
|
|
|
|
2018-01-08 21:07:01 -08:00
|
|
|
zig_args.append(builder.zig_exe) catch unreachable;
|
2017-09-25 22:01:49 -07:00
|
|
|
|
2017-04-26 16:17:05 -07:00
|
|
|
const cmd = switch (self.kind) {
|
2017-09-15 22:00:59 -07:00
|
|
|
Kind.Lib => "build-lib",
|
|
|
|
Kind.Exe => "build-exe",
|
|
|
|
Kind.Obj => "build-obj",
|
2019-02-25 08:37:54 -08:00
|
|
|
Kind.Test => "test",
|
2017-04-19 11:00:12 -07:00
|
|
|
};
|
2018-01-08 21:07:01 -08:00
|
|
|
zig_args.append(cmd) catch unreachable;
|
2017-04-19 11:00:12 -07:00
|
|
|
|
2020-01-04 23:01:28 -08:00
|
|
|
if (self.root_src) |root_src| try zig_args.append(root_src.getPath(builder));
|
2017-04-26 16:17:05 -07:00
|
|
|
|
2020-03-30 11:23:22 -07:00
|
|
|
for (self.link_objects.span()) |link_object| {
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
switch (link_object) {
|
2020-01-04 23:01:28 -08:00
|
|
|
.StaticPath => |static_path| {
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
try zig_args.append("--object");
|
|
|
|
try zig_args.append(builder.pathFromRoot(static_path));
|
|
|
|
},
|
|
|
|
|
2020-01-04 23:01:28 -08:00
|
|
|
.OtherStep => |other| switch (other.kind) {
|
|
|
|
.Exe => unreachable,
|
|
|
|
.Test => unreachable,
|
|
|
|
.Obj => {
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
try zig_args.append("--object");
|
|
|
|
try zig_args.append(other.getOutputPath());
|
|
|
|
},
|
2020-01-04 23:01:28 -08:00
|
|
|
.Lib => {
|
2019-03-13 16:33:19 -07:00
|
|
|
if (!other.is_dynamic or self.target.isWindows()) {
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
try zig_args.append("--object");
|
2019-03-08 21:42:14 -08:00
|
|
|
try zig_args.append(other.getOutputLibPath());
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
} else {
|
|
|
|
const full_path_lib = other.getOutputPath();
|
|
|
|
try zig_args.append("--library");
|
|
|
|
try zig_args.append(full_path_lib);
|
|
|
|
|
2019-05-26 10:17:34 -07:00
|
|
|
if (fs.path.dirname(full_path_lib)) |dirname| {
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
try zig_args.append("-rpath");
|
|
|
|
try zig_args.append(dirname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2020-01-04 23:01:28 -08:00
|
|
|
.SystemLib => |name| {
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
try zig_args.append("--library");
|
|
|
|
try zig_args.append(name);
|
|
|
|
},
|
2020-01-04 23:01:28 -08:00
|
|
|
.AssemblyFile => |asm_file| {
|
2019-05-11 12:06:31 -07:00
|
|
|
try zig_args.append("--c-source");
|
2020-01-04 23:01:28 -08:00
|
|
|
try zig_args.append(asm_file.getPath(builder));
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
},
|
2020-01-04 23:01:28 -08:00
|
|
|
.CSourceFile => |c_source_file| {
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
try zig_args.append("--c-source");
|
|
|
|
for (c_source_file.args) |arg| {
|
|
|
|
try zig_args.append(arg);
|
|
|
|
}
|
2020-01-04 23:01:28 -08:00
|
|
|
try zig_args.append(c_source_file.source.getPath(builder));
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
},
|
2019-02-25 08:37:54 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-01 15:00:42 -07:00
|
|
|
if (self.build_options_contents.items.len > 0) {
|
2019-05-26 10:17:34 -07:00
|
|
|
const build_options_file = try fs.path.join(
|
2019-02-06 21:42:41 -08:00
|
|
|
builder.allocator,
|
2019-12-08 19:53:51 -08:00
|
|
|
&[_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", .{self.name}) },
|
2019-02-06 21:42:41 -08:00
|
|
|
);
|
2020-03-30 11:23:22 -07:00
|
|
|
try fs.cwd().writeFile(build_options_file, self.build_options_contents.span());
|
2018-07-07 21:00:05 -07:00
|
|
|
try zig_args.append("--pkg-begin");
|
|
|
|
try zig_args.append("build_options");
|
|
|
|
try zig_args.append(builder.pathFromRoot(build_options_file));
|
|
|
|
try zig_args.append("--pkg-end");
|
|
|
|
}
|
|
|
|
|
2019-02-25 08:37:54 -08:00
|
|
|
if (self.filter) |filter| {
|
|
|
|
try zig_args.append("--test-filter");
|
|
|
|
try zig_args.append(filter);
|
|
|
|
}
|
|
|
|
|
2020-05-05 12:18:04 -07:00
|
|
|
if (self.test_evented_io) {
|
2020-05-05 08:49:33 -07:00
|
|
|
try zig_args.append("--test-evented-io");
|
|
|
|
}
|
|
|
|
|
2019-02-25 08:37:54 -08:00
|
|
|
if (self.name_prefix.len != 0) {
|
|
|
|
try zig_args.append("--test-name-prefix");
|
|
|
|
try zig_args.append(self.name_prefix);
|
|
|
|
}
|
|
|
|
|
2018-01-08 21:07:01 -08:00
|
|
|
if (builder.verbose_tokenize) zig_args.append("--verbose-tokenize") catch unreachable;
|
|
|
|
if (builder.verbose_ast) zig_args.append("--verbose-ast") catch unreachable;
|
|
|
|
if (builder.verbose_cimport) zig_args.append("--verbose-cimport") catch unreachable;
|
|
|
|
if (builder.verbose_ir) zig_args.append("--verbose-ir") catch unreachable;
|
|
|
|
if (builder.verbose_llvm_ir) zig_args.append("--verbose-llvm-ir") catch unreachable;
|
|
|
|
if (builder.verbose_link or self.verbose_link) zig_args.append("--verbose-link") catch unreachable;
|
2019-02-25 08:37:54 -08:00
|
|
|
if (builder.verbose_cc or self.verbose_cc) zig_args.append("--verbose-cc") catch unreachable;
|
2020-02-24 17:11:33 -08:00
|
|
|
if (builder.verbose_llvm_cpu_features) zig_args.append("--verbose-llvm-cpu-features") catch unreachable;
|
2017-04-19 11:00:12 -07:00
|
|
|
|
2020-02-18 18:59:43 -08:00
|
|
|
if (self.emit_llvm_ir) try zig_args.append("-femit-llvm-ir");
|
|
|
|
if (self.emit_asm) try zig_args.append("-femit-asm");
|
|
|
|
if (!self.emit_bin) try zig_args.append("-fno-emit-bin");
|
2020-03-20 15:33:36 -07:00
|
|
|
if (self.emit_h) try zig_args.append("-femit-h");
|
2020-02-09 16:52:50 -08:00
|
|
|
|
2017-09-17 23:50:51 -07:00
|
|
|
if (self.strip) {
|
2020-01-07 13:02:38 -08:00
|
|
|
try zig_args.append("--strip");
|
|
|
|
}
|
|
|
|
if (self.link_eh_frame_hdr) {
|
|
|
|
try zig_args.append("--eh-frame-hdr");
|
2017-09-17 23:50:51 -07:00
|
|
|
}
|
2020-03-16 01:54:11 -07:00
|
|
|
if (self.link_function_sections) {
|
|
|
|
try zig_args.append("-ffunction-sections");
|
|
|
|
}
|
2019-04-05 11:54:37 -07:00
|
|
|
if (self.single_threaded) {
|
|
|
|
try zig_args.append("--single-threaded");
|
|
|
|
}
|
|
|
|
|
2019-07-07 08:31:07 -07:00
|
|
|
if (self.libc_file) |libc_file| {
|
|
|
|
try zig_args.append("--libc");
|
|
|
|
try zig_args.append(builder.pathFromRoot(libc_file));
|
|
|
|
}
|
|
|
|
|
2017-05-02 14:34:21 -07:00
|
|
|
switch (self.build_mode) {
|
2020-02-25 12:29:56 -08:00
|
|
|
.Debug => {},
|
|
|
|
.ReleaseSafe => zig_args.append("--release-safe") catch unreachable,
|
|
|
|
.ReleaseFast => zig_args.append("--release-fast") catch unreachable,
|
|
|
|
.ReleaseSmall => zig_args.append("--release-small") catch unreachable,
|
2017-04-19 11:00:12 -07:00
|
|
|
}
|
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
try zig_args.append("--cache-dir");
|
|
|
|
try zig_args.append(builder.pathFromRoot(builder.cache_root));
|
2017-04-19 11:00:12 -07:00
|
|
|
|
2018-01-08 21:07:01 -08:00
|
|
|
zig_args.append("--name") catch unreachable;
|
|
|
|
zig_args.append(self.name) catch unreachable;
|
2017-04-19 11:00:12 -07:00
|
|
|
|
2019-03-13 16:33:19 -07:00
|
|
|
if (self.kind == Kind.Lib and self.is_dynamic) {
|
2018-01-08 21:07:01 -08:00
|
|
|
zig_args.append("--ver-major") catch unreachable;
|
2019-12-08 19:53:51 -08:00
|
|
|
zig_args.append(builder.fmt("{}", .{self.version.major})) catch unreachable;
|
2017-04-26 16:17:05 -07:00
|
|
|
|
2018-01-08 21:07:01 -08:00
|
|
|
zig_args.append("--ver-minor") catch unreachable;
|
2019-12-08 19:53:51 -08:00
|
|
|
zig_args.append(builder.fmt("{}", .{self.version.minor})) catch unreachable;
|
2017-04-26 16:17:05 -07:00
|
|
|
|
2018-01-08 21:07:01 -08:00
|
|
|
zig_args.append("--ver-patch") catch unreachable;
|
2019-12-08 19:53:51 -08:00
|
|
|
zig_args.append(builder.fmt("{}", .{self.version.patch})) catch unreachable;
|
2017-04-26 16:17:05 -07:00
|
|
|
}
|
2019-03-13 16:33:19 -07:00
|
|
|
if (self.is_dynamic) {
|
|
|
|
try zig_args.append("-dynamic");
|
2018-11-30 22:21:59 -08:00
|
|
|
}
|
2019-05-08 17:49:07 -07:00
|
|
|
if (self.bundle_compiler_rt) {
|
|
|
|
try zig_args.append("--bundle-compiler-rt");
|
|
|
|
}
|
2019-05-08 19:43:11 -07:00
|
|
|
if (self.disable_stack_probing) {
|
2019-07-26 06:01:49 -07:00
|
|
|
try zig_args.append("-fno-stack-check");
|
2019-05-08 19:43:11 -07:00
|
|
|
}
|
2019-12-16 10:51:21 -08:00
|
|
|
if (self.disable_sanitize_c) {
|
|
|
|
try zig_args.append("-fno-sanitize-c");
|
|
|
|
}
|
2017-04-26 16:17:05 -07:00
|
|
|
|
2020-01-29 04:22:11 -08:00
|
|
|
if (self.code_model != .default) {
|
|
|
|
try zig_args.append("-code-model");
|
|
|
|
try zig_args.append(@tagName(self.code_model));
|
|
|
|
}
|
|
|
|
|
2020-02-25 22:18:23 -08:00
|
|
|
if (!self.target.isNative()) {
|
|
|
|
try zig_args.append("-target");
|
|
|
|
try zig_args.append(try self.target.zigTriple(builder.allocator));
|
2017-04-19 11:00:12 -07:00
|
|
|
|
2020-02-25 22:18:23 -08:00
|
|
|
// TODO this logic can disappear if cpu model + features becomes part of the target triple
|
|
|
|
const cross = self.target.toTarget();
|
|
|
|
const all_features = cross.cpu.arch.allFeaturesList();
|
|
|
|
var populated_cpu_features = cross.cpu.model.features;
|
|
|
|
populated_cpu_features.populateDependencies(all_features);
|
2020-01-22 14:13:31 -08:00
|
|
|
|
2020-02-25 22:18:23 -08:00
|
|
|
if (populated_cpu_features.eql(cross.cpu.features)) {
|
|
|
|
// The CPU name alone is sufficient.
|
|
|
|
// If it is the baseline CPU, no command line args are required.
|
|
|
|
if (cross.cpu.model != std.Target.Cpu.baseline(cross.cpu.arch).model) {
|
|
|
|
try zig_args.append("-mcpu");
|
|
|
|
try zig_args.append(cross.cpu.model.name);
|
|
|
|
}
|
|
|
|
} else {
|
2020-03-06 20:35:06 -08:00
|
|
|
var mcpu_buffer = std.ArrayList(u8).init(builder.allocator);
|
|
|
|
|
|
|
|
try mcpu_buffer.outStream().print("-mcpu={}", .{cross.cpu.model.name});
|
2020-02-25 22:18:23 -08:00
|
|
|
|
|
|
|
for (all_features) |feature, i_usize| {
|
|
|
|
const i = @intCast(std.Target.Cpu.Feature.Set.Index, i_usize);
|
|
|
|
const in_cpu_set = populated_cpu_features.isEnabled(i);
|
|
|
|
const in_actual_set = cross.cpu.features.isEnabled(i);
|
|
|
|
if (in_cpu_set and !in_actual_set) {
|
2020-03-06 20:35:06 -08:00
|
|
|
try mcpu_buffer.outStream().print("-{}", .{feature.name});
|
2020-02-25 22:18:23 -08:00
|
|
|
} else if (!in_cpu_set and in_actual_set) {
|
2020-03-06 20:35:06 -08:00
|
|
|
try mcpu_buffer.outStream().print("+{}", .{feature.name});
|
2020-01-22 14:13:31 -08:00
|
|
|
}
|
2020-01-18 23:40:35 -08:00
|
|
|
}
|
2020-03-06 20:35:06 -08:00
|
|
|
|
|
|
|
try zig_args.append(mcpu_buffer.toOwnedSlice());
|
2020-02-25 22:18:23 -08:00
|
|
|
}
|
2020-02-28 10:27:52 -08:00
|
|
|
|
|
|
|
if (self.target.dynamic_linker.get()) |dynamic_linker| {
|
|
|
|
try zig_args.append("--dynamic-linker");
|
|
|
|
try zig_args.append(dynamic_linker);
|
|
|
|
}
|
2019-07-07 14:24:49 -07:00
|
|
|
}
|
|
|
|
|
2017-05-03 14:23:11 -07:00
|
|
|
if (self.linker_script) |linker_script| {
|
2018-01-08 21:07:01 -08:00
|
|
|
zig_args.append("--linker-script") catch unreachable;
|
2019-07-07 14:55:25 -07:00
|
|
|
zig_args.append(builder.pathFromRoot(linker_script)) catch unreachable;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self.version_script) |version_script| {
|
|
|
|
try zig_args.append("--version-script");
|
|
|
|
try zig_args.append(builder.pathFromRoot(version_script));
|
2017-04-19 11:00:12 -07:00
|
|
|
}
|
|
|
|
|
2019-02-25 08:37:54 -08:00
|
|
|
if (self.exec_cmd_args) |exec_cmd_args| {
|
|
|
|
for (exec_cmd_args) |cmd_arg| {
|
|
|
|
if (cmd_arg) |arg| {
|
|
|
|
try zig_args.append("--test-cmd");
|
|
|
|
try zig_args.append(arg);
|
|
|
|
} else {
|
|
|
|
try zig_args.append("--test-cmd-bin");
|
|
|
|
}
|
|
|
|
}
|
2019-09-21 20:55:56 -07:00
|
|
|
} else switch (self.target.getExternalExecutor()) {
|
|
|
|
.native, .unavailable => {},
|
|
|
|
.qemu => |bin_name| if (self.enable_qemu) qemu: {
|
2020-02-25 00:43:21 -08:00
|
|
|
const need_cross_glibc = self.target.isGnuLibC() and self.is_linking_libc;
|
2019-09-21 20:55:56 -07:00
|
|
|
const glibc_dir_arg = if (need_cross_glibc)
|
|
|
|
self.glibc_multi_install_dir orelse break :qemu
|
|
|
|
else
|
|
|
|
null;
|
|
|
|
try zig_args.append("--test-cmd");
|
|
|
|
try zig_args.append(bin_name);
|
|
|
|
if (glibc_dir_arg) |dir| {
|
2019-11-27 00:30:39 -08:00
|
|
|
const full_dir = try fs.path.join(builder.allocator, &[_][]const u8{
|
2019-09-21 20:55:56 -07:00
|
|
|
dir,
|
|
|
|
try self.target.linuxTriple(builder.allocator),
|
|
|
|
});
|
|
|
|
|
|
|
|
try zig_args.append("--test-cmd");
|
|
|
|
try zig_args.append("-L");
|
|
|
|
try zig_args.append("--test-cmd");
|
|
|
|
try zig_args.append(full_dir);
|
|
|
|
}
|
|
|
|
try zig_args.append("--test-cmd-bin");
|
|
|
|
},
|
|
|
|
.wine => |bin_name| if (self.enable_wine) {
|
|
|
|
try zig_args.append("--test-cmd");
|
|
|
|
try zig_args.append(bin_name);
|
|
|
|
try zig_args.append("--test-cmd-bin");
|
|
|
|
},
|
2019-11-19 22:56:34 -08:00
|
|
|
.wasmtime => |bin_name| if (self.enable_wasmtime) {
|
|
|
|
try zig_args.append("--test-cmd");
|
|
|
|
try zig_args.append(bin_name);
|
Add/fix missing WASI functionality to pass libstd tests
This rather large commit adds/fixes missing WASI functionality
in `libstd` needed to pass the `libstd` tests. As such, now by
default tests targeting `wasm32-wasi` target are enabled in
`test/tests.zig` module. However, they can be disabled by passing
the `-Dskip-wasi=true` flag when invoking the `zig build test`
command. When the flag is set to `false`, i.e., when WASI tests are
included, `wasmtime` with `--dir=.` is used as the default testing
command.
Since the majority of `libstd` tests were relying on `fs.cwd()`
call to get current working directory handle wrapped in `Dir`
struct, in order to make the tests WASI-friendly, `fs.cwd()`
call was replaced with `testing.getTestDir()` function which
resolved to either `fs.cwd()` for non-WASI targets, or tries to
fetch the preopen list from the WASI runtime and extract a
preopen for '.' path.
The summary of changes introduced by this commit:
* implement `Dir.makeDir` and `Dir.openDir` targeting WASI
* implement `Dir.deleteFile` and `Dir.deleteDir` targeting WASI
* fix `os.close` and map errors in `unlinkat`
* move WASI-specific `mkdirat` and `unlinkat` from `std.fs.wasi`
to `std.os` module
* implement `lseek_{SET, CUR, END}` targeting WASI
* implement `futimens` targeting WASI
* implement `ftruncate` targeting WASI
* implement `readv`, `writev`, `pread{v}`, `pwrite{v}` targeting WASI
* make sure ANSI escape codes are _not_ used in stderr or stdout
in WASI, as WASI always sanitizes stderr, and sanitizes stdout if
fd is a TTY
* fix specifying WASI rights when opening/creating files/dirs
* tweak `AtomicFile` to be WASI-compatible
* implement `os.renameatWasi` for WASI-compliant `os.renameat` function
* implement sleep() targeting WASI
* fix `process.getEnvMap` targeting WASI
2020-05-05 08:23:49 -07:00
|
|
|
try zig_args.append("--test-cmd");
|
|
|
|
try zig_args.append("--dir=.");
|
2019-11-19 22:56:34 -08:00
|
|
|
try zig_args.append("--test-cmd-bin");
|
|
|
|
},
|
2017-09-17 23:50:51 -07:00
|
|
|
}
|
2020-01-31 10:02:12 -08:00
|
|
|
|
2020-03-30 11:23:22 -07:00
|
|
|
for (self.packages.span()) |pkg| {
|
2020-04-29 09:54:06 -07:00
|
|
|
try self.makePackageCmd(pkg, &zig_args);
|
2017-05-01 13:35:10 -07:00
|
|
|
}
|
|
|
|
|
2020-03-30 11:23:22 -07:00
|
|
|
for (self.include_dirs.span()) |include_dir| {
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
switch (include_dir) {
|
2019-11-05 11:32:17 -08:00
|
|
|
.RawPath => |include_path| {
|
|
|
|
try zig_args.append("-I");
|
|
|
|
try zig_args.append(self.builder.pathFromRoot(include_path));
|
|
|
|
},
|
|
|
|
.RawPathSystem => |include_path| {
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
try zig_args.append("-isystem");
|
|
|
|
try zig_args.append(self.builder.pathFromRoot(include_path));
|
|
|
|
},
|
2020-03-20 15:33:36 -07:00
|
|
|
.OtherStep => |other| if (other.emit_h) {
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
const h_path = other.getOutputHPath();
|
|
|
|
try zig_args.append("-isystem");
|
2019-05-26 10:17:34 -07:00
|
|
|
try zig_args.append(fs.path.dirname(h_path).?);
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
},
|
|
|
|
}
|
2017-12-11 20:34:59 -08:00
|
|
|
}
|
|
|
|
|
2020-03-30 11:23:22 -07:00
|
|
|
for (self.lib_paths.span()) |lib_path| {
|
2019-09-02 08:32:22 -07:00
|
|
|
try zig_args.append("-L");
|
|
|
|
try zig_args.append(lib_path);
|
2017-12-11 20:34:59 -08:00
|
|
|
}
|
|
|
|
|
2020-03-30 11:23:22 -07:00
|
|
|
for (self.c_macros.span()) |c_macro| {
|
2019-09-23 10:33:43 -07:00
|
|
|
try zig_args.append("-D");
|
|
|
|
try zig_args.append(c_macro);
|
|
|
|
}
|
|
|
|
|
2017-09-23 14:59:30 -07:00
|
|
|
if (self.target.isDarwin()) {
|
2020-03-30 11:23:22 -07:00
|
|
|
for (self.framework_dirs.span()) |dir| {
|
2019-09-02 08:32:22 -07:00
|
|
|
try zig_args.append("-F");
|
|
|
|
try zig_args.append(dir);
|
|
|
|
}
|
|
|
|
|
2017-09-23 14:59:30 -07:00
|
|
|
var it = self.frameworks.iterator();
|
|
|
|
while (it.next()) |entry| {
|
2018-01-08 21:07:01 -08:00
|
|
|
zig_args.append("-framework") catch unreachable;
|
|
|
|
zig_args.append(entry.key) catch unreachable;
|
2017-09-23 14:59:30 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-01 21:07:43 -07:00
|
|
|
if (self.system_linker_hack) {
|
|
|
|
try zig_args.append("--system-linker-hack");
|
|
|
|
}
|
2018-07-24 18:28:54 -07:00
|
|
|
|
2019-07-18 17:03:38 -07:00
|
|
|
if (self.valgrind_support) |valgrind_support| {
|
|
|
|
if (valgrind_support) {
|
|
|
|
try zig_args.append("--enable-valgrind");
|
|
|
|
} else {
|
|
|
|
try zig_args.append("--disable-valgrind");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
stage1 is now a hybrid of C++ and Zig
This modifies the build process of Zig to put all of the source files
into libcompiler.a, except main.cpp and userland.cpp.
Next, the build process links main.cpp, userland.cpp, and libcompiler.a
into zig1. userland.cpp is a shim for functions that will later be
replaced with self-hosted implementations.
Next, the build process uses zig1 to build src-self-hosted/stage1.zig
into libuserland.a, which does not depend on any of the things that
are shimmed in userland.cpp, such as translate-c.
Finally, the build process re-links main.cpp and libcompiler.a, except
with libuserland.a instead of userland.cpp. Now the shims are replaced
with .zig code. This provides all of the Zig standard library to the
stage1 C++ compiler, and enables us to move certain things to userland,
such as translate-c.
As a proof of concept I have made the `zig zen` command use text defined
in userland. I added `zig translate-c-2` which is a work-in-progress
reimplementation of translate-c in userland, which currently calls
`std.debug.panic("unimplemented")` and you can see the stack trace makes
it all the way back into the C++ main() function (Thanks LemonBoy for
improving that!).
This could potentially let us move other things into userland, such as
hashing algorithms, the entire cache system, .d file parsing, pretty
much anything that libuserland.a itself doesn't need to depend on.
This can also let us have `zig fmt` in stage1 without the overhead
of child process execution, and without the initial compilation delay
before it gets cached.
See #1964
2019-04-16 13:47:47 -07:00
|
|
|
if (self.override_lib_dir) |dir| {
|
|
|
|
try zig_args.append("--override-lib-dir");
|
|
|
|
try zig_args.append(builder.pathFromRoot(dir));
|
|
|
|
} else if (self.builder.override_lib_dir) |dir| {
|
|
|
|
try zig_args.append("--override-lib-dir");
|
|
|
|
try zig_args.append(builder.pathFromRoot(dir));
|
2019-02-06 11:32:20 -08:00
|
|
|
}
|
2018-07-24 18:28:54 -07:00
|
|
|
|
2019-03-02 07:38:27 -08:00
|
|
|
if (self.main_pkg_path) |dir| {
|
|
|
|
try zig_args.append("--main-pkg-path");
|
|
|
|
try zig_args.append(builder.pathFromRoot(dir));
|
|
|
|
}
|
|
|
|
|
2019-10-07 14:22:28 -07:00
|
|
|
if (self.force_pic) |pic| {
|
|
|
|
if (pic) {
|
|
|
|
try zig_args.append("-fPIC");
|
|
|
|
} else {
|
|
|
|
try zig_args.append("-fno-PIC");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-18 11:11:28 -07:00
|
|
|
if (self.subsystem) |subsystem| {
|
|
|
|
try zig_args.append("--subsystem");
|
|
|
|
try zig_args.append(switch (subsystem) {
|
|
|
|
.Console => "console",
|
|
|
|
.Windows => "windows",
|
|
|
|
.Posix => "posix",
|
|
|
|
.Native => "native",
|
|
|
|
.EfiApplication => "efi_application",
|
|
|
|
.EfiBootServiceDriver => "efi_boot_service_driver",
|
|
|
|
.EfiRom => "efi_rom",
|
|
|
|
.EfiRuntimeDriver => "efi_runtime_driver",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-07-14 00:06:20 -07:00
|
|
|
if (self.kind == Kind.Test) {
|
2020-03-30 11:23:22 -07:00
|
|
|
try builder.spawnChild(zig_args.span());
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
} else {
|
|
|
|
try zig_args.append("--cache");
|
|
|
|
try zig_args.append("on");
|
|
|
|
|
2020-03-30 11:23:22 -07:00
|
|
|
const output_dir_nl = try builder.execFromStep(zig_args.span(), &self.step);
|
zig build system: correctly handle multiple output artifacts
Previously the zig build system incorrectly assumed that the only build
artifact was a binary. Now, when you enable the cache, only the output
dir is printed to stdout, and the zig build system iterates over the
files in that directory, copying them to the output directory.
To support this change:
* Add `std.os.renameat`, `std.os.renameatZ`, and `std.os.renameatW`.
* Fix `std.os.linux.renameat` not compiling due to typos.
* Deprecate `std.fs.updateFile` and `std.fs.updateFileMode`.
* Add `std.fs.Dir.updateFile`, which supports using open directory
handles for both the source and destination paths, as well as an
options parameter which allows overriding the mode.
* Update `std.fs.AtomicFile` to support operating based on an open
directory handle. Instead of `std.fs.AtomicFile.init`, use
`std.fs.Dir.atomicFile`.
* `std.fs.AtomicFile` deinit() better handles the situation when the
rename fails but the temporary file still exists, by still
attempting to remove the temporary file.
* `std.fs.Dir.openFileWindows` is moved to `std.os.windows.OpenFileW`.
* `std.os.RenameError` gains the error codes `NoDevice`,
`SharingViolation`, and `PipeBusy` which have been observed from
Windows.
Closes #4733
2020-03-13 18:06:07 -07:00
|
|
|
const build_output_dir = mem.trimRight(u8, output_dir_nl, "\r\n");
|
2019-07-14 00:06:20 -07:00
|
|
|
|
|
|
|
if (self.output_dir) |output_dir| {
|
2020-03-18 11:45:01 -07:00
|
|
|
var src_dir = try std.fs.cwd().openDir(build_output_dir, .{ .iterate = true });
|
zig build system: correctly handle multiple output artifacts
Previously the zig build system incorrectly assumed that the only build
artifact was a binary. Now, when you enable the cache, only the output
dir is printed to stdout, and the zig build system iterates over the
files in that directory, copying them to the output directory.
To support this change:
* Add `std.os.renameat`, `std.os.renameatZ`, and `std.os.renameatW`.
* Fix `std.os.linux.renameat` not compiling due to typos.
* Deprecate `std.fs.updateFile` and `std.fs.updateFileMode`.
* Add `std.fs.Dir.updateFile`, which supports using open directory
handles for both the source and destination paths, as well as an
options parameter which allows overriding the mode.
* Update `std.fs.AtomicFile` to support operating based on an open
directory handle. Instead of `std.fs.AtomicFile.init`, use
`std.fs.Dir.atomicFile`.
* `std.fs.AtomicFile` deinit() better handles the situation when the
rename fails but the temporary file still exists, by still
attempting to remove the temporary file.
* `std.fs.Dir.openFileWindows` is moved to `std.os.windows.OpenFileW`.
* `std.os.RenameError` gains the error codes `NoDevice`,
`SharingViolation`, and `PipeBusy` which have been observed from
Windows.
Closes #4733
2020-03-13 18:06:07 -07:00
|
|
|
defer src_dir.close();
|
|
|
|
|
2020-04-16 01:03:42 -07:00
|
|
|
// Create the output directory if it doesn't exist.
|
|
|
|
try std.fs.cwd().makePath(output_dir);
|
|
|
|
|
2020-03-18 11:45:01 -07:00
|
|
|
var dest_dir = try std.fs.cwd().openDir(output_dir, .{});
|
zig build system: correctly handle multiple output artifacts
Previously the zig build system incorrectly assumed that the only build
artifact was a binary. Now, when you enable the cache, only the output
dir is printed to stdout, and the zig build system iterates over the
files in that directory, copying them to the output directory.
To support this change:
* Add `std.os.renameat`, `std.os.renameatZ`, and `std.os.renameatW`.
* Fix `std.os.linux.renameat` not compiling due to typos.
* Deprecate `std.fs.updateFile` and `std.fs.updateFileMode`.
* Add `std.fs.Dir.updateFile`, which supports using open directory
handles for both the source and destination paths, as well as an
options parameter which allows overriding the mode.
* Update `std.fs.AtomicFile` to support operating based on an open
directory handle. Instead of `std.fs.AtomicFile.init`, use
`std.fs.Dir.atomicFile`.
* `std.fs.AtomicFile` deinit() better handles the situation when the
rename fails but the temporary file still exists, by still
attempting to remove the temporary file.
* `std.fs.Dir.openFileWindows` is moved to `std.os.windows.OpenFileW`.
* `std.os.RenameError` gains the error codes `NoDevice`,
`SharingViolation`, and `PipeBusy` which have been observed from
Windows.
Closes #4733
2020-03-13 18:06:07 -07:00
|
|
|
defer dest_dir.close();
|
|
|
|
|
|
|
|
var it = src_dir.iterate();
|
|
|
|
while (try it.next()) |entry| {
|
|
|
|
_ = try src_dir.updateFile(entry.name, dest_dir, entry.name, .{});
|
|
|
|
}
|
2019-07-14 00:06:20 -07:00
|
|
|
} else {
|
zig build system: correctly handle multiple output artifacts
Previously the zig build system incorrectly assumed that the only build
artifact was a binary. Now, when you enable the cache, only the output
dir is printed to stdout, and the zig build system iterates over the
files in that directory, copying them to the output directory.
To support this change:
* Add `std.os.renameat`, `std.os.renameatZ`, and `std.os.renameatW`.
* Fix `std.os.linux.renameat` not compiling due to typos.
* Deprecate `std.fs.updateFile` and `std.fs.updateFileMode`.
* Add `std.fs.Dir.updateFile`, which supports using open directory
handles for both the source and destination paths, as well as an
options parameter which allows overriding the mode.
* Update `std.fs.AtomicFile` to support operating based on an open
directory handle. Instead of `std.fs.AtomicFile.init`, use
`std.fs.Dir.atomicFile`.
* `std.fs.AtomicFile` deinit() better handles the situation when the
rename fails but the temporary file still exists, by still
attempting to remove the temporary file.
* `std.fs.Dir.openFileWindows` is moved to `std.os.windows.OpenFileW`.
* `std.os.RenameError` gains the error codes `NoDevice`,
`SharingViolation`, and `PipeBusy` which have been observed from
Windows.
Closes #4733
2020-03-13 18:06:07 -07:00
|
|
|
self.output_dir = build_output_dir;
|
2019-07-14 00:06:20 -07:00
|
|
|
}
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
}
|
2019-02-25 08:37:54 -08:00
|
|
|
|
2019-03-13 16:33:19 -07:00
|
|
|
if (self.kind == Kind.Lib and self.is_dynamic and self.target.wantSharedLibSymLinks()) {
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 19:53:35 -08:00
|
|
|
try doAtomicSymLinks(builder.allocator, self.getOutputPath(), self.major_only_filename, self.name_only_filename);
|
2019-02-25 08:37:54 -08:00
|
|
|
}
|
2017-09-17 23:50:51 -07:00
|
|
|
}
|
2017-04-13 14:21:00 -07:00
|
|
|
};
|
|
|
|
|
2018-11-13 05:08:37 -08:00
|
|
|
const InstallArtifactStep = struct {
|
2017-09-17 23:50:51 -07:00
|
|
|
step: Step,
|
2018-05-31 07:56:59 -07:00
|
|
|
builder: *Builder,
|
|
|
|
artifact: *LibExeObjStep,
|
2019-07-04 12:32:44 -07:00
|
|
|
dest_dir: InstallDir,
|
2019-07-08 15:48:03 -07:00
|
|
|
pdb_dir: ?InstallDir,
|
2019-12-18 19:10:17 -08:00
|
|
|
h_dir: ?InstallDir,
|
2017-09-17 23:50:51 -07:00
|
|
|
|
2018-09-13 13:34:33 -07:00
|
|
|
const Self = @This();
|
2017-09-17 23:50:51 -07:00
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn create(builder: *Builder, artifact: *LibExeObjStep) *Self {
|
2019-07-04 12:32:44 -07:00
|
|
|
if (artifact.install_step) |s| return s;
|
|
|
|
|
2019-02-03 13:13:28 -08:00
|
|
|
const self = builder.allocator.create(Self) catch unreachable;
|
|
|
|
self.* = Self{
|
2017-09-17 23:50:51 -07:00
|
|
|
.builder = builder,
|
2019-12-08 19:53:51 -08:00
|
|
|
.step = Step.init(builder.fmt("install {}", .{artifact.step.name}), builder.allocator, make),
|
2017-09-17 23:50:51 -07:00
|
|
|
.artifact = artifact,
|
2019-07-04 12:32:44 -07:00
|
|
|
.dest_dir = switch (artifact.kind) {
|
|
|
|
.Obj => unreachable,
|
|
|
|
.Test => unreachable,
|
2019-12-18 19:10:17 -08:00
|
|
|
.Exe => .Bin,
|
|
|
|
.Lib => .Lib,
|
2019-07-04 12:32:44 -07:00
|
|
|
},
|
2019-07-10 16:40:46 -07:00
|
|
|
.pdb_dir = if (artifact.producesPdbFile()) blk: {
|
2019-07-08 15:48:03 -07:00
|
|
|
if (artifact.kind == .Exe) {
|
|
|
|
break :blk InstallDir.Bin;
|
|
|
|
} else {
|
|
|
|
break :blk InstallDir.Lib;
|
|
|
|
}
|
|
|
|
} else null,
|
2020-03-20 15:33:36 -07:00
|
|
|
.h_dir = if (artifact.kind == .Lib and artifact.emit_h) .Header else null,
|
2019-02-06 21:42:41 -08:00
|
|
|
};
|
2017-09-17 23:50:51 -07:00
|
|
|
self.step.dependOn(&artifact.step);
|
2019-07-04 12:32:44 -07:00
|
|
|
artifact.install_step = self;
|
|
|
|
|
|
|
|
builder.pushInstalledFile(self.dest_dir, artifact.out_filename);
|
|
|
|
if (self.artifact.isDynamicLibrary()) {
|
|
|
|
builder.pushInstalledFile(.Lib, artifact.major_only_filename);
|
|
|
|
builder.pushInstalledFile(.Lib, artifact.name_only_filename);
|
2019-11-27 00:30:39 -08:00
|
|
|
if (self.artifact.target.isWindows()) {
|
|
|
|
builder.pushInstalledFile(.Lib, artifact.out_lib_filename);
|
|
|
|
}
|
2017-04-17 03:45:44 -07:00
|
|
|
}
|
2019-07-08 15:48:03 -07:00
|
|
|
if (self.pdb_dir) |pdb_dir| {
|
|
|
|
builder.pushInstalledFile(pdb_dir, artifact.out_pdb_filename);
|
|
|
|
}
|
2019-12-18 19:10:17 -08:00
|
|
|
if (self.h_dir) |h_dir| {
|
|
|
|
builder.pushInstalledFile(h_dir, artifact.out_h_filename);
|
|
|
|
}
|
2017-09-17 23:50:51 -07:00
|
|
|
return self;
|
|
|
|
}
|
2017-04-17 03:45:44 -07:00
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
fn make(step: *Step) !void {
|
2017-09-17 23:50:51 -07:00
|
|
|
const self = @fieldParentPtr(Self, "step", step);
|
|
|
|
const builder = self.builder;
|
2017-04-17 03:45:44 -07:00
|
|
|
|
2019-07-04 12:32:44 -07:00
|
|
|
const full_dest_path = builder.getInstallPath(self.dest_dir, self.artifact.out_filename);
|
2019-07-14 00:06:20 -07:00
|
|
|
try builder.updateFile(self.artifact.getOutputPath(), full_dest_path);
|
2019-11-26 12:37:38 -08:00
|
|
|
if (self.artifact.isDynamicLibrary() and self.artifact.target.wantSharedLibSymLinks()) {
|
2019-07-04 12:32:44 -07:00
|
|
|
try doAtomicSymLinks(builder.allocator, full_dest_path, self.artifact.major_only_filename, self.artifact.name_only_filename);
|
2017-04-17 03:45:44 -07:00
|
|
|
}
|
2019-07-08 15:48:03 -07:00
|
|
|
if (self.pdb_dir) |pdb_dir| {
|
|
|
|
const full_pdb_path = builder.getInstallPath(pdb_dir, self.artifact.out_pdb_filename);
|
2019-07-14 00:06:20 -07:00
|
|
|
try builder.updateFile(self.artifact.getOutputPdbPath(), full_pdb_path);
|
2019-07-08 15:48:03 -07:00
|
|
|
}
|
2019-12-18 19:10:17 -08:00
|
|
|
if (self.h_dir) |h_dir| {
|
|
|
|
const full_pdb_path = builder.getInstallPath(h_dir, self.artifact.out_h_filename);
|
|
|
|
try builder.updateFile(self.artifact.getOutputHPath(), full_pdb_path);
|
|
|
|
}
|
2019-07-04 12:32:44 -07:00
|
|
|
self.artifact.installed_path = full_dest_path;
|
2017-04-17 03:45:44 -07:00
|
|
|
}
|
2017-09-17 23:50:51 -07:00
|
|
|
};
|
2017-04-17 03:45:44 -07:00
|
|
|
|
2018-11-13 05:08:37 -08:00
|
|
|
pub const InstallFileStep = struct {
|
2017-04-17 03:45:44 -07:00
|
|
|
step: Step,
|
2018-05-31 07:56:59 -07:00
|
|
|
builder: *Builder,
|
2017-04-17 03:45:44 -07:00
|
|
|
src_path: []const u8,
|
2019-07-04 12:32:44 -07:00
|
|
|
dir: InstallDir,
|
|
|
|
dest_rel_path: []const u8,
|
|
|
|
|
|
|
|
pub fn init(
|
|
|
|
builder: *Builder,
|
|
|
|
src_path: []const u8,
|
|
|
|
dir: InstallDir,
|
|
|
|
dest_rel_path: []const u8,
|
|
|
|
) InstallFileStep {
|
|
|
|
builder.pushInstalledFile(dir, dest_rel_path);
|
2018-11-13 05:08:37 -08:00
|
|
|
return InstallFileStep{
|
2017-04-17 03:45:44 -07:00
|
|
|
.builder = builder,
|
2019-12-08 19:53:51 -08:00
|
|
|
.step = Step.init(builder.fmt("install {}", .{src_path}), builder.allocator, make),
|
2017-04-17 03:45:44 -07:00
|
|
|
.src_path = src_path,
|
2019-07-04 12:32:44 -07:00
|
|
|
.dir = dir,
|
|
|
|
.dest_rel_path = dest_rel_path,
|
2017-04-17 03:45:44 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
fn make(step: *Step) !void {
|
2017-04-17 23:28:05 -07:00
|
|
|
const self = @fieldParentPtr(InstallFileStep, "step", step);
|
2019-07-04 12:32:44 -07:00
|
|
|
const full_dest_path = self.builder.getInstallPath(self.dir, self.dest_rel_path);
|
2019-07-14 00:06:20 -07:00
|
|
|
const full_src_path = self.builder.pathFromRoot(self.src_path);
|
|
|
|
try self.builder.updateFile(full_src_path, full_dest_path);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
pub const InstallDirectoryOptions = struct {
|
|
|
|
source_dir: []const u8,
|
|
|
|
install_dir: InstallDir,
|
|
|
|
install_subdir: []const u8,
|
|
|
|
exclude_extensions: ?[]const []const u8 = null,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub const InstallDirStep = struct {
|
|
|
|
step: Step,
|
|
|
|
builder: *Builder,
|
|
|
|
options: InstallDirectoryOptions,
|
|
|
|
|
|
|
|
pub fn init(
|
|
|
|
builder: *Builder,
|
|
|
|
options: InstallDirectoryOptions,
|
|
|
|
) InstallDirStep {
|
|
|
|
builder.pushInstalledFile(options.install_dir, options.install_subdir);
|
|
|
|
return InstallDirStep{
|
|
|
|
.builder = builder,
|
2019-12-08 19:53:51 -08:00
|
|
|
.step = Step.init(builder.fmt("install {}/", .{options.source_dir}), builder.allocator, make),
|
2019-07-14 00:06:20 -07:00
|
|
|
.options = options,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make(step: *Step) !void {
|
|
|
|
const self = @fieldParentPtr(InstallDirStep, "step", step);
|
|
|
|
const dest_prefix = self.builder.getInstallPath(self.options.install_dir, self.options.install_subdir);
|
|
|
|
const full_src_dir = self.builder.pathFromRoot(self.options.source_dir);
|
|
|
|
var it = try fs.walkPath(self.builder.allocator, full_src_dir);
|
|
|
|
next_entry: while (try it.next()) |entry| {
|
|
|
|
if (self.options.exclude_extensions) |ext_list| for (ext_list) |ext| {
|
|
|
|
if (mem.endsWith(u8, entry.path, ext)) {
|
|
|
|
continue :next_entry;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const rel_path = entry.path[full_src_dir.len + 1 ..];
|
2019-11-27 00:30:39 -08:00
|
|
|
const dest_path = try fs.path.join(self.builder.allocator, &[_][]const u8{ dest_prefix, rel_path });
|
2019-07-14 00:06:20 -07:00
|
|
|
switch (entry.kind) {
|
2020-01-15 18:21:00 -08:00
|
|
|
.Directory => try fs.cwd().makePath(dest_path),
|
2019-07-14 00:06:20 -07:00
|
|
|
.File => try self.builder.updateFile(entry.path, dest_path),
|
|
|
|
else => continue,
|
|
|
|
}
|
|
|
|
}
|
2017-04-17 03:45:44 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-11-13 05:08:37 -08:00
|
|
|
pub const LogStep = struct {
|
2017-04-18 22:13:15 -07:00
|
|
|
step: Step,
|
2018-05-31 07:56:59 -07:00
|
|
|
builder: *Builder,
|
2017-04-18 22:13:15 -07:00
|
|
|
data: []const u8,
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn init(builder: *Builder, data: []const u8) LogStep {
|
2018-11-13 05:08:37 -08:00
|
|
|
return LogStep{
|
2017-04-18 22:13:15 -07:00
|
|
|
.builder = builder,
|
2019-12-08 19:53:51 -08:00
|
|
|
.step = Step.init(builder.fmt("log {}", .{data}), builder.allocator, make),
|
2017-04-18 22:13:15 -07:00
|
|
|
.data = data,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-11-13 05:08:37 -08:00
|
|
|
fn make(step: *Step) anyerror!void {
|
2017-04-18 22:13:15 -07:00
|
|
|
const self = @fieldParentPtr(LogStep, "step", step);
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("{}", .{self.data});
|
2017-04-18 22:13:15 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-11-13 05:08:37 -08:00
|
|
|
pub const RemoveDirStep = struct {
|
2017-04-19 23:26:36 -07:00
|
|
|
step: Step,
|
2018-05-31 07:56:59 -07:00
|
|
|
builder: *Builder,
|
2017-04-19 23:26:36 -07:00
|
|
|
dir_path: []const u8,
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn init(builder: *Builder, dir_path: []const u8) RemoveDirStep {
|
2018-11-13 05:08:37 -08:00
|
|
|
return RemoveDirStep{
|
2017-04-19 23:26:36 -07:00
|
|
|
.builder = builder,
|
2019-12-08 19:53:51 -08:00
|
|
|
.step = Step.init(builder.fmt("RemoveDir {}", .{dir_path}), builder.allocator, make),
|
2017-04-19 23:26:36 -07:00
|
|
|
.dir_path = dir_path,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
fn make(step: *Step) !void {
|
2017-04-19 23:26:36 -07:00
|
|
|
const self = @fieldParentPtr(RemoveDirStep, "step", step);
|
|
|
|
|
|
|
|
const full_path = self.builder.pathFromRoot(self.dir_path);
|
2020-03-18 13:09:06 -07:00
|
|
|
fs.cwd().deleteTree(full_path) catch |err| {
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("Unable to remove {}: {}\n", .{ full_path, @errorName(err) });
|
2017-04-19 23:26:36 -07:00
|
|
|
return err;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-11-13 05:08:37 -08:00
|
|
|
pub const Step = struct {
|
2017-04-13 14:21:00 -07:00
|
|
|
name: []const u8,
|
2018-11-13 05:08:37 -08:00
|
|
|
makeFn: fn (self: *Step) anyerror!void,
|
2018-05-31 07:56:59 -07:00
|
|
|
dependencies: ArrayList(*Step),
|
2017-04-13 14:21:00 -07:00
|
|
|
loop_flag: bool,
|
|
|
|
done_flag: bool,
|
|
|
|
|
2018-11-13 05:08:37 -08:00
|
|
|
pub fn init(name: []const u8, allocator: *Allocator, makeFn: fn (*Step) anyerror!void) Step {
|
|
|
|
return Step{
|
2017-04-13 14:21:00 -07:00
|
|
|
.name = name,
|
|
|
|
.makeFn = makeFn,
|
2018-05-31 07:56:59 -07:00
|
|
|
.dependencies = ArrayList(*Step).init(allocator),
|
2017-04-13 14:21:00 -07:00
|
|
|
.loop_flag = false,
|
|
|
|
.done_flag = false,
|
2017-12-21 21:50:30 -08:00
|
|
|
};
|
2017-04-13 14:21:00 -07:00
|
|
|
}
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn initNoOp(name: []const u8, allocator: *Allocator) Step {
|
2017-12-21 21:50:30 -08:00
|
|
|
return init(name, allocator, makeNoOp);
|
2017-04-13 14:21:00 -07:00
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn make(self: *Step) !void {
|
2018-05-09 21:29:49 -07:00
|
|
|
if (self.done_flag) return;
|
2017-04-13 14:21:00 -07:00
|
|
|
|
2018-01-07 13:51:46 -08:00
|
|
|
try self.makeFn(self);
|
2017-04-13 14:21:00 -07:00
|
|
|
self.done_flag = true;
|
|
|
|
}
|
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
pub fn dependOn(self: *Step, other: *Step) void {
|
2018-01-08 21:07:01 -08:00
|
|
|
self.dependencies.append(other) catch unreachable;
|
2017-04-13 14:21:00 -07:00
|
|
|
}
|
|
|
|
|
2018-11-13 05:08:37 -08:00
|
|
|
fn makeNoOp(self: *Step) anyerror!void {}
|
2017-04-13 14:21:00 -07:00
|
|
|
};
|
2017-04-30 15:56:24 -07:00
|
|
|
|
2018-05-31 07:56:59 -07:00
|
|
|
fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_major_only: []const u8, filename_name_only: []const u8) !void {
|
2019-05-26 10:17:34 -07:00
|
|
|
const out_dir = fs.path.dirname(output_path) orelse ".";
|
|
|
|
const out_basename = fs.path.basename(output_path);
|
2017-04-30 15:56:24 -07:00
|
|
|
// sym link for libfoo.so.1 to libfoo.so.1.2.3
|
2019-05-26 10:17:34 -07:00
|
|
|
const major_only_path = fs.path.join(
|
2019-02-06 21:42:41 -08:00
|
|
|
allocator,
|
2019-11-27 00:30:39 -08:00
|
|
|
&[_][]const u8{ out_dir, filename_major_only },
|
2019-02-06 21:42:41 -08:00
|
|
|
) catch unreachable;
|
2019-05-26 10:17:34 -07:00
|
|
|
fs.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("Unable to symlink {} -> {}\n", .{ major_only_path, out_basename });
|
2017-04-30 15:56:24 -07:00
|
|
|
return err;
|
|
|
|
};
|
|
|
|
// sym link for libfoo.so to libfoo.so.1
|
2019-05-26 10:17:34 -07:00
|
|
|
const name_only_path = fs.path.join(
|
2019-02-06 21:42:41 -08:00
|
|
|
allocator,
|
2019-11-27 00:30:39 -08:00
|
|
|
&[_][]const u8{ out_dir, filename_name_only },
|
2019-02-06 21:42:41 -08:00
|
|
|
) catch unreachable;
|
2019-05-26 10:17:34 -07:00
|
|
|
fs.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| {
|
2019-12-08 19:53:51 -08:00
|
|
|
warn("Unable to symlink {} -> {}\n", .{ name_only_path, filename_major_only });
|
2017-04-30 15:56:24 -07:00
|
|
|
return err;
|
|
|
|
};
|
|
|
|
}
|
2019-07-04 12:32:44 -07:00
|
|
|
|
2019-10-10 12:58:47 -07:00
|
|
|
/// Returned slice must be freed by the caller.
|
|
|
|
fn findVcpkgRoot(allocator: *Allocator) !?[]const u8 {
|
|
|
|
const appdata_path = try fs.getAppDataDir(allocator, "vcpkg");
|
|
|
|
defer allocator.free(appdata_path);
|
|
|
|
|
2019-11-27 00:30:39 -08:00
|
|
|
const path_file = try fs.path.join(allocator, &[_][]const u8{ appdata_path, "vcpkg.path.txt" });
|
2019-10-10 12:58:47 -07:00
|
|
|
defer allocator.free(path_file);
|
|
|
|
|
2019-11-30 12:14:04 -08:00
|
|
|
const file = fs.cwd().openFile(path_file, .{}) catch return null;
|
2019-10-10 12:58:47 -07:00
|
|
|
defer file.close();
|
|
|
|
|
|
|
|
const size = @intCast(usize, try file.getEndPos());
|
|
|
|
const vcpkg_path = try allocator.alloc(u8, size);
|
|
|
|
const size_read = try file.read(vcpkg_path);
|
|
|
|
std.debug.assert(size == size_read);
|
|
|
|
|
|
|
|
return vcpkg_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
const VcpkgRoot = union(VcpkgRootStatus) {
|
|
|
|
Unattempted: void,
|
|
|
|
NotFound: void,
|
|
|
|
Found: []const u8,
|
|
|
|
};
|
|
|
|
|
|
|
|
const VcpkgRootStatus = enum {
|
|
|
|
Unattempted,
|
|
|
|
NotFound,
|
|
|
|
Found,
|
|
|
|
};
|
|
|
|
|
2020-02-25 22:18:23 -08:00
|
|
|
pub const VcpkgLinkage = std.builtin.LinkMode;
|
2019-10-10 12:58:47 -07:00
|
|
|
|
2019-07-04 12:32:44 -07:00
|
|
|
pub const InstallDir = enum {
|
|
|
|
Prefix,
|
|
|
|
Lib,
|
|
|
|
Bin,
|
2019-12-18 19:10:17 -08:00
|
|
|
Header,
|
2019-07-04 12:32:44 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
pub const InstalledFile = struct {
|
|
|
|
dir: InstallDir,
|
|
|
|
path: []const u8,
|
|
|
|
};
|