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 * --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
17 * 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
38 * repair @cImport
49 * make sure zig cc works
510 - using it as a preprocessor (-E)
......@@ -13,23 +18,17 @@
1318 * -fno-emit-asm (default) do not output .s (assembly code)\n"
1419 * -femit-llvm-ir produce a .ll file with LLVM IR\n"
1520 * -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
1921 * mingw-w64
2022 * MachO LLD linking
2123 * COFF LLD linking
2224 * WASM LLD linking
23 * --main-pkg-path
2425 * skip LLD caching when bin directory is not in the cache (so we don't put `id.txt` into the cwd)
2526 (maybe make it an explicit option and have main.zig disable it)
2627 * audit the CLI options for stage2
2728 * audit the base cache hash
28 * implement proper parsing of LLD stderr/stdout and exposing compile errors
2929 * implement proper parsing of clang stderr/stdout and exposing compile errors
3030 * On operating systems that support it, do an execve for `zig test` and `zig run` rather than child process.
3131 * restore error messages for stage2_add_link_lib
32 * update std/build.zig to use new CLI
3332
3433 * support cross compiling stage2 with `zig build`
3534 * 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)
8989 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")
9090endif()
9191
92set(ZIG_CPP_LIB_DIR "${CMAKE_BINARY_DIR}/zig_cpp")
92set(ZIG_CPP_LIB_DIR "${CMAKE_BINARY_DIR}/zigcpp")
9393
9494# Handle multi-config builds and place each into a common lib. The VS generator
9595# for example will append a Debug folder by default if not explicitly specified.
......@@ -260,7 +260,7 @@ set(ZIG0_SOURCES
260260 "${CMAKE_SOURCE_DIR}/src/stage1/zig0.cpp"
261261)
262262
263set(ZIG_SOURCES
263set(STAGE1_SOURCES
264264 "${CMAKE_SOURCE_DIR}/src/stage1/analyze.cpp"
265265 "${CMAKE_SOURCE_DIR}/src/stage1/ast_render.cpp"
266266 "${CMAKE_SOURCE_DIR}/src/stage1/bigfloat.cpp"
......@@ -392,21 +392,19 @@ if(ZIG_TEST_COVERAGE)
392392 set(EXE_LDFLAGS "${EXE_LDFLAGS} -fprofile-arcs -ftest-coverage")
393393endif()
394394
395add_library(zig_cpp STATIC ${ZIG_SOURCES} ${ZIG_CPP_SOURCES})
396set_target_properties(zig_cpp PROPERTIES
395add_library(zigcpp STATIC ${ZIG_CPP_SOURCES})
396set_target_properties(zigcpp PROPERTIES
397397 COMPILE_FLAGS ${EXE_CFLAGS}
398398)
399399
400target_link_libraries(zig_cpp LINK_PUBLIC
401 opt_c_util
402 ${SOFTFLOAT_LIBRARIES}
400target_link_libraries(zigcpp LINK_PUBLIC
403401 ${CLANG_LIBRARIES}
404402 ${LLD_LIBRARIES}
405403 ${LLVM_LIBRARIES}
406404 ${CMAKE_THREAD_LIBS_INIT}
407405)
408406if(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}")
410408endif()
411409
412410add_library(opt_c_util STATIC ${OPTIMIZED_C_SOURCES})
......@@ -414,16 +412,26 @@ set_target_properties(opt_c_util PROPERTIES
414412 COMPILE_FLAGS "${OPTIMIZED_C_FLAGS}"
415413)
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)
417425if(NOT MSVC)
418 target_link_libraries(zig_cpp LINK_PUBLIC ${LIBXML2})
426 target_link_libraries(zigstage1 LINK_PUBLIC ${LIBXML2})
419427endif()
420428
421429if(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})
423431endif()
424432
425433if(MSVC OR MINGW)
426 target_link_libraries(zig_cpp LINK_PUBLIC version)
434 target_link_libraries(zigstage1 LINK_PUBLIC version)
427435endif()
428436
429437add_executable(zig0 ${ZIG0_SOURCES})
......@@ -431,7 +439,7 @@ set_target_properties(zig0 PROPERTIES
431439 COMPILE_FLAGS ${EXE_CFLAGS}
432440 LINK_FLAGS ${EXE_LDFLAGS}
433441)
434target_link_libraries(zig0 zig_cpp)
442target_link_libraries(zig0 zigstage1)
435443
436444if(MSVC)
437445 set(ZIG1_OBJECT "${CMAKE_BINARY_DIR}/zig1.obj")
......@@ -487,7 +495,7 @@ set_target_properties(zig PROPERTIES
487495 COMPILE_FLAGS ${EXE_CFLAGS}
488496 LINK_FLAGS ${EXE_LDFLAGS}
489497)
490target_link_libraries(zig "${ZIG1_OBJECT}" zig_cpp)
498target_link_libraries(zig "${ZIG1_OBJECT}" zigstage1)
491499if(MSVC)
492500 target_link_libraries(zig ntdll.lib)
493501elseif(MINGW)
build.zig+2-2
......@@ -270,7 +270,7 @@ fn fileExists(filename: []const u8) !bool {
270270fn addCppLib(b: *Builder, lib_exe_obj: anytype, cmake_binary_dir: []const u8, lib_name: []const u8) void {
271271 lib_exe_obj.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{
272272 cmake_binary_dir,
273 "zig_cpp",
273 "zigcpp",
274274 b.fmt("{}{}{}", .{ lib_exe_obj.target.libPrefix(), lib_name, lib_exe_obj.target.staticLibSuffix() }),
275275 }) catch unreachable);
276276}
......@@ -352,7 +352,7 @@ fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
352352fn configureStage2(b: *Builder, exe: anytype, ctx: Context, need_cpp_includes: bool) !void {
353353 exe.addIncludeDir("src");
354354 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");
356356 assert(ctx.lld_include_dir.len != 0);
357357 exe.addIncludeDir(ctx.lld_include_dir);
358358 {
lib/std/build/translate_c.zig+1-2
......@@ -72,8 +72,7 @@ pub const TranslateCStep = struct {
7272 try argv_list.append("translate-c");
7373 try argv_list.append("-lc");
7474
75 try argv_list.append("--cache");
76 try argv_list.append("on");
75 try argv_list.append("--enable-cache");
7776
7877 if (!self.target.isNative()) {
7978 try argv_list.append("-target");
src/zig_clang.cpp+6-5
......@@ -13,7 +13,6 @@
1313 * 3. Prevent C++ from infecting the rest of the project.
1414 */
1515#include "zig_clang.h"
16#include "list.hpp"
1716
1817#if __GNUC__ >= 8
1918#pragma GCC diagnostic push
......@@ -2186,7 +2185,7 @@ ZigClangASTUnit *ZigClangLoadFromCommandLine(const char **args_begin, const char
21862185 // Take ownership of the err_unit ASTUnit object so that it won't be
21872186 // free'd when we return, invalidating the error message pointers
21882187 clang::ASTUnit *unit = ast_unit ? ast_unit : err_unit.release();
2189 ZigList<Stage2ErrorMsg> errors = {};
2188 Stage2ErrorMsg *errors = nullptr;
21902189
21912190 for (clang::ASTUnit::stored_diag_iterator it = unit->stored_diag_begin(),
21922191 it_end = unit->stored_diag_end(); it != it_end; ++it)
......@@ -2204,7 +2203,10 @@ ZigClangASTUnit *ZigClangLoadFromCommandLine(const char **args_begin, const char
22042203
22052204 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];
22082210 memset(msg, 0, sizeof(*msg));
22092211
22102212 msg->msg_ptr = (const char *)msg_str_ref.bytes_begin();
......@@ -2242,8 +2244,7 @@ ZigClangASTUnit *ZigClangLoadFromCommandLine(const char **args_begin, const char
22422244 }
22432245 }
22442246
2245 *errors_ptr = errors.items;
2246 *errors_len = errors.length;
2247 *errors_ptr = errors;
22472248
22482249 return nullptr;
22492250 }