Merge pull request #7309 from ziglang/build-stage1-with-only-zig

ability to build stage1 using only a zig tarball
This commit is contained in:
Andrew Kelley 2020-12-07 23:54:34 -05:00 committed by GitHub
commit a01d55e801
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 677 additions and 353 deletions

View File

@ -63,9 +63,6 @@ endif()
if(ZIG_STATIC)
set(ZIG_STATIC_LLVM "on")
set(ZIG_LINK_MODE "Static")
else()
set(ZIG_LINK_MODE "Dynamic")
endif()
string(REGEX REPLACE "\\\\" "\\\\\\\\" ZIG_LIBC_LIB_DIR_ESCAPED "${ZIG_LIBC_LIB_DIR}")
@ -594,6 +591,12 @@ else(MSVC)
set(EXE_CFLAGS "-std=c++14")
endif(MSVC)
if(ZIG_STATIC)
set(EXE_CFLAGS "${EXE_CFLAGS} -DZIG_LINK_MODE=Static")
else()
set(EXE_CFLAGS "${EXE_CFLAGS} -DZIG_LINK_MODE=Dynamic")
endif()
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
if(MSVC)
set(EXE_CFLAGS "${EXE_CFLAGS} /w")

View File

@ -14,98 +14,12 @@ A general-purpose programming language and toolchain for maintaining
* [Frequently Asked Questions](https://github.com/ziglang/zig/wiki/FAQ)
* [Community Projects](https://github.com/ziglang/zig/wiki/Community-Projects)
## Building from Source
## Installation
[![Build Status](https://dev.azure.com/ziglang/zig/_apis/build/status/ziglang.zig?branchName=master)](https://dev.azure.com/ziglang/zig/_build/latest?definitionId=1&branchName=master)
Note that you can
[download a binary of the master branch](https://ziglang.org/download/#release-master) or
[install Zig from a package manager](https://github.com/ziglang/zig/wiki/Install-Zig-from-a-Package-Manager).
### Stage 1: Build Zig from C++ Source Code
This step must be repeated when you make changes to any of the C++ source code.
#### Dependencies
##### POSIX
* cmake >= 2.8.5
* gcc >= 5.0.0 or clang >= 3.6.0
* LLVM, Clang, LLD development libraries == 11.x, compiled with the same gcc or clang version above
- Use the system package manager, or [build from source](https://github.com/ziglang/zig/wiki/How-to-build-LLVM,-libclang,-and-liblld-from-source#posix).
##### Windows
* cmake >= 3.15.3
* Microsoft Visual Studio. Supported versions:
- 2017 (version 15.8)
- 2019 (version 16)
* LLVM, Clang, LLD development libraries == 11.x
- Use the [pre-built binaries](https://github.com/ziglang/zig/wiki/Building-Zig-on-Windows) or [build from source](https://github.com/ziglang/zig/wiki/How-to-build-LLVM,-libclang,-and-liblld-from-source#windows).
#### Instructions
##### POSIX
```
mkdir build
cd build
cmake ..
make install
```
Need help? [Troubleshooting Build Issues](https://github.com/ziglang/zig/wiki/Troubleshooting-Build-Issues)
##### MacOS
```
brew install cmake llvm
brew outdated llvm || brew upgrade llvm
mkdir build
cd build
cmake .. -DCMAKE_PREFIX_PATH=$(brew --prefix llvm)
make install
```
##### Windows
See https://github.com/ziglang/zig/wiki/Building-Zig-on-Windows
### Stage 2: Build Self-Hosted Zig from Zig Source Code
Now we use the stage1 binary:
```
zig build --prefix $(pwd)/stage2 -Denable-llvm
```
This produces `stage2/bin/zig` which can be used for testing and development.
Once it is feature complete, it will be used to build stage 3 - the final compiler
binary.
### Stage 3: Rebuild Self-Hosted Zig Using the Self-Hosted Compiler
*Note: Stage 2 compiler is not yet able to build Stage 3. Building Stage 3 is
not yet supported.*
Once the self-hosted compiler can build itself, this will be the actual
compiler binary that we will install to the system. Until then, users should
use stage 1.
#### Debug / Development Build
```
stage2/bin/zig build
```
This produces `zig-cache/bin/zig`.
#### Release / Install Build
```
stage2/bin/zig build install -Drelease
```
* [download a pre-built binary](https://ziglang.org/download/)
* [install from a package manager](https://github.com/ziglang/zig/wiki/Install-Zig-from-a-Package-Manager)
* [build from source](https://github.com/ziglang/zig/wiki/Building-Zig-From-Source)
* [bootstrap zig for any target](https://github.com/ziglang/zig-bootstrap)
## License

768
build.zig
View File

@ -53,7 +53,9 @@ pub fn build(b: *Builder) !void {
const skip_compile_errors = b.option(bool, "skip-compile-errors", "Main test suite skips compile error tests") orelse false;
const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false;
const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse false;
const is_stage1 = b.option(bool, "stage1", "Build the stage1 compiler, put stage2 behind a feature flag") orelse false;
const static_llvm = b.option(bool, "static-llvm", "Disable integration with system-installed LLVM, Clang, LLD, and libc++") orelse false;
const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse (is_stage1 or static_llvm);
const config_h_path_option = b.option([]const u8, "config_h", "Path to the generated config.h");
b.installDirectory(InstallDirectoryOptions{
@ -76,7 +78,9 @@ pub fn build(b: *Builder) !void {
const tracy = b.option([]const u8, "tracy", "Enable Tracy integration. Supply path to Tracy source");
const link_libc = b.option(bool, "force-link-libc", "Force self-hosted compiler to link libc") orelse enable_llvm;
var exe = b.addExecutable("zig", "src/main.zig");
const main_file = if (is_stage1) "src/stage1.zig" else "src/main.zig";
var exe = b.addExecutable("zig", main_file);
exe.install();
exe.setBuildMode(mode);
exe.setTarget(target);
@ -86,15 +90,126 @@ pub fn build(b: *Builder) !void {
exe.addBuildOption(bool, "skip_non_native", skip_non_native);
exe.addBuildOption(bool, "have_llvm", enable_llvm);
if (enable_llvm) {
const config_h_text = if (config_h_path_option) |config_h_path|
try std.fs.cwd().readFileAlloc(b.allocator, toNativePathSep(b, config_h_path), max_config_h_bytes)
else
try findAndReadConfigH(b);
const cmake_cfg = if (static_llvm) null else findAndParseConfigH(b, config_h_path_option);
if (is_stage1) {
exe.addIncludeDir("src");
exe.addIncludeDir("deps/SoftFloat-3e/source/include");
// This is intentionally a dummy path. stage1.zig tries to @import("compiler_rt") in case
// of being built by cmake. But when built by zig it's gonna get a compiler_rt so that
// is pointless.
exe.addPackagePath("compiler_rt", "src/empty.zig");
exe.defineCMacro("ZIG_LINK_MODE=Static");
var ctx = parseConfigH(b, config_h_text);
ctx.llvm = try findLLVM(b, ctx.llvm_config_exe);
const softfloat = b.addStaticLibrary("softfloat", null);
softfloat.setBuildMode(.ReleaseFast);
softfloat.setTarget(target);
softfloat.addIncludeDir("deps/SoftFloat-3e-prebuilt");
softfloat.addIncludeDir("deps/SoftFloat-3e/source/8086");
softfloat.addIncludeDir("deps/SoftFloat-3e/source/include");
softfloat.addCSourceFiles(&softfloat_sources, &[_][]const u8{ "-std=c99", "-O3" });
exe.linkLibrary(softfloat);
try configureStage2(b, exe, ctx, tracy != null);
const exe_cflags = [_][]const u8{
"-std=c++14",
"-D__STDC_CONSTANT_MACROS",
"-D__STDC_FORMAT_MACROS",
"-D__STDC_LIMIT_MACROS",
"-D_GNU_SOURCE",
"-fvisibility-inlines-hidden",
"-fno-exceptions",
"-fno-rtti",
"-Werror=type-limits",
"-Wno-missing-braces",
"-Wno-comment",
};
exe.addCSourceFiles(&stage1_sources, &exe_cflags);
exe.addCSourceFiles(&optimized_c_sources, &[_][]const u8{ "-std=c99", "-O3" });
if (cmake_cfg == null) {
// We need this because otherwise zig_clang_cc1_main.cpp ends up pulling
// in a dependency on llvm::cfg::Update<llvm::BasicBlock*>::dump() which is
// unavailable when LLVM is compiled in Release mode.
const zig_cpp_cflags = exe_cflags ++ [_][]const u8{"-DNDEBUG=1"};
exe.addCSourceFiles(&zig_cpp_sources, &zig_cpp_cflags);
}
}
if (cmake_cfg) |cfg| {
// Inside this code path, we have to coordinate with system packaged LLVM, Clang, and LLD.
// That means we also have to rely on stage1 compiled c++ files. We parse config.h to find
// the information passed on to us from cmake.
if (cfg.cmake_prefix_path.len > 0) {
b.addSearchPrefix(cfg.cmake_prefix_path);
}
exe.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{
cfg.cmake_binary_dir,
"zigcpp",
b.fmt("{s}{s}{s}", .{ exe.target.libPrefix(), "zigcpp", exe.target.staticLibSuffix() }),
}) catch unreachable);
assert(cfg.lld_include_dir.len != 0);
exe.addIncludeDir(cfg.lld_include_dir);
addCMakeLibraryList(exe, cfg.clang_libraries);
addCMakeLibraryList(exe, cfg.lld_libraries);
addCMakeLibraryList(exe, cfg.llvm_libraries);
const need_cpp_includes = tracy != null;
// System -lc++ must be used because in this code path we are attempting to link
// against system-provided LLVM, Clang, LLD.
if (exe.target.getOsTag() == .linux) {
// First we try to static link against gcc libstdc++. If that doesn't work,
// we fall back to -lc++ and cross our fingers.
addCxxKnownPath(b, cfg, exe, "libstdc++.a", "", need_cpp_includes) catch |err| switch (err) {
error.RequiredLibraryNotFound => {
exe.linkSystemLibrary("c++");
},
else => |e| return e,
};
exe.linkSystemLibrary("pthread");
} else if (exe.target.isFreeBSD()) {
try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes);
exe.linkSystemLibrary("pthread");
} else if (exe.target.isDarwin()) {
if (addCxxKnownPath(b, cfg, exe, "libgcc_eh.a", "", need_cpp_includes)) {
// Compiler is GCC.
try addCxxKnownPath(b, cfg, exe, "libstdc++.a", null, need_cpp_includes);
exe.linkSystemLibrary("pthread");
// TODO LLD cannot perform this link.
// Set ZIG_SYSTEM_LINKER_HACK env var to use system linker ld instead.
// See https://github.com/ziglang/zig/issues/1535
} else |err| switch (err) {
error.RequiredLibraryNotFound => {
// System compiler, not gcc.
exe.linkSystemLibrary("c++");
},
else => |e| return e,
}
}
if (cfg.dia_guids_lib.len != 0) {
exe.addObjectFile(cfg.dia_guids_lib);
}
} else {
// Here we are -Denable-llvm but no cmake integration.
for (clang_libs) |lib_name| {
exe.linkSystemLibrary(lib_name);
}
for (lld_libs) |lib_name| {
exe.linkSystemLibrary(lib_name);
}
for (llvm_libs) |lib_name| {
exe.linkSystemLibrary(lib_name);
}
// This means we rely on clang-or-zig-built LLVM, Clang, LLD libraries.
exe.linkSystemLibrary("c++");
if (target.getOs().tag == .windows) {
exe.linkSystemLibrary("version");
exe.linkSystemLibrary("uuid");
}
}
}
if (link_libc) {
exe.linkLibC();
@ -141,12 +256,15 @@ pub fn build(b: *Builder) !void {
break :v b.fmt("{}+{}{}", .{ version_string, git_sha_trimmed, dirty_suffix });
}
};
exe.addBuildOption([]const u8, "version", version);
exe.addBuildOption([:0]const u8, "version", try b.allocator.dupeZ(u8, version));
const semver = try std.SemanticVersion.parse(version);
exe.addBuildOption(std.SemanticVersion, "semver", semver);
exe.addBuildOption([]const []const u8, "log_scopes", log_scopes);
exe.addBuildOption([]const []const u8, "zir_dumps", zir_dumps);
exe.addBuildOption(bool, "enable_tracy", tracy != null);
exe.addBuildOption(bool, "is_stage1", false);
exe.addBuildOption(bool, "is_stage1", is_stage1);
if (tracy) |tracy_path| {
const client_cpp = fs.path.join(
b.allocator,
@ -168,7 +286,7 @@ pub fn build(b: *Builder) !void {
const glibc_multi_dir = b.option([]const u8, "enable-foreign-glibc", "Provide directory with glibc installations to run cross compiled tests that link glibc");
test_stage2.addBuildOption(bool, "skip_non_native", skip_non_native);
test_stage2.addBuildOption(bool, "is_stage1", false);
test_stage2.addBuildOption(bool, "is_stage1", is_stage1);
test_stage2.addBuildOption(bool, "have_llvm", enable_llvm);
test_stage2.addBuildOption(bool, "enable_qemu", is_qemu_enabled);
test_stage2.addBuildOption(bool, "enable_wine", is_wine_enabled);
@ -226,199 +344,10 @@ pub fn build(b: *Builder) !void {
test_step.dependOn(docs_step);
}
fn dependOnLib(b: *Builder, lib_exe_obj: anytype, dep: LibraryDep) void {
for (dep.libdirs.items) |lib_dir| {
lib_exe_obj.addLibPath(lib_dir);
}
const lib_dir = fs.path.join(
b.allocator,
&[_][]const u8{ dep.prefix, "lib" },
) catch unreachable;
for (dep.system_libs.items) |lib| {
const static_bare_name = if (mem.eql(u8, lib, "curses"))
@as([]const u8, "libncurses.a")
else
b.fmt("lib{}.a", .{lib});
const static_lib_name = fs.path.join(
b.allocator,
&[_][]const u8{ lib_dir, static_bare_name },
) catch unreachable;
const have_static = fileExists(static_lib_name) catch unreachable;
if (have_static) {
lib_exe_obj.addObjectFile(static_lib_name);
} else {
lib_exe_obj.linkSystemLibrary(lib);
}
}
for (dep.libs.items) |lib| {
lib_exe_obj.addObjectFile(lib);
}
for (dep.includes.items) |include_path| {
lib_exe_obj.addIncludeDir(include_path);
}
}
fn fileExists(filename: []const u8) !bool {
fs.cwd().access(filename, .{}) catch |err| switch (err) {
error.FileNotFound => return false,
else => return err,
};
return true;
}
fn addCppLib(b: *Builder, lib_exe_obj: anytype, cmake_binary_dir: []const u8, lib_name: []const u8) void {
lib_exe_obj.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{
cmake_binary_dir,
"zigcpp",
b.fmt("{}{}{}", .{ lib_exe_obj.target.libPrefix(), lib_name, lib_exe_obj.target.staticLibSuffix() }),
}) catch unreachable);
}
const LibraryDep = struct {
prefix: []const u8,
libdirs: ArrayList([]const u8),
libs: ArrayList([]const u8),
system_libs: ArrayList([]const u8),
includes: ArrayList([]const u8),
};
fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
const shared_mode = try b.exec(&[_][]const u8{ llvm_config_exe, "--shared-mode" });
const is_static = mem.startsWith(u8, shared_mode, "static");
const libs_output = if (is_static)
try b.exec(&[_][]const u8{
llvm_config_exe,
"--libfiles",
"--system-libs",
})
else
try b.exec(&[_][]const u8{
llvm_config_exe,
"--libs",
});
const includes_output = try b.exec(&[_][]const u8{ llvm_config_exe, "--includedir" });
const libdir_output = try b.exec(&[_][]const u8{ llvm_config_exe, "--libdir" });
const prefix_output = try b.exec(&[_][]const u8{ llvm_config_exe, "--prefix" });
var result = LibraryDep{
.prefix = mem.tokenize(prefix_output, " \r\n").next().?,
.libs = ArrayList([]const u8).init(b.allocator),
.system_libs = ArrayList([]const u8).init(b.allocator),
.includes = ArrayList([]const u8).init(b.allocator),
.libdirs = ArrayList([]const u8).init(b.allocator),
};
{
var it = mem.tokenize(libs_output, " \r\n");
while (it.next()) |lib_arg| {
if (mem.startsWith(u8, lib_arg, "-l")) {
try result.system_libs.append(lib_arg[2..]);
} else {
if (fs.path.isAbsolute(lib_arg)) {
try result.libs.append(lib_arg);
} else {
var lib_arg_copy = lib_arg;
if (mem.endsWith(u8, lib_arg, ".lib")) {
lib_arg_copy = lib_arg[0 .. lib_arg.len - 4];
}
try result.system_libs.append(lib_arg_copy);
}
}
}
}
{
var it = mem.tokenize(includes_output, " \r\n");
while (it.next()) |include_arg| {
if (mem.startsWith(u8, include_arg, "-I")) {
try result.includes.append(include_arg[2..]);
} else {
try result.includes.append(include_arg);
}
}
}
{
var it = mem.tokenize(libdir_output, " \r\n");
while (it.next()) |libdir| {
if (mem.startsWith(u8, libdir, "-L")) {
try result.libdirs.append(libdir[2..]);
} else {
try result.libdirs.append(libdir);
}
}
}
return result;
}
fn configureStage2(b: *Builder, exe: anytype, ctx: Context, need_cpp_includes: bool) !void {
exe.addIncludeDir("src");
exe.addIncludeDir(ctx.cmake_binary_dir);
addCppLib(b, exe, ctx.cmake_binary_dir, "zigcpp");
assert(ctx.lld_include_dir.len != 0);
exe.addIncludeDir(ctx.lld_include_dir);
{
var it = mem.tokenize(ctx.lld_libraries, ";");
while (it.next()) |lib| {
exe.addObjectFile(lib);
}
}
{
var it = mem.tokenize(ctx.clang_libraries, ";");
while (it.next()) |lib| {
exe.addObjectFile(lib);
}
}
dependOnLib(b, exe, ctx.llvm);
// Boy, it sure would be nice to simply linkSystemLibrary("c++") and rely on zig's
// ability to provide libc++ right? Well thanks to C++ not having a stable ABI this
// will cause linker errors. It would work in the situation when `zig cc` is used to
// build LLVM, Clang, and LLD, however when depending on them as system libraries, system
// libc++ must be used.
const cross_compile = false; // TODO
if (cross_compile) {
// In this case we assume that zig cc was used to build the LLVM, Clang, LLD dependencies.
exe.linkSystemLibrary("c++");
} else {
if (exe.target.getOsTag() == .linux) {
// First we try to static link against gcc libstdc++. If that doesn't work,
// we fall back to -lc++ and cross our fingers.
addCxxKnownPath(b, ctx, exe, "libstdc++.a", "", need_cpp_includes) catch |err| switch (err) {
error.RequiredLibraryNotFound => {
exe.linkSystemLibrary("c++");
},
else => |e| return e,
};
exe.linkSystemLibrary("pthread");
} else if (exe.target.isFreeBSD()) {
try addCxxKnownPath(b, ctx, exe, "libc++.a", null, need_cpp_includes);
exe.linkSystemLibrary("pthread");
} else if (exe.target.isDarwin()) {
if (addCxxKnownPath(b, ctx, exe, "libgcc_eh.a", "", need_cpp_includes)) {
// Compiler is GCC.
try addCxxKnownPath(b, ctx, exe, "libstdc++.a", null, need_cpp_includes);
exe.linkSystemLibrary("pthread");
// TODO LLD cannot perform this link.
// Set ZIG_SYSTEM_LINKER_HACK env var to use system linker ld instead.
// See https://github.com/ziglang/zig/issues/1535
} else |err| switch (err) {
error.RequiredLibraryNotFound => {
// System compiler, not gcc.
exe.linkSystemLibrary("c++");
},
else => |e| return e,
}
}
if (ctx.dia_guids_lib.len != 0) {
exe.addObjectFile(ctx.dia_guids_lib);
}
}
}
fn addCxxKnownPath(
b: *Builder,
ctx: Context,
exe: anytype,
ctx: CMakeConfig,
exe: *std.build.LibExeObjStep,
objname: []const u8,
errtxt: ?[]const u8,
need_cpp_includes: bool,
@ -449,52 +378,64 @@ fn addCxxKnownPath(
}
}
const Context = struct {
fn addCMakeLibraryList(exe: *std.build.LibExeObjStep, list: []const u8) void {
var it = mem.tokenize(list, ";");
while (it.next()) |lib| {
if (mem.startsWith(u8, lib, "-l")) {
exe.linkSystemLibrary(lib["-l".len..]);
} else {
exe.addObjectFile(lib);
}
}
}
const CMakeConfig = struct {
cmake_binary_dir: []const u8,
cmake_prefix_path: []const u8,
cxx_compiler: []const u8,
llvm_config_exe: []const u8,
lld_include_dir: []const u8,
lld_libraries: []const u8,
clang_libraries: []const u8,
llvm_libraries: []const u8,
dia_guids_lib: []const u8,
llvm: LibraryDep,
};
const max_config_h_bytes = 1 * 1024 * 1024;
fn findAndReadConfigH(b: *Builder) ![]const u8 {
var check_dir = fs.path.dirname(b.zig_exe).?;
while (true) {
var dir = try fs.cwd().openDir(check_dir, .{});
defer dir.close();
fn findAndParseConfigH(b: *Builder, config_h_path_option: ?[]const u8) ?CMakeConfig {
const config_h_text: []const u8 = if (config_h_path_option) |config_h_path| blk: {
break :blk fs.cwd().readFileAlloc(b.allocator, config_h_path, max_config_h_bytes) catch unreachable;
} else blk: {
// TODO this should stop looking for config.h once it detects we hit the
// zig source root directory.
var check_dir = fs.path.dirname(b.zig_exe).?;
while (true) {
var dir = fs.cwd().openDir(check_dir, .{}) catch unreachable;
defer dir.close();
const config_h_text = dir.readFileAlloc(b.allocator, "config.h", max_config_h_bytes) catch |err| switch (err) {
error.FileNotFound => {
const new_check_dir = fs.path.dirname(check_dir);
if (new_check_dir == null or mem.eql(u8, new_check_dir.?, check_dir)) {
std.debug.warn("Unable to find config.h file relative to Zig executable.\n", .{});
std.debug.warn("`zig build` must be run using a Zig executable within the source tree.\n", .{});
std.process.exit(1);
}
check_dir = new_check_dir.?;
continue;
},
else => |e| return e,
};
return config_h_text;
} else unreachable; // TODO should not need `else unreachable`.
}
break :blk dir.readFileAlloc(b.allocator, "config.h", max_config_h_bytes) catch |err| switch (err) {
error.FileNotFound => {
const new_check_dir = fs.path.dirname(check_dir);
if (new_check_dir == null or mem.eql(u8, new_check_dir.?, check_dir)) {
return null;
}
check_dir = new_check_dir.?;
continue;
},
else => unreachable,
};
} else unreachable; // TODO should not need `else unreachable`.
};
fn parseConfigH(b: *Builder, config_h_text: []const u8) Context {
var ctx: Context = .{
var ctx: CMakeConfig = .{
.cmake_binary_dir = undefined,
.cmake_prefix_path = undefined,
.cxx_compiler = undefined,
.llvm_config_exe = undefined,
.lld_include_dir = undefined,
.lld_libraries = undefined,
.clang_libraries = undefined,
.llvm_libraries = undefined,
.dia_guids_lib = undefined,
.llvm = undefined,
};
const mappings = [_]struct { prefix: []const u8, field: []const u8 }{
@ -502,6 +443,10 @@ fn parseConfigH(b: *Builder, config_h_text: []const u8) Context {
.prefix = "#define ZIG_CMAKE_BINARY_DIR ",
.field = "cmake_binary_dir",
},
.{
.prefix = "#define ZIG_CMAKE_PREFIX_PATH ",
.field = "cmake_prefix_path",
},
.{
.prefix = "#define ZIG_CXX_COMPILER ",
.field = "cxx_compiler",
@ -519,8 +464,8 @@ fn parseConfigH(b: *Builder, config_h_text: []const u8) Context {
.field = "clang_libraries",
},
.{
.prefix = "#define ZIG_LLVM_CONFIG_EXE ",
.field = "llvm_config_exe",
.prefix = "#define ZIG_LLVM_LIBRARIES ",
.field = "llvm_libraries",
},
.{
.prefix = "#define ZIG_DIA_GUIDS_LIB ",
@ -550,3 +495,360 @@ fn toNativePathSep(b: *Builder, s: []const u8) []u8 {
};
return duplicated;
}
const softfloat_sources = [_][]const u8{
"deps/SoftFloat-3e/source/8086/f128M_isSignalingNaN.c",
"deps/SoftFloat-3e/source/8086/s_commonNaNToF128M.c",
"deps/SoftFloat-3e/source/8086/s_commonNaNToF16UI.c",
"deps/SoftFloat-3e/source/8086/s_commonNaNToF32UI.c",
"deps/SoftFloat-3e/source/8086/s_commonNaNToF64UI.c",
"deps/SoftFloat-3e/source/8086/s_f128MToCommonNaN.c",
"deps/SoftFloat-3e/source/8086/s_f16UIToCommonNaN.c",
"deps/SoftFloat-3e/source/8086/s_f32UIToCommonNaN.c",
"deps/SoftFloat-3e/source/8086/s_f64UIToCommonNaN.c",
"deps/SoftFloat-3e/source/8086/s_propagateNaNF128M.c",
"deps/SoftFloat-3e/source/8086/s_propagateNaNF16UI.c",
"deps/SoftFloat-3e/source/8086/softfloat_raiseFlags.c",
"deps/SoftFloat-3e/source/f128M_add.c",
"deps/SoftFloat-3e/source/f128M_div.c",
"deps/SoftFloat-3e/source/f128M_eq.c",
"deps/SoftFloat-3e/source/f128M_eq_signaling.c",
"deps/SoftFloat-3e/source/f128M_le.c",
"deps/SoftFloat-3e/source/f128M_le_quiet.c",
"deps/SoftFloat-3e/source/f128M_lt.c",
"deps/SoftFloat-3e/source/f128M_lt_quiet.c",
"deps/SoftFloat-3e/source/f128M_mul.c",
"deps/SoftFloat-3e/source/f128M_mulAdd.c",
"deps/SoftFloat-3e/source/f128M_rem.c",
"deps/SoftFloat-3e/source/f128M_roundToInt.c",
"deps/SoftFloat-3e/source/f128M_sqrt.c",
"deps/SoftFloat-3e/source/f128M_sub.c",
"deps/SoftFloat-3e/source/f128M_to_f16.c",
"deps/SoftFloat-3e/source/f128M_to_f32.c",
"deps/SoftFloat-3e/source/f128M_to_f64.c",
"deps/SoftFloat-3e/source/f128M_to_i32.c",
"deps/SoftFloat-3e/source/f128M_to_i32_r_minMag.c",
"deps/SoftFloat-3e/source/f128M_to_i64.c",
"deps/SoftFloat-3e/source/f128M_to_i64_r_minMag.c",
"deps/SoftFloat-3e/source/f128M_to_ui32.c",
"deps/SoftFloat-3e/source/f128M_to_ui32_r_minMag.c",
"deps/SoftFloat-3e/source/f128M_to_ui64.c",
"deps/SoftFloat-3e/source/f128M_to_ui64_r_minMag.c",
"deps/SoftFloat-3e/source/f16_add.c",
"deps/SoftFloat-3e/source/f16_div.c",
"deps/SoftFloat-3e/source/f16_eq.c",
"deps/SoftFloat-3e/source/f16_isSignalingNaN.c",
"deps/SoftFloat-3e/source/f16_lt.c",
"deps/SoftFloat-3e/source/f16_mul.c",
"deps/SoftFloat-3e/source/f16_mulAdd.c",
"deps/SoftFloat-3e/source/f16_rem.c",
"deps/SoftFloat-3e/source/f16_roundToInt.c",
"deps/SoftFloat-3e/source/f16_sqrt.c",
"deps/SoftFloat-3e/source/f16_sub.c",
"deps/SoftFloat-3e/source/f16_to_f128M.c",
"deps/SoftFloat-3e/source/f16_to_f64.c",
"deps/SoftFloat-3e/source/f32_to_f128M.c",
"deps/SoftFloat-3e/source/f64_to_f128M.c",
"deps/SoftFloat-3e/source/f64_to_f16.c",
"deps/SoftFloat-3e/source/i32_to_f128M.c",
"deps/SoftFloat-3e/source/s_add256M.c",
"deps/SoftFloat-3e/source/s_addCarryM.c",
"deps/SoftFloat-3e/source/s_addComplCarryM.c",
"deps/SoftFloat-3e/source/s_addF128M.c",
"deps/SoftFloat-3e/source/s_addM.c",
"deps/SoftFloat-3e/source/s_addMagsF16.c",
"deps/SoftFloat-3e/source/s_addMagsF32.c",
"deps/SoftFloat-3e/source/s_addMagsF64.c",
"deps/SoftFloat-3e/source/s_approxRecip32_1.c",
"deps/SoftFloat-3e/source/s_approxRecipSqrt32_1.c",
"deps/SoftFloat-3e/source/s_approxRecipSqrt_1Ks.c",
"deps/SoftFloat-3e/source/s_approxRecip_1Ks.c",
"deps/SoftFloat-3e/source/s_compare128M.c",
"deps/SoftFloat-3e/source/s_compare96M.c",
"deps/SoftFloat-3e/source/s_countLeadingZeros16.c",
"deps/SoftFloat-3e/source/s_countLeadingZeros32.c",
"deps/SoftFloat-3e/source/s_countLeadingZeros64.c",
"deps/SoftFloat-3e/source/s_countLeadingZeros8.c",
"deps/SoftFloat-3e/source/s_eq128.c",
"deps/SoftFloat-3e/source/s_invalidF128M.c",
"deps/SoftFloat-3e/source/s_isNaNF128M.c",
"deps/SoftFloat-3e/source/s_le128.c",
"deps/SoftFloat-3e/source/s_lt128.c",
"deps/SoftFloat-3e/source/s_mul128MTo256M.c",
"deps/SoftFloat-3e/source/s_mul64To128M.c",
"deps/SoftFloat-3e/source/s_mulAddF128M.c",
"deps/SoftFloat-3e/source/s_mulAddF16.c",
"deps/SoftFloat-3e/source/s_mulAddF32.c",
"deps/SoftFloat-3e/source/s_mulAddF64.c",
"deps/SoftFloat-3e/source/s_negXM.c",
"deps/SoftFloat-3e/source/s_normRoundPackMToF128M.c",
"deps/SoftFloat-3e/source/s_normRoundPackToF16.c",
"deps/SoftFloat-3e/source/s_normRoundPackToF32.c",
"deps/SoftFloat-3e/source/s_normRoundPackToF64.c",
"deps/SoftFloat-3e/source/s_normSubnormalF128SigM.c",
"deps/SoftFloat-3e/source/s_normSubnormalF16Sig.c",
"deps/SoftFloat-3e/source/s_normSubnormalF32Sig.c",
"deps/SoftFloat-3e/source/s_normSubnormalF64Sig.c",
"deps/SoftFloat-3e/source/s_remStepMBy32.c",
"deps/SoftFloat-3e/source/s_roundMToI64.c",
"deps/SoftFloat-3e/source/s_roundMToUI64.c",
"deps/SoftFloat-3e/source/s_roundPackMToF128M.c",
"deps/SoftFloat-3e/source/s_roundPackToF16.c",
"deps/SoftFloat-3e/source/s_roundPackToF32.c",
"deps/SoftFloat-3e/source/s_roundPackToF64.c",
"deps/SoftFloat-3e/source/s_roundToI32.c",
"deps/SoftFloat-3e/source/s_roundToI64.c",
"deps/SoftFloat-3e/source/s_roundToUI32.c",
"deps/SoftFloat-3e/source/s_roundToUI64.c",
"deps/SoftFloat-3e/source/s_shiftLeftM.c",
"deps/SoftFloat-3e/source/s_shiftNormSigF128M.c",
"deps/SoftFloat-3e/source/s_shiftRightJam256M.c",
"deps/SoftFloat-3e/source/s_shiftRightJam32.c",
"deps/SoftFloat-3e/source/s_shiftRightJam64.c",
"deps/SoftFloat-3e/source/s_shiftRightJamM.c",
"deps/SoftFloat-3e/source/s_shiftRightM.c",
"deps/SoftFloat-3e/source/s_shortShiftLeft64To96M.c",
"deps/SoftFloat-3e/source/s_shortShiftLeftM.c",
"deps/SoftFloat-3e/source/s_shortShiftRightExtendM.c",
"deps/SoftFloat-3e/source/s_shortShiftRightJam64.c",
"deps/SoftFloat-3e/source/s_shortShiftRightJamM.c",
"deps/SoftFloat-3e/source/s_shortShiftRightM.c",
"deps/SoftFloat-3e/source/s_sub1XM.c",
"deps/SoftFloat-3e/source/s_sub256M.c",
"deps/SoftFloat-3e/source/s_subM.c",
"deps/SoftFloat-3e/source/s_subMagsF16.c",
"deps/SoftFloat-3e/source/s_subMagsF32.c",
"deps/SoftFloat-3e/source/s_subMagsF64.c",
"deps/SoftFloat-3e/source/s_tryPropagateNaNF128M.c",
"deps/SoftFloat-3e/source/softfloat_state.c",
"deps/SoftFloat-3e/source/ui32_to_f128M.c",
"deps/SoftFloat-3e/source/ui64_to_f128M.c",
};
const stage1_sources = [_][]const u8{
"src/stage1/analyze.cpp",
"src/stage1/ast_render.cpp",
"src/stage1/bigfloat.cpp",
"src/stage1/bigint.cpp",
"src/stage1/buffer.cpp",
"src/stage1/codegen.cpp",
"src/stage1/dump_analysis.cpp",
"src/stage1/errmsg.cpp",
"src/stage1/error.cpp",
"src/stage1/heap.cpp",
"src/stage1/ir.cpp",
"src/stage1/ir_print.cpp",
"src/stage1/mem.cpp",
"src/stage1/os.cpp",
"src/stage1/parser.cpp",
"src/stage1/range_set.cpp",
"src/stage1/stage1.cpp",
"src/stage1/target.cpp",
"src/stage1/tokenizer.cpp",
"src/stage1/util.cpp",
"src/stage1/softfloat_ext.cpp",
};
const optimized_c_sources = [_][]const u8{
"src/stage1/parse_f128.c",
};
const zig_cpp_sources = [_][]const u8{
// These are planned to stay even when we are self-hosted.
"src/zig_llvm.cpp",
"src/zig_clang.cpp",
"src/zig_clang_driver.cpp",
"src/zig_clang_cc1_main.cpp",
"src/zig_clang_cc1as_main.cpp",
// https://github.com/ziglang/zig/issues/6363
"src/windows_sdk.cpp",
};
const clang_libs = [_][]const u8{
"clangFrontendTool",
"clangCodeGen",
"clangFrontend",
"clangDriver",
"clangSerialization",
"clangSema",
"clangStaticAnalyzerFrontend",
"clangStaticAnalyzerCheckers",
"clangStaticAnalyzerCore",
"clangAnalysis",
"clangASTMatchers",
"clangAST",
"clangParse",
"clangSema",
"clangBasic",
"clangEdit",
"clangLex",
"clangARCMigrate",
"clangRewriteFrontend",
"clangRewrite",
"clangCrossTU",
"clangIndex",
"clangToolingCore",
};
const lld_libs = [_][]const u8{
"lldDriver",
"lldMinGW",
"lldELF",
"lldCOFF",
"lldMachO",
"lldWasm",
"lldReaderWriter",
"lldCore",
"lldYAML",
"lldCommon",
};
// This list can be re-generated with `llvm-config --libfiles` and then
// reformatting using your favorite text editor. Note we do not execute
// `llvm-config` here because we are cross compiling.
const llvm_libs = [_][]const u8{
"LLVMXRay",
"LLVMWindowsManifest",
"LLVMSymbolize",
"LLVMDebugInfoPDB",
"LLVMOrcJIT",
"LLVMOrcError",
"LLVMJITLink",
"LLVMObjectYAML",
"LLVMMCA",
"LLVMLTO",
"LLVMPasses",
"LLVMCoroutines",
"LLVMObjCARCOpts",
"LLVMExtensions",
"LLVMLineEditor",
"LLVMLibDriver",
"LLVMInterpreter",
"LLVMFuzzMutate",
"LLVMMCJIT",
"LLVMExecutionEngine",
"LLVMRuntimeDyld",
"LLVMDWARFLinker",
"LLVMDlltoolDriver",
"LLVMOption",
"LLVMDebugInfoGSYM",
"LLVMCoverage",
"LLVMXCoreDisassembler",
"LLVMXCoreCodeGen",
"LLVMXCoreDesc",
"LLVMXCoreInfo",
"LLVMX86Disassembler",
"LLVMX86CodeGen",
"LLVMX86AsmParser",
"LLVMX86Desc",
"LLVMX86Info",
"LLVMWebAssemblyDisassembler",
"LLVMWebAssemblyCodeGen",
"LLVMWebAssemblyDesc",
"LLVMWebAssemblyAsmParser",
"LLVMWebAssemblyInfo",
"LLVMSystemZDisassembler",
"LLVMSystemZCodeGen",
"LLVMSystemZAsmParser",
"LLVMSystemZDesc",
"LLVMSystemZInfo",
"LLVMSparcDisassembler",
"LLVMSparcCodeGen",
"LLVMSparcAsmParser",
"LLVMSparcDesc",
"LLVMSparcInfo",
"LLVMRISCVDisassembler",
"LLVMRISCVCodeGen",
"LLVMRISCVAsmParser",
"LLVMRISCVDesc",
"LLVMRISCVUtils",
"LLVMRISCVInfo",
"LLVMPowerPCDisassembler",
"LLVMPowerPCCodeGen",
"LLVMPowerPCAsmParser",
"LLVMPowerPCDesc",
"LLVMPowerPCInfo",
"LLVMNVPTXCodeGen",
"LLVMNVPTXDesc",
"LLVMNVPTXInfo",
"LLVMMSP430Disassembler",
"LLVMMSP430CodeGen",
"LLVMMSP430AsmParser",
"LLVMMSP430Desc",
"LLVMMSP430Info",
"LLVMMipsDisassembler",
"LLVMMipsCodeGen",
"LLVMMipsAsmParser",
"LLVMMipsDesc",
"LLVMMipsInfo",
"LLVMLanaiDisassembler",
"LLVMLanaiCodeGen",
"LLVMLanaiAsmParser",
"LLVMLanaiDesc",
"LLVMLanaiInfo",
"LLVMHexagonDisassembler",
"LLVMHexagonCodeGen",
"LLVMHexagonAsmParser",
"LLVMHexagonDesc",
"LLVMHexagonInfo",
"LLVMBPFDisassembler",
"LLVMBPFCodeGen",
"LLVMBPFAsmParser",
"LLVMBPFDesc",
"LLVMBPFInfo",
"LLVMAVRDisassembler",
"LLVMAVRCodeGen",
"LLVMAVRAsmParser",
"LLVMAVRDesc",
"LLVMAVRInfo",
"LLVMARMDisassembler",
"LLVMARMCodeGen",
"LLVMARMAsmParser",
"LLVMARMDesc",
"LLVMARMUtils",
"LLVMARMInfo",
"LLVMAMDGPUDisassembler",
"LLVMAMDGPUCodeGen",
"LLVMMIRParser",
"LLVMipo",
"LLVMInstrumentation",
"LLVMVectorize",
"LLVMLinker",
"LLVMIRReader",
"LLVMAsmParser",
"LLVMFrontendOpenMP",
"LLVMAMDGPUAsmParser",
"LLVMAMDGPUDesc",
"LLVMAMDGPUUtils",
"LLVMAMDGPUInfo",
"LLVMAArch64Disassembler",
"LLVMMCDisassembler",
"LLVMAArch64CodeGen",
"LLVMCFGuard",
"LLVMGlobalISel",
"LLVMSelectionDAG",
"LLVMAsmPrinter",
"LLVMDebugInfoDWARF",
"LLVMCodeGen",
"LLVMTarget",
"LLVMScalarOpts",
"LLVMInstCombine",
"LLVMAggressiveInstCombine",
"LLVMTransformUtils",
"LLVMBitWriter",
"LLVMAnalysis",
"LLVMProfileData",
"LLVMObject",
"LLVMTextAPI",
"LLVMBitReader",
"LLVMCore",
"LLVMRemarks",
"LLVMBitstreamReader",
"LLVMAArch64AsmParser",
"LLVMMCParser",
"LLVMAArch64Desc",
"LLVMMC",
"LLVMDebugInfoCodeView",
"LLVMDebugInfoMSF",
"LLVMBinaryFormat",
"LLVMAArch64Utils",
"LLVMAArch64Info",
"LLVMSupport",
"LLVMDemangle",
};

View File

@ -1150,6 +1150,11 @@ const CSourceFile = struct {
args: []const []const u8,
};
const CSourceFiles = struct {
files: []const []const u8,
flags: []const []const u8,
};
fn isLibCLibrary(name: []const u8) bool {
const libc_libraries = [_][]const u8{ "c", "m", "dl", "rt", "pthread" };
for (libc_libraries) |libc_lib_name| {
@ -1297,6 +1302,7 @@ pub const LibExeObjStep = struct {
SystemLib: []const u8,
AssemblyFile: FileSource,
CSourceFile: *CSourceFile,
CSourceFiles: *CSourceFiles,
};
const IncludeDir = union(enum) {
@ -1670,9 +1676,25 @@ pub const LibExeObjStep = struct {
self.filter = text;
}
pub fn addCSourceFile(self: *LibExeObjStep, file: []const u8, args: []const []const u8) void {
/// Handy when you have many C/C++ source files and want them all to have the same flags.
pub fn addCSourceFiles(self: *LibExeObjStep, files: []const []const u8, flags: []const []const u8) void {
const c_source_files = self.builder.allocator.create(CSourceFiles) catch unreachable;
const flags_copy = self.builder.allocator.alloc([]u8, flags.len) catch unreachable;
for (flags) |flag, i| {
flags_copy[i] = self.builder.dupe(flag);
}
c_source_files.* = .{
.files = files,
.flags = flags_copy,
};
self.link_objects.append(LinkObject{ .CSourceFiles = c_source_files }) catch unreachable;
}
pub fn addCSourceFile(self: *LibExeObjStep, file: []const u8, flags: []const []const u8) void {
self.addCSourceFileSource(.{
.args = args,
.args = flags,
.source = .{ .path = file },
});
}
@ -1795,6 +1817,10 @@ pub const LibExeObjStep = struct {
out.writeAll("};\n") catch unreachable;
return;
},
[:0]const u8 => {
out.print("pub const {z}: [:0]const u8 = \"{Z}\";\n", .{ name, value }) catch unreachable;
return;
},
[]const u8 => {
out.print("pub const {z}: []const u8 = \"{Z}\";\n", .{ name, value }) catch unreachable;
return;
@ -1808,6 +1834,22 @@ pub const LibExeObjStep = struct {
}
return;
},
std.builtin.Version => {
out.print(
\\pub const {z}: @import("builtin").Version = .{{
\\ .major = {d},
\\ .minor = {d},
\\ .patch = {d},
\\}};
\\
, .{
name,
value.major,
value.minor,
value.patch,
}) catch unreachable;
},
std.SemanticVersion => {
out.print(
\\pub const {z}: @import("std").SemanticVersion = .{{
@ -2015,8 +2057,7 @@ pub const LibExeObjStep = struct {
},
},
.SystemLib => |name| {
try zig_args.append("--library");
try zig_args.append(name);
try zig_args.append(builder.fmt("-l{s}", .{name}));
},
.AssemblyFile => |asm_file| {
if (prev_has_extra_flags) {
@ -2026,6 +2067,7 @@ pub const LibExeObjStep = struct {
}
try zig_args.append(asm_file.getPath(builder));
},
.CSourceFile => |c_source_file| {
if (c_source_file.args.len == 0) {
if (prev_has_extra_flags) {
@ -2042,6 +2084,25 @@ pub const LibExeObjStep = struct {
}
try zig_args.append(c_source_file.source.getPath(builder));
},
.CSourceFiles => |c_source_files| {
if (c_source_files.flags.len == 0) {
if (prev_has_extra_flags) {
try zig_args.append("-cflags");
try zig_args.append("--");
prev_has_extra_flags = false;
}
} else {
try zig_args.append("-cflags");
for (c_source_files.flags) |flag| {
try zig_args.append(flag);
}
try zig_args.append("--");
}
for (c_source_files.files) |file| {
try zig_args.append(builder.pathFromRoot(file));
}
},
}
}
@ -2304,6 +2365,17 @@ pub const LibExeObjStep = struct {
}
}
for (builder.search_prefixes.items) |search_prefix| {
try zig_args.append("-L");
try zig_args.append(try fs.path.join(builder.allocator, &[_][]const u8{
search_prefix, "lib",
}));
try zig_args.append("-isystem");
try zig_args.append(try fs.path.join(builder.allocator, &[_][]const u8{
search_prefix, "include",
}));
}
if (self.valgrind_support) |valgrind_support| {
if (valgrind_support) {
try zig_args.append("-fvalgrind");

View File

@ -1,5 +1,11 @@
pub const have_llvm = true;
pub const version: []const u8 = "@ZIG_VERSION@";
pub const version: [:0]const u8 = "@ZIG_VERSION@";
pub const semver: @import("std").SemanticVersion = .{
.major = @ZIG_VERSION_MAJOR@,
.minor = @ZIG_VERSION_MINOR@,
.patch = @ZIG_VERSION_PATCH@,
.build = "@ZIG_GIT_REV@",
};
pub const log_scopes: []const []const u8 = &[_][]const u8{};
pub const zir_dumps: []const []const u8 = &[_][]const u8{};
pub const enable_tracy = false;

0
src/empty.zig Normal file
View File

View File

@ -251,6 +251,20 @@ const Error = extern enum {
Locked,
};
// ABI warning
export fn stage2_version_string() [*:0]const u8 {
return build_options.version;
}
// ABI warning
export fn stage2_version() Stage2SemVer {
return .{
.major = build_options.semver.major,
.minor = build_options.semver.minor,
.patch = build_options.semver.patch,
};
}
// ABI warning
export fn stage2_attach_segfault_handler() void {
if (std.debug.runtime_safety and std.debug.have_segfault_handling_support) {

View File

@ -8,7 +8,6 @@
#include "analyze.hpp"
#include "ast_render.hpp"
#include "codegen.hpp"
#include "config.h"
#include "error.hpp"
#include "ir.hpp"
#include "ir_print.hpp"

View File

@ -8,7 +8,6 @@
#include "analyze.hpp"
#include "ast_render.hpp"
#include "codegen.hpp"
#include "config.h"
#include "errmsg.hpp"
#include "error.hpp"
#include "hash_map.hpp"
@ -9051,7 +9050,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
buf_append_str(contents, "/// Deprecated: use `std.Target.current.cpu.arch.endian()`\n");
buf_append_str(contents, "pub const endian = Target.current.cpu.arch.endian();\n");
buf_appendf(contents, "pub const output_mode = OutputMode.Obj;\n");
buf_appendf(contents, "pub const link_mode = LinkMode.%s;\n", ZIG_LINK_MODE);
buf_appendf(contents, "pub const link_mode = LinkMode.%s;\n", ZIG_QUOTE(ZIG_LINK_MODE));
buf_appendf(contents, "pub const is_test = false;\n");
buf_appendf(contents, "pub const single_threaded = %s;\n", bool_to_str(g->is_single_threaded));
buf_appendf(contents, "pub const abi = Abi.%s;\n", cur_abi);
@ -9251,9 +9250,9 @@ static void init(CodeGen *g) {
g->builder = LLVMCreateBuilder();
g->dbuilder = ZigLLVMCreateDIBuilder(g->module, true);
// Don't use ZIG_VERSION_STRING here, llvm misparses it when it includes
// the git revision.
Buf *producer = buf_sprintf("zig %d.%d.%d", ZIG_VERSION_MAJOR, ZIG_VERSION_MINOR, ZIG_VERSION_PATCH);
// Don't use the version string here, llvm misparses it when it includes the git revision.
Stage2SemVer semver = stage2_version();
Buf *producer = buf_sprintf("zig %d.%d.%d", semver.major, semver.minor, semver.patch);
const char *flags = "";
unsigned runtime_version = 0;
@ -9551,9 +9550,9 @@ void codegen_build_object(CodeGen *g) {
}
do_code_gen(g);
codegen_add_time_event(g, "LLVM Emit Output");
codegen_add_time_event(g, "LLVM Emit Object");
{
const char *progress_name = "LLVM Emit Output";
const char *progress_name = "LLVM Emit Object";
codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node,
progress_name, strlen(progress_name), 0));
}

View File

@ -8,19 +8,20 @@
#ifndef ZIG_CONFIG_H
#define ZIG_CONFIG_H
// Used by zig0.cpp
#define ZIG_VERSION_MAJOR @ZIG_VERSION_MAJOR@
#define ZIG_VERSION_MINOR @ZIG_VERSION_MINOR@
#define ZIG_VERSION_PATCH @ZIG_VERSION_PATCH@
#define ZIG_VERSION_STRING "@ZIG_VERSION@"
// Used for communicating build information to self hosted build.
// Used by build.zig for communicating build information to self hosted build.
#define ZIG_CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@"
#define ZIG_CMAKE_PREFIX_PATH "@CMAKE_PREFIX_PATH@"
#define ZIG_CXX_COMPILER "@CMAKE_CXX_COMPILER@"
#define ZIG_LLD_INCLUDE_PATH "@LLD_INCLUDE_DIRS@"
#define ZIG_LLD_LIBRARIES "@LLD_LIBRARIES@"
#define ZIG_CLANG_LIBRARIES "@CLANG_LIBRARIES@"
#define ZIG_LLVM_CONFIG_EXE "@LLVM_CONFIG_EXE@"
#define ZIG_LLVM_LIBRARIES "@LLVM_LIBRARIES@"
#define ZIG_DIA_GUIDS_LIB "@ZIG_DIA_GUIDS_LIB_ESCAPED@"
#define ZIG_LINK_MODE "@ZIG_LINK_MODE@"
#endif

View File

@ -7,7 +7,6 @@
#include "dump_analysis.hpp"
#include "analyze.hpp"
#include "config.h"
#include "ir.hpp"
#include "codegen.hpp"
#include "os.hpp"
@ -1237,7 +1236,7 @@ void zig_print_analysis_dump(CodeGen *g, FILE *f, const char *one_indent, const
jw_begin_object(jw);
{
jw_object_field(jw, "zigVersion");
jw_string(jw, ZIG_VERSION_STRING);
jw_string(jw, stage2_version_string());
jw_object_field(jw, "builds");
jw_begin_array(jw);

View File

@ -8,7 +8,6 @@
#include <new>
#include <string.h>
#include "config.h"
#include "heap.hpp"
namespace heap {

View File

@ -8,7 +8,6 @@
#ifndef ZIG_HEAP_HPP
#define ZIG_HEAP_HPP
#include "config.h"
#include "util_base.hpp"
#include "mem.hpp"

View File

@ -5,7 +5,6 @@
* See http://opensource.org/licenses/MIT
*/
#include "config.h"
#include "mem.hpp"
#include "heap.hpp"

View File

@ -12,7 +12,6 @@
#include <stdio.h>
#include <stdlib.h>
#include "config.h"
#include "util_base.hpp"
#include "mem_type_info.hpp"

View File

@ -8,8 +8,6 @@
#ifndef ZIG_MEM_TYPE_INFO_HPP
#define ZIG_MEM_TYPE_INFO_HPP
#include "config.h"
namespace mem {
struct TypeInfo {

View File

@ -156,6 +156,12 @@ struct Stage2SemVer {
uint32_t patch;
};
// ABI warning
ZIG_EXTERN_C const char *stage2_version_string(void);
// ABI warning
ZIG_EXTERN_C Stage2SemVer stage2_version(void);
// ABI warning
ZIG_EXTERN_C enum Error stage2_target_parse(struct ZigTarget *target, const char *zig_triple, const char *mcpu,
const char *dynamic_linker);

View File

@ -17,7 +17,9 @@
#include <intrin.h>
#endif
#include "config.h"
#define ZIG_Q(x) #x
#define ZIG_QUOTE(x) ZIG_Q(x)
#include "util_base.hpp"
#include "heap.hpp"
#include "mem.hpp"

View File

@ -18,6 +18,11 @@
#include "buffer.hpp"
#include "os.hpp"
// This is the only file allowed to include config.h because config.h is
// only produced when building with cmake. When using the zig build system,
// zig0.cpp is never touched.
#include "config.h"
#include <stdio.h>
#include <string.h>
@ -537,3 +542,11 @@ const char *stage2_add_link_lib(struct ZigStage1 *stage1,
{
return nullptr;
}
const char *stage2_version_string(void) {
return ZIG_VERSION_STRING;
}
struct Stage2SemVer stage2_version(void) {
return {ZIG_VERSION_MAJOR, ZIG_VERSION_MINOR, ZIG_VERSION_PATCH};
}

View File

@ -8,7 +8,7 @@
#ifndef ZIG_ZIG_CLANG_H
#define ZIG_ZIG_CLANG_H
#include "stage2.h"
#include "stage1/stage2.h"
#include <inttypes.h>
#include <stdbool.h>