authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-04 21:33:29-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-07 17:27:09-07:00
log5a65caa2a3686e12e4dfcfd599ed02f8a09c6017
tree7c5a644b61bdecdb1704e77724fbff74043ae4fe
parent5f7b97e84c7e2bc7682510e97996ad30147026d0

ability to build stage1 using only a zig tarball

The main idea here is that there are now 2 ways to get a stage1 zig binary: * The cmake path. Requirements: cmake, system C++ compiler, system LLVM, LLD, Clang libraries, compiled by the system C++ compiler. * The zig path. Requirements: a zig installation, system LLVM, LLD, Clang libraries, compiled by the zig installation. Note that the former can be used to now take the latter path. Removed config.h.in and config.zig.in. The build.zig script no longer is coupled to the cmake script. cmake no longer tries to determine the zig version. A build with cmake will yield a stage1 zig binary that reports 0.0.0+zig0. This is going to get reverted. `zig build` now accepts `-Dstage1` which will build the stage1 compiler, and put the stage2 backend behind a feature flag. build.zig is simplified to only support the use case of enabling LLVM support when the LLVM, LLD, and Clang libraries were built by zig. This part is probably sadly going to have to get reverted to make package maintainers happy. Zig build system addBuildOption supports a couple new types. The biggest reason to make this change is that the zig path is an attractive option for doing compiler development work on Windows. It allows people to work on the compiler without having MSVC installed, using only a .zip file that contains Zig + LLVM/LLD/Clang libraries.

19 files changed, 539 insertions(+), 429 deletions(-)

CMakeLists.txt+8-45
......@@ -24,34 +24,6 @@ set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX
2424project(zig C CXX)
2525set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
2626
27set(ZIG_VERSION_MAJOR 0)
28set(ZIG_VERSION_MINOR 7)
29set(ZIG_VERSION_PATCH 0)
30set(ZIG_VERSION "" CACHE STRING "Override Zig version string. Default is to find out with git.")
31
32if("${ZIG_VERSION}" STREQUAL "")
33 set(ZIG_VERSION "${ZIG_VERSION_MAJOR}.${ZIG_VERSION_MINOR}.${ZIG_VERSION_PATCH}")
34 find_program(GIT_EXE NAMES git)
35 if(GIT_EXE)
36 execute_process(
37 COMMAND ${GIT_EXE} -C ${CMAKE_SOURCE_DIR} name-rev HEAD --tags --name-only --no-undefined --always
38 RESULT_VARIABLE EXIT_STATUS
39 OUTPUT_VARIABLE ZIG_GIT_REV
40 OUTPUT_STRIP_TRAILING_WHITESPACE
41 ERROR_QUIET)
42 if(EXIT_STATUS EQUAL "0")
43 if(ZIG_GIT_REV MATCHES "\\^0$")
44 if(NOT("${ZIG_GIT_REV}" STREQUAL "${ZIG_VERSION}^0"))
45 message("WARNING: Tag does not match configured Zig version")
46 endif()
47 else()
48 set(ZIG_VERSION "${ZIG_VERSION}+${ZIG_GIT_REV}")
49 endif()
50 endif()
51 endif()
52endif()
53message("Configuring zig version ${ZIG_VERSION}")
54
5527set(ZIG_STATIC off CACHE BOOL "Attempt to build a static zig executable (not compatible with glibc)")
5628set(ZIG_STATIC_LLVM off CACHE BOOL "Prefer linking against static LLVM libraries")
5729set(ZIG_PREFER_CLANG_CPP_DYLIB off CACHE BOOL "Try to link against -lclang-cpp")
......@@ -63,9 +35,6 @@ endif()
6335
6436if(ZIG_STATIC)
6537 set(ZIG_STATIC_LLVM "on")
66 set(ZIG_LINK_MODE "Static")
67else()
68 set(ZIG_LINK_MODE "Dynamic")
6938endif()
7039
7140string(REGEX REPLACE "\\\\" "\\\\\\\\" ZIG_LIBC_LIB_DIR_ESCAPED "${ZIG_LIBC_LIB_DIR}")
......@@ -264,8 +233,6 @@ set(LIBC_FILES_DEST "${ZIG_LIB_DIR}/libc")
264233set(LIBUNWIND_FILES_DEST "${ZIG_LIB_DIR}/libunwind")
265234set(LIBCXX_FILES_DEST "${ZIG_LIB_DIR}/libcxx")
266235set(ZIG_STD_DEST "${ZIG_LIB_DIR}/std")
267set(ZIG_CONFIG_H_OUT "${CMAKE_BINARY_DIR}/config.h")
268set(ZIG_CONFIG_ZIG_OUT "${CMAKE_BINARY_DIR}/config.zig")
269236
270237# This is our shim which will be replaced by stage1.zig.
271238set(ZIG0_SOURCES
......@@ -313,7 +280,6 @@ set(ZIG_CPP_SOURCES
313280# then manually running the build-obj command (see BUILD_ZIG1_ARGS), and then looking
314281# in the zig-cache directory for the compiler-generated list of zig file dependencies.
315282set(ZIG_STAGE2_SOURCES
316 "${ZIG_CONFIG_ZIG_OUT}"
317283 "${CMAKE_SOURCE_DIR}/lib/std/array_hash_map.zig"
318284 "${CMAKE_SOURCE_DIR}/lib/std/array_list.zig"
319285 "${CMAKE_SOURCE_DIR}/lib/std/ascii.zig"
......@@ -553,6 +519,7 @@ set(ZIG_STAGE2_SOURCES
553519 "${CMAKE_SOURCE_DIR}/src/print_env.zig"
554520 "${CMAKE_SOURCE_DIR}/src/print_targets.zig"
555521 "${CMAKE_SOURCE_DIR}/src/stage1.zig"
522 "${CMAKE_SOURCE_DIR}/src/stage1_config.zig"
556523 "${CMAKE_SOURCE_DIR}/src/target.zig"
557524 "${CMAKE_SOURCE_DIR}/src/tracy.zig"
558525 "${CMAKE_SOURCE_DIR}/src/translate_c.zig"
......@@ -571,15 +538,6 @@ if(MSVC)
571538 endif()
572539endif()
573540
574configure_file (
575 "${CMAKE_SOURCE_DIR}/src/stage1/config.h.in"
576 "${ZIG_CONFIG_H_OUT}"
577)
578configure_file (
579 "${CMAKE_SOURCE_DIR}/src/config.zig.in"
580 "${ZIG_CONFIG_ZIG_OUT}"
581)
582
583541include_directories(
584542 ${CMAKE_SOURCE_DIR}
585543 ${CMAKE_BINARY_DIR}
......@@ -594,6 +552,12 @@ else(MSVC)
594552 set(EXE_CFLAGS "-std=c++14")
595553endif(MSVC)
596554
555if(ZIG_STATIC)
556 set(EXE_CFLAGS "${EXE_CFLAGS} -DZIG_LINK_MODE=Static")
557else()
558 set(EXE_CFLAGS "${EXE_CFLAGS} -DZIG_LINK_MODE=Dynamic")
559endif()
560
597561if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
598562 if(MSVC)
599563 set(EXE_CFLAGS "${EXE_CFLAGS} /w")
......@@ -720,7 +684,7 @@ set(BUILD_ZIG1_ARGS
720684 "-femit-bin=${ZIG1_OBJECT}"
721685 "${ZIG1_RELEASE_ARG}"
722686 -lc
723 --pkg-begin build_options "${ZIG_CONFIG_ZIG_OUT}"
687 --pkg-begin build_options "${CMAKE_SOURCE_DIR}/src/stage1_config.zig"
724688 --pkg-end
725689 --pkg-begin compiler_rt "${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt.zig"
726690 --pkg-end
......@@ -769,7 +733,6 @@ set(ZIG_INSTALL_ARGS "build"
769733 --override-lib-dir "${CMAKE_SOURCE_DIR}/lib"
770734 "-Dlib-files-only"
771735 --prefix "${CMAKE_INSTALL_PREFIX}"
772 "-Dconfig_h=${ZIG_CONFIG_H_OUT}"
773736 install
774737)
775738
build.zig+403-329
......@@ -53,7 +53,8 @@ pub fn build(b: *Builder) !void {
5353 const skip_compile_errors = b.option(bool, "skip-compile-errors", "Main test suite skips compile error tests") orelse false;
5454
5555 const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false;
56 const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse false;
56 const is_stage1 = b.option(bool, "stage1", "Build the stage1 compiler, put stage2 behind a feature flag") orelse false;
57 const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse is_stage1;
5758 const config_h_path_option = b.option([]const u8, "config_h", "Path to the generated config.h");
5859
5960 b.installDirectory(InstallDirectoryOptions{
......@@ -76,6 +77,8 @@ pub fn build(b: *Builder) !void {
7677 const tracy = b.option([]const u8, "tracy", "Enable Tracy integration. Supply path to Tracy source");
7778 const link_libc = b.option(bool, "force-link-libc", "Force self-hosted compiler to link libc") orelse enable_llvm;
7879
80 const main_file = if (is_stage1) "src/stage1.zig" else "src/main.zig";
81
7982 var exe = b.addExecutable("zig", "src/main.zig");
8083 exe.install();
8184 exe.setBuildMode(mode);
......@@ -86,15 +89,51 @@ pub fn build(b: *Builder) !void {
8689 exe.addBuildOption(bool, "skip_non_native", skip_non_native);
8790 exe.addBuildOption(bool, "have_llvm", enable_llvm);
8891 if (enable_llvm) {
89 const config_h_text = if (config_h_path_option) |config_h_path|
90 try std.fs.cwd().readFileAlloc(b.allocator, toNativePathSep(b, config_h_path), max_config_h_bytes)
91 else
92 try findAndReadConfigH(b);
92 if (is_stage1) {
93 exe.addIncludeDir("src");
94 exe.addIncludeDir("deps/SoftFloat-3e/source/include");
95
96 const softfloat = b.addStaticLibrary("softfloat", null);
97 softfloat.setBuildMode(.ReleaseFast);
98 softfloat.setTarget(target);
99 softfloat.addIncludeDir("deps/SoftFloat-3e-prebuilt");
100 softfloat.addIncludeDir("deps/SoftFloat-3e/source/8086");
101 softfloat.addIncludeDir("deps/SoftFloat-3e/source/include");
102 softfloat.addCSourceFiles(&softfloat_sources, &[_][]const u8{ "-std=c99", "-O3" });
103 exe.linkLibrary(softfloat);
104
105 const exe_cflags = &[_][]const u8{
106 "-std=c++14",
107 "-D__STDC_CONSTANT_MACROS",
108 "-D__STDC_FORMAT_MACROS",
109 "-D__STDC_LIMIT_MACROS",
110 "-D_GNU_SOURCE",
111 "-fvisibility-inlines-hidden",
112 "-fno-exceptions",
113 "-fno-rtti",
114 "-Werror=type-limits",
115 "-Wno-missing-braces",
116 "-Wno-comment",
117 };
118 exe.addCSourceFiles(&stage1_sources, exe_cflags);
119 exe.addCSourceFiles(&optimized_c_sources, &[_][]const u8{ "-std=c99", "-O3" });
120 exe.addCSourceFiles(&zig_cpp_sources, exe_cflags);
121 }
93122
94 var ctx = parseConfigH(b, config_h_text);
95 ctx.llvm = try findLLVM(b, ctx.llvm_config_exe);
123 for (clang_libs) |lib_name| {
124 exe.linkSystemLibrary(lib_name);
125 }
126
127 for (lld_libs) |lib_name| {
128 exe.linkSystemLibrary(lib_name);
129 }
96130
97 try configureStage2(b, exe, ctx, tracy != null);
131 for (llvm_libs) |lib_name| {
132 exe.linkSystemLibrary(lib_name);
133 }
134
135 // This means we rely on clang-or-zig-built LLVM, Clang, LLD libraries.
136 exe.linkSystemLibrary("c++");
98137 }
99138 if (link_libc) {
100139 exe.linkLibC();
......@@ -141,7 +180,10 @@ pub fn build(b: *Builder) !void {
141180 break :v b.fmt("{}+{}{}", .{ version_string, git_sha_trimmed, dirty_suffix });
142181 }
143182 };
144 exe.addBuildOption([]const u8, "version", version);
183 exe.addBuildOption([:0]const u8, "version", try b.allocator.dupeZ(u8, version));
184
185 const semver = try std.SemanticVersion.parse(version);
186 exe.addBuildOption(std.SemanticVersion, "semver", semver);
145187
146188 exe.addBuildOption([]const []const u8, "log_scopes", log_scopes);
147189 exe.addBuildOption([]const []const u8, "zir_dumps", zir_dumps);
......@@ -226,327 +268,359 @@ pub fn build(b: *Builder) !void {
226268 test_step.dependOn(docs_step);
227269}
228270
229fn dependOnLib(b: *Builder, lib_exe_obj: anytype, dep: LibraryDep) void {
230 for (dep.libdirs.items) |lib_dir| {
231 lib_exe_obj.addLibPath(lib_dir);
232 }
233 const lib_dir = fs.path.join(
234 b.allocator,
235 &[_][]const u8{ dep.prefix, "lib" },
236 ) catch unreachable;
237 for (dep.system_libs.items) |lib| {
238 const static_bare_name = if (mem.eql(u8, lib, "curses"))
239 @as([]const u8, "libncurses.a")
240 else
241 b.fmt("lib{}.a", .{lib});
242 const static_lib_name = fs.path.join(
243 b.allocator,
244 &[_][]const u8{ lib_dir, static_bare_name },
245 ) catch unreachable;
246 const have_static = fileExists(static_lib_name) catch unreachable;
247 if (have_static) {
248 lib_exe_obj.addObjectFile(static_lib_name);
249 } else {
250 lib_exe_obj.linkSystemLibrary(lib);
251 }
252 }
253 for (dep.libs.items) |lib| {
254 lib_exe_obj.addObjectFile(lib);
255 }
256 for (dep.includes.items) |include_path| {
257 lib_exe_obj.addIncludeDir(include_path);
258 }
259}
260
261fn fileExists(filename: []const u8) !bool {
262 fs.cwd().access(filename, .{}) catch |err| switch (err) {
263 error.FileNotFound => return false,
264 else => return err,
265 };
266 return true;
267}
268
269fn addCppLib(b: *Builder, lib_exe_obj: anytype, cmake_binary_dir: []const u8, lib_name: []const u8) void {
270 lib_exe_obj.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{
271 cmake_binary_dir,
272 "zigcpp",
273 b.fmt("{}{}{}", .{ lib_exe_obj.target.libPrefix(), lib_name, lib_exe_obj.target.staticLibSuffix() }),
274 }) catch unreachable);
275}
276
277const LibraryDep = struct {
278 prefix: []const u8,
279 libdirs: ArrayList([]const u8),
280 libs: ArrayList([]const u8),
281 system_libs: ArrayList([]const u8),
282 includes: ArrayList([]const u8),
271const softfloat_sources = [_][]const u8{
272 "deps/SoftFloat-3e/source/8086/f128M_isSignalingNaN.c",
273 "deps/SoftFloat-3e/source/8086/s_commonNaNToF128M.c",
274 "deps/SoftFloat-3e/source/8086/s_commonNaNToF16UI.c",
275 "deps/SoftFloat-3e/source/8086/s_commonNaNToF32UI.c",
276 "deps/SoftFloat-3e/source/8086/s_commonNaNToF64UI.c",
277 "deps/SoftFloat-3e/source/8086/s_f128MToCommonNaN.c",
278 "deps/SoftFloat-3e/source/8086/s_f16UIToCommonNaN.c",
279 "deps/SoftFloat-3e/source/8086/s_f32UIToCommonNaN.c",
280 "deps/SoftFloat-3e/source/8086/s_f64UIToCommonNaN.c",
281 "deps/SoftFloat-3e/source/8086/s_propagateNaNF128M.c",
282 "deps/SoftFloat-3e/source/8086/s_propagateNaNF16UI.c",
283 "deps/SoftFloat-3e/source/8086/softfloat_raiseFlags.c",
284 "deps/SoftFloat-3e/source/f128M_add.c",
285 "deps/SoftFloat-3e/source/f128M_div.c",
286 "deps/SoftFloat-3e/source/f128M_eq.c",
287 "deps/SoftFloat-3e/source/f128M_eq_signaling.c",
288 "deps/SoftFloat-3e/source/f128M_le.c",
289 "deps/SoftFloat-3e/source/f128M_le_quiet.c",
290 "deps/SoftFloat-3e/source/f128M_lt.c",
291 "deps/SoftFloat-3e/source/f128M_lt_quiet.c",
292 "deps/SoftFloat-3e/source/f128M_mul.c",
293 "deps/SoftFloat-3e/source/f128M_mulAdd.c",
294 "deps/SoftFloat-3e/source/f128M_rem.c",
295 "deps/SoftFloat-3e/source/f128M_roundToInt.c",
296 "deps/SoftFloat-3e/source/f128M_sqrt.c",
297 "deps/SoftFloat-3e/source/f128M_sub.c",
298 "deps/SoftFloat-3e/source/f128M_to_f16.c",
299 "deps/SoftFloat-3e/source/f128M_to_f32.c",
300 "deps/SoftFloat-3e/source/f128M_to_f64.c",
301 "deps/SoftFloat-3e/source/f128M_to_i32.c",
302 "deps/SoftFloat-3e/source/f128M_to_i32_r_minMag.c",
303 "deps/SoftFloat-3e/source/f128M_to_i64.c",
304 "deps/SoftFloat-3e/source/f128M_to_i64_r_minMag.c",
305 "deps/SoftFloat-3e/source/f128M_to_ui32.c",
306 "deps/SoftFloat-3e/source/f128M_to_ui32_r_minMag.c",
307 "deps/SoftFloat-3e/source/f128M_to_ui64.c",
308 "deps/SoftFloat-3e/source/f128M_to_ui64_r_minMag.c",
309 "deps/SoftFloat-3e/source/f16_add.c",
310 "deps/SoftFloat-3e/source/f16_div.c",
311 "deps/SoftFloat-3e/source/f16_eq.c",
312 "deps/SoftFloat-3e/source/f16_isSignalingNaN.c",
313 "deps/SoftFloat-3e/source/f16_lt.c",
314 "deps/SoftFloat-3e/source/f16_mul.c",
315 "deps/SoftFloat-3e/source/f16_mulAdd.c",
316 "deps/SoftFloat-3e/source/f16_rem.c",
317 "deps/SoftFloat-3e/source/f16_roundToInt.c",
318 "deps/SoftFloat-3e/source/f16_sqrt.c",
319 "deps/SoftFloat-3e/source/f16_sub.c",
320 "deps/SoftFloat-3e/source/f16_to_f128M.c",
321 "deps/SoftFloat-3e/source/f16_to_f64.c",
322 "deps/SoftFloat-3e/source/f32_to_f128M.c",
323 "deps/SoftFloat-3e/source/f64_to_f128M.c",
324 "deps/SoftFloat-3e/source/f64_to_f16.c",
325 "deps/SoftFloat-3e/source/i32_to_f128M.c",
326 "deps/SoftFloat-3e/source/s_add256M.c",
327 "deps/SoftFloat-3e/source/s_addCarryM.c",
328 "deps/SoftFloat-3e/source/s_addComplCarryM.c",
329 "deps/SoftFloat-3e/source/s_addF128M.c",
330 "deps/SoftFloat-3e/source/s_addM.c",
331 "deps/SoftFloat-3e/source/s_addMagsF16.c",
332 "deps/SoftFloat-3e/source/s_addMagsF32.c",
333 "deps/SoftFloat-3e/source/s_addMagsF64.c",
334 "deps/SoftFloat-3e/source/s_approxRecip32_1.c",
335 "deps/SoftFloat-3e/source/s_approxRecipSqrt32_1.c",
336 "deps/SoftFloat-3e/source/s_approxRecipSqrt_1Ks.c",
337 "deps/SoftFloat-3e/source/s_approxRecip_1Ks.c",
338 "deps/SoftFloat-3e/source/s_compare128M.c",
339 "deps/SoftFloat-3e/source/s_compare96M.c",
340 "deps/SoftFloat-3e/source/s_countLeadingZeros16.c",
341 "deps/SoftFloat-3e/source/s_countLeadingZeros32.c",
342 "deps/SoftFloat-3e/source/s_countLeadingZeros64.c",
343 "deps/SoftFloat-3e/source/s_countLeadingZeros8.c",
344 "deps/SoftFloat-3e/source/s_eq128.c",
345 "deps/SoftFloat-3e/source/s_invalidF128M.c",
346 "deps/SoftFloat-3e/source/s_isNaNF128M.c",
347 "deps/SoftFloat-3e/source/s_le128.c",
348 "deps/SoftFloat-3e/source/s_lt128.c",
349 "deps/SoftFloat-3e/source/s_mul128MTo256M.c",
350 "deps/SoftFloat-3e/source/s_mul64To128M.c",
351 "deps/SoftFloat-3e/source/s_mulAddF128M.c",
352 "deps/SoftFloat-3e/source/s_mulAddF16.c",
353 "deps/SoftFloat-3e/source/s_mulAddF32.c",
354 "deps/SoftFloat-3e/source/s_mulAddF64.c",
355 "deps/SoftFloat-3e/source/s_negXM.c",
356 "deps/SoftFloat-3e/source/s_normRoundPackMToF128M.c",
357 "deps/SoftFloat-3e/source/s_normRoundPackToF16.c",
358 "deps/SoftFloat-3e/source/s_normRoundPackToF32.c",
359 "deps/SoftFloat-3e/source/s_normRoundPackToF64.c",
360 "deps/SoftFloat-3e/source/s_normSubnormalF128SigM.c",
361 "deps/SoftFloat-3e/source/s_normSubnormalF16Sig.c",
362 "deps/SoftFloat-3e/source/s_normSubnormalF32Sig.c",
363 "deps/SoftFloat-3e/source/s_normSubnormalF64Sig.c",
364 "deps/SoftFloat-3e/source/s_remStepMBy32.c",
365 "deps/SoftFloat-3e/source/s_roundMToI64.c",
366 "deps/SoftFloat-3e/source/s_roundMToUI64.c",
367 "deps/SoftFloat-3e/source/s_roundPackMToF128M.c",
368 "deps/SoftFloat-3e/source/s_roundPackToF16.c",
369 "deps/SoftFloat-3e/source/s_roundPackToF32.c",
370 "deps/SoftFloat-3e/source/s_roundPackToF64.c",
371 "deps/SoftFloat-3e/source/s_roundToI32.c",
372 "deps/SoftFloat-3e/source/s_roundToI64.c",
373 "deps/SoftFloat-3e/source/s_roundToUI32.c",
374 "deps/SoftFloat-3e/source/s_roundToUI64.c",
375 "deps/SoftFloat-3e/source/s_shiftLeftM.c",
376 "deps/SoftFloat-3e/source/s_shiftNormSigF128M.c",
377 "deps/SoftFloat-3e/source/s_shiftRightJam256M.c",
378 "deps/SoftFloat-3e/source/s_shiftRightJam32.c",
379 "deps/SoftFloat-3e/source/s_shiftRightJam64.c",
380 "deps/SoftFloat-3e/source/s_shiftRightJamM.c",
381 "deps/SoftFloat-3e/source/s_shiftRightM.c",
382 "deps/SoftFloat-3e/source/s_shortShiftLeft64To96M.c",
383 "deps/SoftFloat-3e/source/s_shortShiftLeftM.c",
384 "deps/SoftFloat-3e/source/s_shortShiftRightExtendM.c",
385 "deps/SoftFloat-3e/source/s_shortShiftRightJam64.c",
386 "deps/SoftFloat-3e/source/s_shortShiftRightJamM.c",
387 "deps/SoftFloat-3e/source/s_shortShiftRightM.c",
388 "deps/SoftFloat-3e/source/s_sub1XM.c",
389 "deps/SoftFloat-3e/source/s_sub256M.c",
390 "deps/SoftFloat-3e/source/s_subM.c",
391 "deps/SoftFloat-3e/source/s_subMagsF16.c",
392 "deps/SoftFloat-3e/source/s_subMagsF32.c",
393 "deps/SoftFloat-3e/source/s_subMagsF64.c",
394 "deps/SoftFloat-3e/source/s_tryPropagateNaNF128M.c",
395 "deps/SoftFloat-3e/source/softfloat_state.c",
396 "deps/SoftFloat-3e/source/ui32_to_f128M.c",
397 "deps/SoftFloat-3e/source/ui64_to_f128M.c",
283398};
284399
285fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
286 const shared_mode = try b.exec(&[_][]const u8{ llvm_config_exe, "--shared-mode" });
287 const is_static = mem.startsWith(u8, shared_mode, "static");
288 const libs_output = if (is_static)
289 try b.exec(&[_][]const u8{
290 llvm_config_exe,
291 "--libfiles",
292 "--system-libs",
293 })
294 else
295 try b.exec(&[_][]const u8{
296 llvm_config_exe,
297 "--libs",
298 });
299 const includes_output = try b.exec(&[_][]const u8{ llvm_config_exe, "--includedir" });
300 const libdir_output = try b.exec(&[_][]const u8{ llvm_config_exe, "--libdir" });
301 const prefix_output = try b.exec(&[_][]const u8{ llvm_config_exe, "--prefix" });
302
303 var result = LibraryDep{
304 .prefix = mem.tokenize(prefix_output, " \r\n").next().?,
305 .libs = ArrayList([]const u8).init(b.allocator),
306 .system_libs = ArrayList([]const u8).init(b.allocator),
307 .includes = ArrayList([]const u8).init(b.allocator),
308 .libdirs = ArrayList([]const u8).init(b.allocator),
309 };
310 {
311 var it = mem.tokenize(libs_output, " \r\n");
312 while (it.next()) |lib_arg| {
313 if (mem.startsWith(u8, lib_arg, "-l")) {
314 try result.system_libs.append(lib_arg[2..]);
315 } else {
316 if (fs.path.isAbsolute(lib_arg)) {
317 try result.libs.append(lib_arg);
318 } else {
319 var lib_arg_copy = lib_arg;
320 if (mem.endsWith(u8, lib_arg, ".lib")) {
321 lib_arg_copy = lib_arg[0 .. lib_arg.len - 4];
322 }
323 try result.system_libs.append(lib_arg_copy);
324 }
325 }
326 }
327 }
328 {
329 var it = mem.tokenize(includes_output, " \r\n");
330 while (it.next()) |include_arg| {
331 if (mem.startsWith(u8, include_arg, "-I")) {
332 try result.includes.append(include_arg[2..]);
333 } else {
334 try result.includes.append(include_arg);
335 }
336 }
337 }
338 {
339 var it = mem.tokenize(libdir_output, " \r\n");
340 while (it.next()) |libdir| {
341 if (mem.startsWith(u8, libdir, "-L")) {
342 try result.libdirs.append(libdir[2..]);
343 } else {
344 try result.libdirs.append(libdir);
345 }
346 }
347 }
348 return result;
349}
350
351fn configureStage2(b: *Builder, exe: anytype, ctx: Context, need_cpp_includes: bool) !void {
352 exe.addIncludeDir("src");
353 exe.addIncludeDir(ctx.cmake_binary_dir);
354 addCppLib(b, exe, ctx.cmake_binary_dir, "zigcpp");
355 assert(ctx.lld_include_dir.len != 0);
356 exe.addIncludeDir(ctx.lld_include_dir);
357 {
358 var it = mem.tokenize(ctx.lld_libraries, ";");
359 while (it.next()) |lib| {
360 exe.addObjectFile(lib);
361 }
362 }
363 {
364 var it = mem.tokenize(ctx.clang_libraries, ";");
365 while (it.next()) |lib| {
366 exe.addObjectFile(lib);
367 }
368 }
369 dependOnLib(b, exe, ctx.llvm);
370
371 // Boy, it sure would be nice to simply linkSystemLibrary("c++") and rely on zig's
372 // ability to provide libc++ right? Well thanks to C++ not having a stable ABI this
373 // will cause linker errors. It would work in the situation when `zig cc` is used to
374 // build LLVM, Clang, and LLD, however when depending on them as system libraries, system
375 // libc++ must be used.
376 const cross_compile = false; // TODO
377 if (cross_compile) {
378 // In this case we assume that zig cc was used to build the LLVM, Clang, LLD dependencies.
379 exe.linkSystemLibrary("c++");
380 } else {
381 if (exe.target.getOsTag() == .linux) {
382 // First we try to static link against gcc libstdc++. If that doesn't work,
383 // we fall back to -lc++ and cross our fingers.
384 addCxxKnownPath(b, ctx, exe, "libstdc++.a", "", need_cpp_includes) catch |err| switch (err) {
385 error.RequiredLibraryNotFound => {
386 exe.linkSystemLibrary("c++");
387 },
388 else => |e| return e,
389 };
390
391 exe.linkSystemLibrary("pthread");
392 } else if (exe.target.isFreeBSD()) {
393 try addCxxKnownPath(b, ctx, exe, "libc++.a", null, need_cpp_includes);
394 exe.linkSystemLibrary("pthread");
395 } else if (exe.target.isDarwin()) {
396 if (addCxxKnownPath(b, ctx, exe, "libgcc_eh.a", "", need_cpp_includes)) {
397 // Compiler is GCC.
398 try addCxxKnownPath(b, ctx, exe, "libstdc++.a", null, need_cpp_includes);
399 exe.linkSystemLibrary("pthread");
400 // TODO LLD cannot perform this link.
401 // Set ZIG_SYSTEM_LINKER_HACK env var to use system linker ld instead.
402 // See https://github.com/ziglang/zig/issues/1535
403 } else |err| switch (err) {
404 error.RequiredLibraryNotFound => {
405 // System compiler, not gcc.
406 exe.linkSystemLibrary("c++");
407 },
408 else => |e| return e,
409 }
410 }
411
412 if (ctx.dia_guids_lib.len != 0) {
413 exe.addObjectFile(ctx.dia_guids_lib);
414 }
415 }
416}
417
418fn addCxxKnownPath(
419 b: *Builder,
420 ctx: Context,
421 exe: anytype,
422 objname: []const u8,
423 errtxt: ?[]const u8,
424 need_cpp_includes: bool,
425) !void {
426 const path_padded = try b.exec(&[_][]const u8{
427 ctx.cxx_compiler,
428 b.fmt("-print-file-name={}", .{objname}),
429 });
430 const path_unpadded = mem.tokenize(path_padded, "\r\n").next().?;
431 if (mem.eql(u8, path_unpadded, objname)) {
432 if (errtxt) |msg| {
433 warn("{}", .{msg});
434 } else {
435 warn("Unable to determine path to {}\n", .{objname});
436 }
437 return error.RequiredLibraryNotFound;
438 }
439 exe.addObjectFile(path_unpadded);
440
441 // TODO a way to integrate with system c++ include files here
442 // cc -E -Wp,-v -xc++ /dev/null
443 if (need_cpp_includes) {
444 // I used these temporarily for testing something but we obviously need a
445 // more general purpose solution here.
446 //exe.addIncludeDir("/nix/store/b3zsk4ihlpiimv3vff86bb5bxghgdzb9-gcc-9.2.0/lib/gcc/x86_64-unknown-linux-gnu/9.2.0/../../../../include/c++/9.2.0");
447 //exe.addIncludeDir("/nix/store/b3zsk4ihlpiimv3vff86bb5bxghgdzb9-gcc-9.2.0/lib/gcc/x86_64-unknown-linux-gnu/9.2.0/../../../../include/c++/9.2.0/x86_64-unknown-linux-gnu");
448 //exe.addIncludeDir("/nix/store/b3zsk4ihlpiimv3vff86bb5bxghgdzb9-gcc-9.2.0/lib/gcc/x86_64-unknown-linux-gnu/9.2.0/../../../../include/c++/9.2.0/backward");
449 }
450}
451
452const Context = struct {
453 cmake_binary_dir: []const u8,
454 cxx_compiler: []const u8,
455 llvm_config_exe: []const u8,
456 lld_include_dir: []const u8,
457 lld_libraries: []const u8,
458 clang_libraries: []const u8,
459 dia_guids_lib: []const u8,
460 llvm: LibraryDep,
400const stage1_sources = [_][]const u8{
401 "src/stage1/analyze.cpp",
402 "src/stage1/ast_render.cpp",
403 "src/stage1/bigfloat.cpp",
404 "src/stage1/bigint.cpp",
405 "src/stage1/buffer.cpp",
406 "src/stage1/codegen.cpp",
407 "src/stage1/dump_analysis.cpp",
408 "src/stage1/errmsg.cpp",
409 "src/stage1/error.cpp",
410 "src/stage1/heap.cpp",
411 "src/stage1/ir.cpp",
412 "src/stage1/ir_print.cpp",
413 "src/stage1/mem.cpp",
414 "src/stage1/os.cpp",
415 "src/stage1/parser.cpp",
416 "src/stage1/range_set.cpp",
417 "src/stage1/stage1.cpp",
418 "src/stage1/target.cpp",
419 "src/stage1/tokenizer.cpp",
420 "src/stage1/util.cpp",
421 "src/stage1/softfloat_ext.cpp",
422};
423const optimized_c_sources = [_][]const u8{
424 "src/stage1/parse_f128.c",
425};
426const zig_cpp_sources = [_][]const u8{
427 // These are planned to stay even when we are self-hosted.
428 "src/zig_llvm.cpp",
429 "src/zig_clang.cpp",
430 "src/zig_clang_driver.cpp",
431 "src/zig_clang_cc1_main.cpp",
432 "src/zig_clang_cc1as_main.cpp",
433 // https://github.com/ziglang/zig/issues/6363
434 "src/windows_sdk.cpp",
461435};
462436
463const max_config_h_bytes = 1 * 1024 * 1024;
464
465fn findAndReadConfigH(b: *Builder) ![]const u8 {
466 var check_dir = fs.path.dirname(b.zig_exe).?;
467 while (true) {
468 var dir = try fs.cwd().openDir(check_dir, .{});
469 defer dir.close();
470
471 const config_h_text = dir.readFileAlloc(b.allocator, "config.h", max_config_h_bytes) catch |err| switch (err) {
472 error.FileNotFound => {
473 const new_check_dir = fs.path.dirname(check_dir);
474 if (new_check_dir == null or mem.eql(u8, new_check_dir.?, check_dir)) {
475 std.debug.warn("Unable to find config.h file relative to Zig executable.\n", .{});
476 std.debug.warn("`zig build` must be run using a Zig executable within the source tree.\n", .{});
477 std.process.exit(1);
478 }
479 check_dir = new_check_dir.?;
480 continue;
481 },
482 else => |e| return e,
483 };
484 return config_h_text;
485 } else unreachable; // TODO should not need `else unreachable`.
486}
487
488fn parseConfigH(b: *Builder, config_h_text: []const u8) Context {
489 var ctx: Context = .{
490 .cmake_binary_dir = undefined,
491 .cxx_compiler = undefined,
492 .llvm_config_exe = undefined,
493 .lld_include_dir = undefined,
494 .lld_libraries = undefined,
495 .clang_libraries = undefined,
496 .dia_guids_lib = undefined,
497 .llvm = undefined,
498 };
499
500 const mappings = [_]struct { prefix: []const u8, field: []const u8 }{
501 .{
502 .prefix = "#define ZIG_CMAKE_BINARY_DIR ",
503 .field = "cmake_binary_dir",
504 },
505 .{
506 .prefix = "#define ZIG_CXX_COMPILER ",
507 .field = "cxx_compiler",
508 },
509 .{
510 .prefix = "#define ZIG_LLD_INCLUDE_PATH ",
511 .field = "lld_include_dir",
512 },
513 .{
514 .prefix = "#define ZIG_LLD_LIBRARIES ",
515 .field = "lld_libraries",
516 },
517 .{
518 .prefix = "#define ZIG_CLANG_LIBRARIES ",
519 .field = "clang_libraries",
520 },
521 .{
522 .prefix = "#define ZIG_LLVM_CONFIG_EXE ",
523 .field = "llvm_config_exe",
524 },
525 .{
526 .prefix = "#define ZIG_DIA_GUIDS_LIB ",
527 .field = "dia_guids_lib",
528 },
529 };
530
531 var lines_it = mem.tokenize(config_h_text, "\r\n");
532 while (lines_it.next()) |line| {
533 inline for (mappings) |mapping| {
534 if (mem.startsWith(u8, line, mapping.prefix)) {
535 var it = mem.split(line, "\"");
536 _ = it.next().?; // skip the stuff before the quote
537 const quoted = it.next().?; // the stuff inside the quote
538 @field(ctx, mapping.field) = toNativePathSep(b, quoted);
539 }
540 }
541 }
542 return ctx;
543}
544
545fn toNativePathSep(b: *Builder, s: []const u8) []u8 {
546 const duplicated = mem.dupe(b.allocator, u8, s) catch unreachable;
547 for (duplicated) |*byte| switch (byte.*) {
548 '/' => byte.* = fs.path.sep,
549 else => {},
550 };
551 return duplicated;
552}
437const clang_libs = [_][]const u8{
438 "clangFrontendTool",
439 "clangCodeGen",
440 "clangFrontend",
441 "clangDriver",
442 "clangSerialization",
443 "clangSema",
444 "clangStaticAnalyzerFrontend",
445 "clangStaticAnalyzerCheckers",
446 "clangStaticAnalyzerCore",
447 "clangAnalysis",
448 "clangASTMatchers",
449 "clangAST",
450 "clangParse",
451 "clangSema",
452 "clangBasic",
453 "clangEdit",
454 "clangLex",
455 "clangARCMigrate",
456 "clangRewriteFrontend",
457 "clangRewrite",
458 "clangCrossTU",
459 "clangIndex",
460 "clangToolingCore",
461};
462const lld_libs = [_][]const u8{
463 "lldDriver",
464 "lldMinGW",
465 "lldELF",
466 "lldCOFF",
467 "lldMachO",
468 "lldWasm",
469 "lldReaderWriter",
470 "lldCore",
471 "lldYAML",
472 "lldCommon",
473};
474// This list can be re-generated with `llvm-config --libfiles` and then
475// reformatting using your favorite text editor. Note we do not execute
476// `llvm-config` here because we are cross compiling.
477const llvm_libs = [_][]const u8{
478 "LLVMXRay",
479 "LLVMWindowsManifest",
480 "LLVMSymbolize",
481 "LLVMDebugInfoPDB",
482 "LLVMOrcJIT",
483 "LLVMOrcError",
484 "LLVMJITLink",
485 "LLVMObjectYAML",
486 "LLVMMCA",
487 "LLVMLTO",
488 "LLVMPasses",
489 "LLVMCoroutines",
490 "LLVMObjCARCOpts",
491 "LLVMExtensions",
492 "LLVMLineEditor",
493 "LLVMLibDriver",
494 "LLVMInterpreter",
495 "LLVMFuzzMutate",
496 "LLVMMCJIT",
497 "LLVMExecutionEngine",
498 "LLVMRuntimeDyld",
499 "LLVMDWARFLinker",
500 "LLVMDlltoolDriver",
501 "LLVMOption",
502 "LLVMDebugInfoGSYM",
503 "LLVMCoverage",
504 "LLVMXCoreDisassembler",
505 "LLVMXCoreCodeGen",
506 "LLVMXCoreDesc",
507 "LLVMXCoreInfo",
508 "LLVMX86Disassembler",
509 "LLVMX86CodeGen",
510 "LLVMX86AsmParser",
511 "LLVMX86Desc",
512 "LLVMX86Info",
513 "LLVMWebAssemblyDisassembler",
514 "LLVMWebAssemblyCodeGen",
515 "LLVMWebAssemblyDesc",
516 "LLVMWebAssemblyAsmParser",
517 "LLVMWebAssemblyInfo",
518 "LLVMSystemZDisassembler",
519 "LLVMSystemZCodeGen",
520 "LLVMSystemZAsmParser",
521 "LLVMSystemZDesc",
522 "LLVMSystemZInfo",
523 "LLVMSparcDisassembler",
524 "LLVMSparcCodeGen",
525 "LLVMSparcAsmParser",
526 "LLVMSparcDesc",
527 "LLVMSparcInfo",
528 "LLVMRISCVDisassembler",
529 "LLVMRISCVCodeGen",
530 "LLVMRISCVAsmParser",
531 "LLVMRISCVDesc",
532 "LLVMRISCVUtils",
533 "LLVMRISCVInfo",
534 "LLVMPowerPCDisassembler",
535 "LLVMPowerPCCodeGen",
536 "LLVMPowerPCAsmParser",
537 "LLVMPowerPCDesc",
538 "LLVMPowerPCInfo",
539 "LLVMNVPTXCodeGen",
540 "LLVMNVPTXDesc",
541 "LLVMNVPTXInfo",
542 "LLVMMSP430Disassembler",
543 "LLVMMSP430CodeGen",
544 "LLVMMSP430AsmParser",
545 "LLVMMSP430Desc",
546 "LLVMMSP430Info",
547 "LLVMMipsDisassembler",
548 "LLVMMipsCodeGen",
549 "LLVMMipsAsmParser",
550 "LLVMMipsDesc",
551 "LLVMMipsInfo",
552 "LLVMLanaiDisassembler",
553 "LLVMLanaiCodeGen",
554 "LLVMLanaiAsmParser",
555 "LLVMLanaiDesc",
556 "LLVMLanaiInfo",
557 "LLVMHexagonDisassembler",
558 "LLVMHexagonCodeGen",
559 "LLVMHexagonAsmParser",
560 "LLVMHexagonDesc",
561 "LLVMHexagonInfo",
562 "LLVMBPFDisassembler",
563 "LLVMBPFCodeGen",
564 "LLVMBPFAsmParser",
565 "LLVMBPFDesc",
566 "LLVMBPFInfo",
567 "LLVMAVRDisassembler",
568 "LLVMAVRCodeGen",
569 "LLVMAVRAsmParser",
570 "LLVMAVRDesc",
571 "LLVMAVRInfo",
572 "LLVMARMDisassembler",
573 "LLVMARMCodeGen",
574 "LLVMARMAsmParser",
575 "LLVMARMDesc",
576 "LLVMARMUtils",
577 "LLVMARMInfo",
578 "LLVMAMDGPUDisassembler",
579 "LLVMAMDGPUCodeGen",
580 "LLVMMIRParser",
581 "LLVMipo",
582 "LLVMInstrumentation",
583 "LLVMVectorize",
584 "LLVMLinker",
585 "LLVMIRReader",
586 "LLVMAsmParser",
587 "LLVMFrontendOpenMP",
588 "LLVMAMDGPUAsmParser",
589 "LLVMAMDGPUDesc",
590 "LLVMAMDGPUUtils",
591 "LLVMAMDGPUInfo",
592 "LLVMAArch64Disassembler",
593 "LLVMMCDisassembler",
594 "LLVMAArch64CodeGen",
595 "LLVMCFGuard",
596 "LLVMGlobalISel",
597 "LLVMSelectionDAG",
598 "LLVMAsmPrinter",
599 "LLVMDebugInfoDWARF",
600 "LLVMCodeGen",
601 "LLVMTarget",
602 "LLVMScalarOpts",
603 "LLVMInstCombine",
604 "LLVMAggressiveInstCombine",
605 "LLVMTransformUtils",
606 "LLVMBitWriter",
607 "LLVMAnalysis",
608 "LLVMProfileData",
609 "LLVMObject",
610 "LLVMTextAPI",
611 "LLVMBitReader",
612 "LLVMCore",
613 "LLVMRemarks",
614 "LLVMBitstreamReader",
615 "LLVMAArch64AsmParser",
616 "LLVMMCParser",
617 "LLVMAArch64Desc",
618 "LLVMMC",
619 "LLVMDebugInfoCodeView",
620 "LLVMDebugInfoMSF",
621 "LLVMBinaryFormat",
622 "LLVMAArch64Utils",
623 "LLVMAArch64Info",
624 "LLVMSupport",
625 "LLVMDemangle",
626};
lib/std/build.zig+76-4
......@@ -1150,6 +1150,11 @@ const CSourceFile = struct {
11501150 args: []const []const u8,
11511151};
11521152
1153const CSourceFiles = struct {
1154 files: []const []const u8,
1155 flags: []const []const u8,
1156};
1157
11531158fn isLibCLibrary(name: []const u8) bool {
11541159 const libc_libraries = [_][]const u8{ "c", "m", "dl", "rt", "pthread" };
11551160 for (libc_libraries) |libc_lib_name| {
......@@ -1297,6 +1302,7 @@ pub const LibExeObjStep = struct {
12971302 SystemLib: []const u8,
12981303 AssemblyFile: FileSource,
12991304 CSourceFile: *CSourceFile,
1305 CSourceFiles: *CSourceFiles,
13001306 };
13011307
13021308 const IncludeDir = union(enum) {
......@@ -1670,9 +1676,25 @@ pub const LibExeObjStep = struct {
16701676 self.filter = text;
16711677 }
16721678
1673 pub fn addCSourceFile(self: *LibExeObjStep, file: []const u8, args: []const []const u8) void {
1679 /// Handy when you have many C/C++ source files and want them all to have the same flags.
1680 pub fn addCSourceFiles(self: *LibExeObjStep, files: []const []const u8, flags: []const []const u8) void {
1681 const c_source_files = self.builder.allocator.create(CSourceFiles) catch unreachable;
1682
1683 const flags_copy = self.builder.allocator.alloc([]u8, flags.len) catch unreachable;
1684 for (flags) |flag, i| {
1685 flags_copy[i] = self.builder.dupe(flag);
1686 }
1687
1688 c_source_files.* = .{
1689 .files = files,
1690 .flags = flags_copy,
1691 };
1692 self.link_objects.append(LinkObject{ .CSourceFiles = c_source_files }) catch unreachable;
1693 }
1694
1695 pub fn addCSourceFile(self: *LibExeObjStep, file: []const u8, flags: []const []const u8) void {
16741696 self.addCSourceFileSource(.{
1675 .args = args,
1697 .args = flags,
16761698 .source = .{ .path = file },
16771699 });
16781700 }
......@@ -1795,6 +1817,10 @@ pub const LibExeObjStep = struct {
17951817 out.writeAll("};\n") catch unreachable;
17961818 return;
17971819 },
1820 [:0]const u8 => {
1821 out.print("pub const {z}: [:0]const u8 = \"{Z}\";\n", .{ name, value }) catch unreachable;
1822 return;
1823 },
17981824 []const u8 => {
17991825 out.print("pub const {z}: []const u8 = \"{Z}\";\n", .{ name, value }) catch unreachable;
18001826 return;
......@@ -1808,6 +1834,22 @@ pub const LibExeObjStep = struct {
18081834 }
18091835 return;
18101836 },
1837 std.builtin.Version => {
1838 out.print(
1839 \\pub const {z}: @import("builtin").Version = .{{
1840 \\ .major = {d},
1841 \\ .minor = {d},
1842 \\ .patch = {d},
1843 \\}};
1844 \\
1845 , .{
1846 name,
1847
1848 value.major,
1849 value.minor,
1850 value.patch,
1851 }) catch unreachable;
1852 },
18111853 std.SemanticVersion => {
18121854 out.print(
18131855 \\pub const {z}: @import("std").SemanticVersion = .{{
......@@ -2015,8 +2057,7 @@ pub const LibExeObjStep = struct {
20152057 },
20162058 },
20172059 .SystemLib => |name| {
2018 try zig_args.append("--library");
2019 try zig_args.append(name);
2060 try zig_args.append(builder.fmt("-l{s}", .{name}));
20202061 },
20212062 .AssemblyFile => |asm_file| {
20222063 if (prev_has_extra_flags) {
......@@ -2026,6 +2067,7 @@ pub const LibExeObjStep = struct {
20262067 }
20272068 try zig_args.append(asm_file.getPath(builder));
20282069 },
2070
20292071 .CSourceFile => |c_source_file| {
20302072 if (c_source_file.args.len == 0) {
20312073 if (prev_has_extra_flags) {
......@@ -2042,6 +2084,25 @@ pub const LibExeObjStep = struct {
20422084 }
20432085 try zig_args.append(c_source_file.source.getPath(builder));
20442086 },
2087
2088 .CSourceFiles => |c_source_files| {
2089 if (c_source_files.flags.len == 0) {
2090 if (prev_has_extra_flags) {
2091 try zig_args.append("-cflags");
2092 try zig_args.append("--");
2093 prev_has_extra_flags = false;
2094 }
2095 } else {
2096 try zig_args.append("-cflags");
2097 for (c_source_files.flags) |flag| {
2098 try zig_args.append(flag);
2099 }
2100 try zig_args.append("--");
2101 }
2102 for (c_source_files.files) |file| {
2103 try zig_args.append(builder.pathFromRoot(file));
2104 }
2105 },
20452106 }
20462107 }
20472108
......@@ -2304,6 +2365,17 @@ pub const LibExeObjStep = struct {
23042365 }
23052366 }
23062367
2368 for (builder.search_prefixes.items) |search_prefix| {
2369 try zig_args.append("-L");
2370 try zig_args.append(try fs.path.join(builder.allocator, &[_][]const u8{
2371 search_prefix, "lib",
2372 }));
2373 try zig_args.append("-isystem");
2374 try zig_args.append(try fs.path.join(builder.allocator, &[_][]const u8{
2375 search_prefix, "include",
2376 }));
2377 }
2378
23072379 if (self.valgrind_support) |valgrind_support| {
23082380 if (valgrind_support) {
23092381 try zig_args.append("-fvalgrind");
src/config.zig.in deleted-7
......@@ -1,7 +0,0 @@
1pub const have_llvm = true;
2pub const version: []const u8 = "@ZIG_VERSION@";
3pub const log_scopes: []const []const u8 = &[_][]const u8{};
4pub const zir_dumps: []const []const u8 = &[_][]const u8{};
5pub const enable_tracy = false;
6pub const is_stage1 = true;
7pub const skip_non_native = false;
src/stage1.zig+14
......@@ -251,6 +251,20 @@ const Error = extern enum {
251251 Locked,
252252};
253253
254// ABI warning
255export fn stage2_version_string() [*:0]const u8 {
256 return build_options.version;
257}
258
259// ABI warning
260export fn stage2_version() Stage2SemVer {
261 return .{
262 .major = build_options.semver.major,
263 .minor = build_options.semver.minor,
264 .patch = build_options.semver.patch,
265 };
266}
267
254268// ABI warning
255269export fn stage2_attach_segfault_handler() void {
256270 if (std.debug.runtime_safety and std.debug.have_segfault_handling_support) {
src/stage1/analyze.cpp-1
......@@ -8,7 +8,6 @@
88#include "analyze.hpp"
99#include "ast_render.hpp"
1010#include "codegen.hpp"
11#include "config.h"
1211#include "error.hpp"
1312#include "ir.hpp"
1413#include "ir_print.hpp"
src/stage1/codegen.cpp+6-7
......@@ -8,7 +8,6 @@
88#include "analyze.hpp"
99#include "ast_render.hpp"
1010#include "codegen.hpp"
11#include "config.h"
1211#include "errmsg.hpp"
1312#include "error.hpp"
1413#include "hash_map.hpp"
......@@ -9051,7 +9050,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
90519050 buf_append_str(contents, "/// Deprecated: use `std.Target.current.cpu.arch.endian()`\n");
90529051 buf_append_str(contents, "pub const endian = Target.current.cpu.arch.endian();\n");
90539052 buf_appendf(contents, "pub const output_mode = OutputMode.Obj;\n");
9054 buf_appendf(contents, "pub const link_mode = LinkMode.%s;\n", ZIG_LINK_MODE);
9053 buf_appendf(contents, "pub const link_mode = LinkMode.%s;\n", ZIG_QUOTE(ZIG_LINK_MODE));
90559054 buf_appendf(contents, "pub const is_test = false;\n");
90569055 buf_appendf(contents, "pub const single_threaded = %s;\n", bool_to_str(g->is_single_threaded));
90579056 buf_appendf(contents, "pub const abi = Abi.%s;\n", cur_abi);
......@@ -9251,9 +9250,9 @@ static void init(CodeGen *g) {
92519250 g->builder = LLVMCreateBuilder();
92529251 g->dbuilder = ZigLLVMCreateDIBuilder(g->module, true);
92539252
9254 // Don't use ZIG_VERSION_STRING here, llvm misparses it when it includes
9255 // the git revision.
9256 Buf *producer = buf_sprintf("zig %d.%d.%d", ZIG_VERSION_MAJOR, ZIG_VERSION_MINOR, ZIG_VERSION_PATCH);
9253 // Don't use the version string here, llvm misparses it when it includes the git revision.
9254 Stage2SemVer semver = stage2_version();
9255 Buf *producer = buf_sprintf("zig %d.%d.%d", semver.major, semver.minor, semver.patch);
92579256 const char *flags = "";
92589257 unsigned runtime_version = 0;
92599258
......@@ -9551,9 +9550,9 @@ void codegen_build_object(CodeGen *g) {
95519550 }
95529551
95539552 do_code_gen(g);
9554 codegen_add_time_event(g, "LLVM Emit Output");
9553 codegen_add_time_event(g, "LLVM Emit Object");
95559554 {
9556 const char *progress_name = "LLVM Emit Output";
9555 const char *progress_name = "LLVM Emit Object";
95579556 codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node,
95589557 progress_name, strlen(progress_name), 0));
95599558 }
src/stage1/config.h.in deleted-26
......@@ -1,26 +0,0 @@
1/*
2 * Copyright (c) 2016 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#ifndef ZIG_CONFIG_H
9#define ZIG_CONFIG_H
10
11#define ZIG_VERSION_MAJOR @ZIG_VERSION_MAJOR@
12#define ZIG_VERSION_MINOR @ZIG_VERSION_MINOR@
13#define ZIG_VERSION_PATCH @ZIG_VERSION_PATCH@
14#define ZIG_VERSION_STRING "@ZIG_VERSION@"
15
16// Used for communicating build information to self hosted build.
17#define ZIG_CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@"
18#define ZIG_CXX_COMPILER "@CMAKE_CXX_COMPILER@"
19#define ZIG_LLD_INCLUDE_PATH "@LLD_INCLUDE_DIRS@"
20#define ZIG_LLD_LIBRARIES "@LLD_LIBRARIES@"
21#define ZIG_CLANG_LIBRARIES "@CLANG_LIBRARIES@"
22#define ZIG_LLVM_CONFIG_EXE "@LLVM_CONFIG_EXE@"
23#define ZIG_DIA_GUIDS_LIB "@ZIG_DIA_GUIDS_LIB_ESCAPED@"
24#define ZIG_LINK_MODE "@ZIG_LINK_MODE@"
25
26#endif
src/stage1/dump_analysis.cpp+1-2
......@@ -7,7 +7,6 @@
77
88#include "dump_analysis.hpp"
99#include "analyze.hpp"
10#include "config.h"
1110#include "ir.hpp"
1211#include "codegen.hpp"
1312#include "os.hpp"
......@@ -1237,7 +1236,7 @@ void zig_print_analysis_dump(CodeGen *g, FILE *f, const char *one_indent, const
12371236 jw_begin_object(jw);
12381237 {
12391238 jw_object_field(jw, "zigVersion");
1240 jw_string(jw, ZIG_VERSION_STRING);
1239 jw_string(jw, stage2_version_string());
12411240
12421241 jw_object_field(jw, "builds");
12431242 jw_begin_array(jw);
src/stage1/heap.cpp-1
......@@ -8,7 +8,6 @@
88#include <new>
99#include <string.h>
1010
11#include "config.h"
1211#include "heap.hpp"
1312
1413namespace heap {
src/stage1/heap.hpp-1
......@@ -8,7 +8,6 @@
88#ifndef ZIG_HEAP_HPP
99#define ZIG_HEAP_HPP
1010
11#include "config.h"
1211#include "util_base.hpp"
1312#include "mem.hpp"
1413
src/stage1/mem.cpp-1
......@@ -5,7 +5,6 @@
55 * See http://opensource.org/licenses/MIT
66 */
77
8#include "config.h"
98#include "mem.hpp"
109#include "heap.hpp"
1110
src/stage1/mem.hpp-1
......@@ -12,7 +12,6 @@
1212#include <stdio.h>
1313#include <stdlib.h>
1414
15#include "config.h"
1615#include "util_base.hpp"
1716#include "mem_type_info.hpp"
1817
src/stage1/mem_type_info.hpp-2
......@@ -8,8 +8,6 @@
88#ifndef ZIG_MEM_TYPE_INFO_HPP
99#define ZIG_MEM_TYPE_INFO_HPP
1010
11#include "config.h"
12
1311namespace mem {
1412
1513struct TypeInfo {
src/stage1/stage2.h+6
......@@ -156,6 +156,12 @@ struct Stage2SemVer {
156156 uint32_t patch;
157157};
158158
159// ABI warning
160ZIG_EXTERN_C const char *stage2_version_string(void);
161
162// ABI warning
163ZIG_EXTERN_C Stage2SemVer stage2_version(void);
164
159165// ABI warning
160166ZIG_EXTERN_C enum Error stage2_target_parse(struct ZigTarget *target, const char *zig_triple, const char *mcpu,
161167 const char *dynamic_linker);
src/stage1/util.hpp+3-1
......@@ -17,7 +17,9 @@
1717#include <intrin.h>
1818#endif
1919
20#include "config.h"
20#define ZIG_Q(x) #x
21#define ZIG_QUOTE(x) ZIG_Q(x)
22
2123#include "util_base.hpp"
2224#include "heap.hpp"
2325#include "mem.hpp"
src/stage1/zig0.cpp+8
......@@ -537,3 +537,11 @@ const char *stage2_add_link_lib(struct ZigStage1 *stage1,
537537{
538538 return nullptr;
539539}
540
541const char *stage2_version_string(void) {
542 return "0.0.0+zig0";
543}
544
545struct Stage2SemVer stage2_version(void) {
546 return {0, 0, 0};
547}
src/stage1_config.zig created+13
......@@ -0,0 +1,13 @@
1pub const have_llvm = true;
2pub const version: [:0]const u8 = "0.0.0+zig0";
3pub const semver: @import("std").SemanticVersion = .{
4 .major = 0,
5 .minor = 0,
6 .patch = 0,
7 .build = "zig0",
8};
9pub const log_scopes: []const []const u8 = &[_][]const u8{};
10pub const zir_dumps: []const []const u8 = &[_][]const u8{};
11pub const enable_tracy = false;
12pub const is_stage1 = true;
13pub const skip_non_native = false;
src/zig_clang.h+1-1
......@@ -8,7 +8,7 @@
88#ifndef ZIG_ZIG_CLANG_H
99#define ZIG_ZIG_CLANG_H
1010
11#include "stage2.h"
11#include "stage1/stage2.h"
1212#include <inttypes.h>
1313#include <stdbool.h>
1414