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.
master
Andrew Kelley 2020-09-23 00:00:24 -07:00
parent fc88d36dae
commit 800a4a6ceb
5 changed files with 36 additions and 29 deletions

View File

@ -1,5 +1,10 @@
* --main-pkg-path
* add CLI support for a way to pass extra flags to c source files
* musl
* support rpaths in ELF linker code
* implement proper parsing of LLD stderr/stdout and exposing compile errors
* tests passing with -Dskip-non-native
* windows CUSTOMBUILD : error : unable to build compiler_rt: FileNotFound [D:\a\1\s\build\zig_install_lib_files.vcxproj]
* separate libzigcpp.a and libzigstage1.a so that we can do non-stage1 builds
* repair @cImport
* make sure zig cc works
- using it as a preprocessor (-E)
@ -13,23 +18,17 @@
* -fno-emit-asm (default) do not output .s (assembly code)\n"
* -femit-llvm-ir produce a .ll file with LLVM IR\n"
* -fno-emit-llvm-ir (default) do not produce a .ll file with LLVM IR\n"
* support rpaths in ELF linker code
* add CLI support for a way to pass extra flags to c source files
* musl
* mingw-w64
* MachO LLD linking
* COFF LLD linking
* WASM LLD linking
* --main-pkg-path
* skip LLD caching when bin directory is not in the cache (so we don't put `id.txt` into the cwd)
(maybe make it an explicit option and have main.zig disable it)
* audit the CLI options for stage2
* audit the base cache hash
* implement proper parsing of LLD stderr/stdout and exposing compile errors
* implement proper parsing of clang stderr/stdout and exposing compile errors
* On operating systems that support it, do an execve for `zig test` and `zig run` rather than child process.
* restore error messages for stage2_add_link_lib
* update std/build.zig to use new CLI
* support cross compiling stage2 with `zig build`
* implement proper compile errors for failing to build glibc crt files and shared libs

View File

@ -89,7 +89,7 @@ if(APPLE AND ZIG_WORKAROUND_4799)
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")
endif()
set(ZIG_CPP_LIB_DIR "${CMAKE_BINARY_DIR}/zig_cpp")
set(ZIG_CPP_LIB_DIR "${CMAKE_BINARY_DIR}/zigcpp")
# Handle multi-config builds and place each into a common lib. The VS generator
# for example will append a Debug folder by default if not explicitly specified.
@ -260,7 +260,7 @@ set(ZIG0_SOURCES
"${CMAKE_SOURCE_DIR}/src/stage1/zig0.cpp"
)
set(ZIG_SOURCES
set(STAGE1_SOURCES
"${CMAKE_SOURCE_DIR}/src/stage1/analyze.cpp"
"${CMAKE_SOURCE_DIR}/src/stage1/ast_render.cpp"
"${CMAKE_SOURCE_DIR}/src/stage1/bigfloat.cpp"
@ -392,21 +392,19 @@ if(ZIG_TEST_COVERAGE)
set(EXE_LDFLAGS "${EXE_LDFLAGS} -fprofile-arcs -ftest-coverage")
endif()
add_library(zig_cpp STATIC ${ZIG_SOURCES} ${ZIG_CPP_SOURCES})
set_target_properties(zig_cpp PROPERTIES
add_library(zigcpp STATIC ${ZIG_CPP_SOURCES})
set_target_properties(zigcpp PROPERTIES
COMPILE_FLAGS ${EXE_CFLAGS}
)
target_link_libraries(zig_cpp LINK_PUBLIC
opt_c_util
${SOFTFLOAT_LIBRARIES}
target_link_libraries(zigcpp LINK_PUBLIC
${CLANG_LIBRARIES}
${LLD_LIBRARIES}
${LLVM_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
if(ZIG_WORKAROUND_POLLY_SO)
target_link_libraries(zig_cpp LINK_PUBLIC "-Wl,${ZIG_WORKAROUND_POLLY_SO}")
target_link_libraries(zigcpp LINK_PUBLIC "-Wl,${ZIG_WORKAROUND_POLLY_SO}")
endif()
add_library(opt_c_util STATIC ${OPTIMIZED_C_SOURCES})
@ -414,16 +412,26 @@ set_target_properties(opt_c_util PROPERTIES
COMPILE_FLAGS "${OPTIMIZED_C_FLAGS}"
)
add_library(zigstage1 STATIC ${STAGE1_SOURCES})
set_target_properties(zigstage1 PROPERTIES
COMPILE_FLAGS ${EXE_CFLAGS}
LINK_FLAGS ${EXE_LDFLAGS}
)
target_link_libraries(zigstage1 LINK_PUBLIC
opt_c_util
${SOFTFLOAT_LIBRARIES}
zigcpp
)
if(NOT MSVC)
target_link_libraries(zig_cpp LINK_PUBLIC ${LIBXML2})
target_link_libraries(zigstage1 LINK_PUBLIC ${LIBXML2})
endif()
if(ZIG_DIA_GUIDS_LIB)
target_link_libraries(zig_cpp LINK_PUBLIC ${ZIG_DIA_GUIDS_LIB})
target_link_libraries(zigstage1 LINK_PUBLIC ${ZIG_DIA_GUIDS_LIB})
endif()
if(MSVC OR MINGW)
target_link_libraries(zig_cpp LINK_PUBLIC version)
target_link_libraries(zigstage1 LINK_PUBLIC version)
endif()
add_executable(zig0 ${ZIG0_SOURCES})
@ -431,7 +439,7 @@ set_target_properties(zig0 PROPERTIES
COMPILE_FLAGS ${EXE_CFLAGS}
LINK_FLAGS ${EXE_LDFLAGS}
)
target_link_libraries(zig0 zig_cpp)
target_link_libraries(zig0 zigstage1)
if(MSVC)
set(ZIG1_OBJECT "${CMAKE_BINARY_DIR}/zig1.obj")
@ -487,7 +495,7 @@ set_target_properties(zig PROPERTIES
COMPILE_FLAGS ${EXE_CFLAGS}
LINK_FLAGS ${EXE_LDFLAGS}
)
target_link_libraries(zig "${ZIG1_OBJECT}" zig_cpp)
target_link_libraries(zig "${ZIG1_OBJECT}" zigstage1)
if(MSVC)
target_link_libraries(zig ntdll.lib)
elseif(MINGW)

View File

@ -270,7 +270,7 @@ fn fileExists(filename: []const u8) !bool {
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,
"zig_cpp",
"zigcpp",
b.fmt("{}{}{}", .{ lib_exe_obj.target.libPrefix(), lib_name, lib_exe_obj.target.staticLibSuffix() }),
}) catch unreachable);
}
@ -352,7 +352,7 @@ fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
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, "zig_cpp");
addCppLib(b, exe, ctx.cmake_binary_dir, "zigcpp");
assert(ctx.lld_include_dir.len != 0);
exe.addIncludeDir(ctx.lld_include_dir);
{

View File

@ -72,8 +72,7 @@ pub const TranslateCStep = struct {
try argv_list.append("translate-c");
try argv_list.append("-lc");
try argv_list.append("--cache");
try argv_list.append("on");
try argv_list.append("--enable-cache");
if (!self.target.isNative()) {
try argv_list.append("-target");

View File

@ -13,7 +13,6 @@
* 3. Prevent C++ from infecting the rest of the project.
*/
#include "zig_clang.h"
#include "list.hpp"
#if __GNUC__ >= 8
#pragma GCC diagnostic push
@ -2186,7 +2185,7 @@ ZigClangASTUnit *ZigClangLoadFromCommandLine(const char **args_begin, const char
// Take ownership of the err_unit ASTUnit object so that it won't be
// free'd when we return, invalidating the error message pointers
clang::ASTUnit *unit = ast_unit ? ast_unit : err_unit.release();
ZigList<Stage2ErrorMsg> errors = {};
Stage2ErrorMsg *errors = nullptr;
for (clang::ASTUnit::stored_diag_iterator it = unit->stored_diag_begin(),
it_end = unit->stored_diag_end(); it != it_end; ++it)
@ -2204,7 +2203,10 @@ ZigClangASTUnit *ZigClangLoadFromCommandLine(const char **args_begin, const char
llvm::StringRef msg_str_ref = it->getMessage();
Stage2ErrorMsg *msg = errors.add_one();
*errors_len += 1;
errors = reinterpret_cast<Stage2ErrorMsg*>(realloc(errors, sizeof(Stage2ErrorMsg) * *errors_len));
if (errors == nullptr) abort();
Stage2ErrorMsg *msg = &errors[*errors_len - 1];
memset(msg, 0, sizeof(*msg));
msg->msg_ptr = (const char *)msg_str_ref.bytes_begin();
@ -2242,8 +2244,7 @@ ZigClangASTUnit *ZigClangLoadFromCommandLine(const char **args_begin, const char
}
}
*errors_ptr = errors.items;
*errors_len = errors.length;
*errors_ptr = errors;
return nullptr;
}