authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-23 00:00:24-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-23 00:00:24-07:00
log800a4a6cebf363c8ba3d1fcfff55db8bfb71f731
tree566a2b9995048fb457bda97db04f8d5d5c5d50be
parentfc88d36daea40b69690186730ae7f2a5296585a9

eliminate dependency of libzigcpp.a on libzigstage1.a

This allows us to create a build of self-hosted with LLVM extensions enabled but without the stage1 backend.

5 files changed, 36 insertions(+), 29 deletions(-)

BRANCH_TODO+6-7
...@@ -1,5 +1,10 @@...@@ -1,5 +1,10 @@
1 * --main-pkg-path
2 * add CLI support for a way to pass extra flags to c source files
3 * musl
4 * support rpaths in ELF linker code
5 * implement proper parsing of LLD stderr/stdout and exposing compile errors
6 * tests passing with -Dskip-non-native
1 * windows CUSTOMBUILD : error : unable to build compiler_rt: FileNotFound [D:\a\1\s\build\zig_install_lib_files.vcxproj]7 * windows CUSTOMBUILD : error : unable to build compiler_rt: FileNotFound [D:\a\1\s\build\zig_install_lib_files.vcxproj]
2 * separate libzigcpp.a and libzigstage1.a so that we can do non-stage1 builds
3 * repair @cImport8 * repair @cImport
4 * make sure zig cc works9 * make sure zig cc works
5 - using it as a preprocessor (-E)10 - using it as a preprocessor (-E)
...@@ -13,23 +18,17 @@...@@ -13,23 +18,17 @@
13 * -fno-emit-asm (default) do not output .s (assembly code)\n"18 * -fno-emit-asm (default) do not output .s (assembly code)\n"
14 * -femit-llvm-ir produce a .ll file with LLVM IR\n"19 * -femit-llvm-ir produce a .ll file with LLVM IR\n"
15 * -fno-emit-llvm-ir (default) do not produce a .ll file with LLVM IR\n"20 * -fno-emit-llvm-ir (default) do not produce a .ll file with LLVM IR\n"
16 * support rpaths in ELF linker code
17 * add CLI support for a way to pass extra flags to c source files
18 * musl
19 * mingw-w6421 * mingw-w64
20 * MachO LLD linking22 * MachO LLD linking
21 * COFF LLD linking23 * COFF LLD linking
22 * WASM LLD linking24 * WASM LLD linking
23 * --main-pkg-path
24 * skip LLD caching when bin directory is not in the cache (so we don't put `id.txt` into the cwd)25 * skip LLD caching when bin directory is not in the cache (so we don't put `id.txt` into the cwd)
25 (maybe make it an explicit option and have main.zig disable it)26 (maybe make it an explicit option and have main.zig disable it)
26 * audit the CLI options for stage227 * audit the CLI options for stage2
27 * audit the base cache hash28 * audit the base cache hash
28 * implement proper parsing of LLD stderr/stdout and exposing compile errors
29 * implement proper parsing of clang stderr/stdout and exposing compile errors29 * implement proper parsing of clang stderr/stdout and exposing compile errors
30 * On operating systems that support it, do an execve for `zig test` and `zig run` rather than child process.30 * On operating systems that support it, do an execve for `zig test` and `zig run` rather than child process.
31 * restore error messages for stage2_add_link_lib31 * restore error messages for stage2_add_link_lib
32 * update std/build.zig to use new CLI
3332
34 * support cross compiling stage2 with `zig build`33 * support cross compiling stage2 with `zig build`
35 * implement proper compile errors for failing to build glibc crt files and shared libs34 * implement proper compile errors for failing to build glibc crt files and shared libs
CMakeLists.txt+21-13
...@@ -89,7 +89,7 @@ if(APPLE AND ZIG_WORKAROUND_4799)...@@ -89,7 +89,7 @@ if(APPLE AND ZIG_WORKAROUND_4799)
89 list(APPEND LLVM_LIBRARIES "-Wl,${CMAKE_PREFIX_PATH}/lib/libPolly.a" "-Wl,${CMAKE_PREFIX_PATH}/lib/libPollyPPCG.a" "-Wl,${CMAKE_PREFIX_PATH}/lib/libPollyISL.a")89 list(APPEND LLVM_LIBRARIES "-Wl,${CMAKE_PREFIX_PATH}/lib/libPolly.a" "-Wl,${CMAKE_PREFIX_PATH}/lib/libPollyPPCG.a" "-Wl,${CMAKE_PREFIX_PATH}/lib/libPollyISL.a")
90endif()90endif()
9191
92set(ZIG_CPP_LIB_DIR "${CMAKE_BINARY_DIR}/zig_cpp")92set(ZIG_CPP_LIB_DIR "${CMAKE_BINARY_DIR}/zigcpp")
9393
94# Handle multi-config builds and place each into a common lib. The VS generator94# Handle multi-config builds and place each into a common lib. The VS generator
95# for example will append a Debug folder by default if not explicitly specified.95# for example will append a Debug folder by default if not explicitly specified.
...@@ -260,7 +260,7 @@ set(ZIG0_SOURCES...@@ -260,7 +260,7 @@ set(ZIG0_SOURCES
260 "${CMAKE_SOURCE_DIR}/src/stage1/zig0.cpp"260 "${CMAKE_SOURCE_DIR}/src/stage1/zig0.cpp"
261)261)
262262
263set(ZIG_SOURCES263set(STAGE1_SOURCES
264 "${CMAKE_SOURCE_DIR}/src/stage1/analyze.cpp"264 "${CMAKE_SOURCE_DIR}/src/stage1/analyze.cpp"
265 "${CMAKE_SOURCE_DIR}/src/stage1/ast_render.cpp"265 "${CMAKE_SOURCE_DIR}/src/stage1/ast_render.cpp"
266 "${CMAKE_SOURCE_DIR}/src/stage1/bigfloat.cpp"266 "${CMAKE_SOURCE_DIR}/src/stage1/bigfloat.cpp"
...@@ -392,21 +392,19 @@ if(ZIG_TEST_COVERAGE)...@@ -392,21 +392,19 @@ if(ZIG_TEST_COVERAGE)
392 set(EXE_LDFLAGS "${EXE_LDFLAGS} -fprofile-arcs -ftest-coverage")392 set(EXE_LDFLAGS "${EXE_LDFLAGS} -fprofile-arcs -ftest-coverage")
393endif()393endif()
394394
395add_library(zig_cpp STATIC ${ZIG_SOURCES} ${ZIG_CPP_SOURCES})395add_library(zigcpp STATIC ${ZIG_CPP_SOURCES})
396set_target_properties(zig_cpp PROPERTIES396set_target_properties(zigcpp PROPERTIES
397 COMPILE_FLAGS ${EXE_CFLAGS}397 COMPILE_FLAGS ${EXE_CFLAGS}
398)398)
399399
400target_link_libraries(zig_cpp LINK_PUBLIC400target_link_libraries(zigcpp LINK_PUBLIC
401 opt_c_util
402 ${SOFTFLOAT_LIBRARIES}
403 ${CLANG_LIBRARIES}401 ${CLANG_LIBRARIES}
404 ${LLD_LIBRARIES}402 ${LLD_LIBRARIES}
405 ${LLVM_LIBRARIES}403 ${LLVM_LIBRARIES}
406 ${CMAKE_THREAD_LIBS_INIT}404 ${CMAKE_THREAD_LIBS_INIT}
407)405)
408if(ZIG_WORKAROUND_POLLY_SO)406if(ZIG_WORKAROUND_POLLY_SO)
409 target_link_libraries(zig_cpp LINK_PUBLIC "-Wl,${ZIG_WORKAROUND_POLLY_SO}")407 target_link_libraries(zigcpp LINK_PUBLIC "-Wl,${ZIG_WORKAROUND_POLLY_SO}")
410endif()408endif()
411409
412add_library(opt_c_util STATIC ${OPTIMIZED_C_SOURCES})410add_library(opt_c_util STATIC ${OPTIMIZED_C_SOURCES})
...@@ -414,16 +412,26 @@ set_target_properties(opt_c_util PROPERTIES...@@ -414,16 +412,26 @@ set_target_properties(opt_c_util PROPERTIES
414 COMPILE_FLAGS "${OPTIMIZED_C_FLAGS}"412 COMPILE_FLAGS "${OPTIMIZED_C_FLAGS}"
415)413)
416414
415add_library(zigstage1 STATIC ${STAGE1_SOURCES})
416set_target_properties(zigstage1 PROPERTIES
417 COMPILE_FLAGS ${EXE_CFLAGS}
418 LINK_FLAGS ${EXE_LDFLAGS}
419)
420target_link_libraries(zigstage1 LINK_PUBLIC
421 opt_c_util
422 ${SOFTFLOAT_LIBRARIES}
423 zigcpp
424)
417if(NOT MSVC)425if(NOT MSVC)
418 target_link_libraries(zig_cpp LINK_PUBLIC ${LIBXML2})426 target_link_libraries(zigstage1 LINK_PUBLIC ${LIBXML2})
419endif()427endif()
420428
421if(ZIG_DIA_GUIDS_LIB)429if(ZIG_DIA_GUIDS_LIB)
422 target_link_libraries(zig_cpp LINK_PUBLIC ${ZIG_DIA_GUIDS_LIB})430 target_link_libraries(zigstage1 LINK_PUBLIC ${ZIG_DIA_GUIDS_LIB})
423endif()431endif()
424432
425if(MSVC OR MINGW)433if(MSVC OR MINGW)
426 target_link_libraries(zig_cpp LINK_PUBLIC version)434 target_link_libraries(zigstage1 LINK_PUBLIC version)
427endif()435endif()
428436
429add_executable(zig0 ${ZIG0_SOURCES})437add_executable(zig0 ${ZIG0_SOURCES})
...@@ -431,7 +439,7 @@ set_target_properties(zig0 PROPERTIES...@@ -431,7 +439,7 @@ set_target_properties(zig0 PROPERTIES
431 COMPILE_FLAGS ${EXE_CFLAGS}439 COMPILE_FLAGS ${EXE_CFLAGS}
432 LINK_FLAGS ${EXE_LDFLAGS}440 LINK_FLAGS ${EXE_LDFLAGS}
433)441)
434target_link_libraries(zig0 zig_cpp)442target_link_libraries(zig0 zigstage1)
435443
436if(MSVC)444if(MSVC)
437 set(ZIG1_OBJECT "${CMAKE_BINARY_DIR}/zig1.obj")445 set(ZIG1_OBJECT "${CMAKE_BINARY_DIR}/zig1.obj")
...@@ -487,7 +495,7 @@ set_target_properties(zig PROPERTIES...@@ -487,7 +495,7 @@ set_target_properties(zig PROPERTIES
487 COMPILE_FLAGS ${EXE_CFLAGS}495 COMPILE_FLAGS ${EXE_CFLAGS}
488 LINK_FLAGS ${EXE_LDFLAGS}496 LINK_FLAGS ${EXE_LDFLAGS}
489)497)
490target_link_libraries(zig "${ZIG1_OBJECT}" zig_cpp)498target_link_libraries(zig "${ZIG1_OBJECT}" zigstage1)
491if(MSVC)499if(MSVC)
492 target_link_libraries(zig ntdll.lib)500 target_link_libraries(zig ntdll.lib)
493elseif(MINGW)501elseif(MINGW)
build.zig+2-2
...@@ -270,7 +270,7 @@ fn fileExists(filename: []const u8) !bool {...@@ -270,7 +270,7 @@ fn fileExists(filename: []const u8) !bool {
270fn addCppLib(b: *Builder, lib_exe_obj: anytype, cmake_binary_dir: []const u8, lib_name: []const u8) void {270fn addCppLib(b: *Builder, lib_exe_obj: anytype, cmake_binary_dir: []const u8, lib_name: []const u8) void {
271 lib_exe_obj.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{271 lib_exe_obj.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{
272 cmake_binary_dir,272 cmake_binary_dir,
273 "zig_cpp",273 "zigcpp",
274 b.fmt("{}{}{}", .{ lib_exe_obj.target.libPrefix(), lib_name, lib_exe_obj.target.staticLibSuffix() }),274 b.fmt("{}{}{}", .{ lib_exe_obj.target.libPrefix(), lib_name, lib_exe_obj.target.staticLibSuffix() }),
275 }) catch unreachable);275 }) catch unreachable);
276}276}
...@@ -352,7 +352,7 @@ fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {...@@ -352,7 +352,7 @@ fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
352fn configureStage2(b: *Builder, exe: anytype, ctx: Context, need_cpp_includes: bool) !void {352fn configureStage2(b: *Builder, exe: anytype, ctx: Context, need_cpp_includes: bool) !void {
353 exe.addIncludeDir("src");353 exe.addIncludeDir("src");
354 exe.addIncludeDir(ctx.cmake_binary_dir);354 exe.addIncludeDir(ctx.cmake_binary_dir);
355 addCppLib(b, exe, ctx.cmake_binary_dir, "zig_cpp");355 addCppLib(b, exe, ctx.cmake_binary_dir, "zigcpp");
356 assert(ctx.lld_include_dir.len != 0);356 assert(ctx.lld_include_dir.len != 0);
357 exe.addIncludeDir(ctx.lld_include_dir);357 exe.addIncludeDir(ctx.lld_include_dir);
358 {358 {
lib/std/build/translate_c.zig+1-2
...@@ -72,8 +72,7 @@ pub const TranslateCStep = struct {...@@ -72,8 +72,7 @@ pub const TranslateCStep = struct {
72 try argv_list.append("translate-c");72 try argv_list.append("translate-c");
73 try argv_list.append("-lc");73 try argv_list.append("-lc");
7474
75 try argv_list.append("--cache");75 try argv_list.append("--enable-cache");
76 try argv_list.append("on");
7776
78 if (!self.target.isNative()) {77 if (!self.target.isNative()) {
79 try argv_list.append("-target");78 try argv_list.append("-target");
src/zig_clang.cpp+6-5
...@@ -13,7 +13,6 @@...@@ -13,7 +13,6 @@
13 * 3. Prevent C++ from infecting the rest of the project.13 * 3. Prevent C++ from infecting the rest of the project.
14 */14 */
15#include "zig_clang.h"15#include "zig_clang.h"
16#include "list.hpp"
1716
18#if __GNUC__ >= 817#if __GNUC__ >= 8
19#pragma GCC diagnostic push18#pragma GCC diagnostic push
...@@ -2186,7 +2185,7 @@ ZigClangASTUnit *ZigClangLoadFromCommandLine(const char **args_begin, const char...@@ -2186,7 +2185,7 @@ ZigClangASTUnit *ZigClangLoadFromCommandLine(const char **args_begin, const char
2186 // Take ownership of the err_unit ASTUnit object so that it won't be2185 // Take ownership of the err_unit ASTUnit object so that it won't be
2187 // free'd when we return, invalidating the error message pointers2186 // free'd when we return, invalidating the error message pointers
2188 clang::ASTUnit *unit = ast_unit ? ast_unit : err_unit.release();2187 clang::ASTUnit *unit = ast_unit ? ast_unit : err_unit.release();
2189 ZigList<Stage2ErrorMsg> errors = {};2188 Stage2ErrorMsg *errors = nullptr;
21902189
2191 for (clang::ASTUnit::stored_diag_iterator it = unit->stored_diag_begin(),2190 for (clang::ASTUnit::stored_diag_iterator it = unit->stored_diag_begin(),
2192 it_end = unit->stored_diag_end(); it != it_end; ++it)2191 it_end = unit->stored_diag_end(); it != it_end; ++it)
...@@ -2204,7 +2203,10 @@ ZigClangASTUnit *ZigClangLoadFromCommandLine(const char **args_begin, const char...@@ -2204,7 +2203,10 @@ ZigClangASTUnit *ZigClangLoadFromCommandLine(const char **args_begin, const char
22042203
2205 llvm::StringRef msg_str_ref = it->getMessage();2204 llvm::StringRef msg_str_ref = it->getMessage();
22062205
2207 Stage2ErrorMsg *msg = errors.add_one();2206 *errors_len += 1;
2207 errors = reinterpret_cast<Stage2ErrorMsg*>(realloc(errors, sizeof(Stage2ErrorMsg) * *errors_len));
2208 if (errors == nullptr) abort();
2209 Stage2ErrorMsg *msg = &errors[*errors_len - 1];
2208 memset(msg, 0, sizeof(*msg));2210 memset(msg, 0, sizeof(*msg));
22092211
2210 msg->msg_ptr = (const char *)msg_str_ref.bytes_begin();2212 msg->msg_ptr = (const char *)msg_str_ref.bytes_begin();
...@@ -2242,8 +2244,7 @@ ZigClangASTUnit *ZigClangLoadFromCommandLine(const char **args_begin, const char...@@ -2242,8 +2244,7 @@ ZigClangASTUnit *ZigClangLoadFromCommandLine(const char **args_begin, const char
2242 }2244 }
2243 }2245 }
22442246
2245 *errors_ptr = errors.items;2247 *errors_ptr = errors;
2246 *errors_len = errors.length;
22472248
2248 return nullptr;2249 return nullptr;
2249 }2250 }