| author | |
| committer | |
| log | 800a4a6cebf363c8ba3d1fcfff55db8bfb71f731 |
| tree | 566a2b9995048fb457bda97db04f8d5d5c5d50be |
| parent | fc88d36daea40b69690186730ae7f2a5296585a9 |
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 @cImport | 8 | * repair @cImport |
| 4 | * make sure zig cc works | 9 | * 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-w64 | 21 | * mingw-w64 |
| 20 | * MachO LLD linking | 22 | * MachO LLD linking |
| 21 | * COFF LLD linking | 23 | * COFF LLD linking |
| 22 | * WASM LLD linking | 24 | * 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 stage2 | 27 | * audit the CLI options for stage2 |
| 27 | * audit the base cache hash | 28 | * 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 errors | 29 | * 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_lib | 31 | * restore error messages for stage2_add_link_lib |
| 32 | * update std/build.zig to use new CLI | ||
| 33 | 32 | ||
| 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 libs | 34 | * 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") |
| 90 | endif() | 90 | endif() |
| 91 | 91 | ||
| 92 | set(ZIG_CPP_LIB_DIR "${CMAKE_BINARY_DIR}/zig_cpp") | 92 | set(ZIG_CPP_LIB_DIR "${CMAKE_BINARY_DIR}/zigcpp") |
| 93 | 93 | ||
| 94 | # Handle multi-config builds and place each into a common lib. The VS generator | 94 | # 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 | ) |
| 262 | 262 | ||
| 263 | set(ZIG_SOURCES | 263 | set(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") |
| 393 | endif() | 393 | endif() |
| 394 | 394 | ||
| 395 | add_library(zig_cpp STATIC ${ZIG_SOURCES} ${ZIG_CPP_SOURCES}) | 395 | add_library(zigcpp STATIC ${ZIG_CPP_SOURCES}) |
| 396 | set_target_properties(zig_cpp PROPERTIES | 396 | set_target_properties(zigcpp PROPERTIES |
| 397 | COMPILE_FLAGS ${EXE_CFLAGS} | 397 | COMPILE_FLAGS ${EXE_CFLAGS} |
| 398 | ) | 398 | ) |
| 399 | 399 | ||
| 400 | target_link_libraries(zig_cpp LINK_PUBLIC | 400 | target_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 | ) |
| 408 | if(ZIG_WORKAROUND_POLLY_SO) | 406 | if(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}") |
| 410 | endif() | 408 | endif() |
| 411 | 409 | ||
| 412 | add_library(opt_c_util STATIC ${OPTIMIZED_C_SOURCES}) | 410 | add_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 | ) |
| 416 | 414 | ||
| 415 | add_library(zigstage1 STATIC ${STAGE1_SOURCES}) | ||
| 416 | set_target_properties(zigstage1 PROPERTIES | ||
| 417 | COMPILE_FLAGS ${EXE_CFLAGS} | ||
| 418 | LINK_FLAGS ${EXE_LDFLAGS} | ||
| 419 | ) | ||
| 420 | target_link_libraries(zigstage1 LINK_PUBLIC | ||
| 421 | opt_c_util | ||
| 422 | ${SOFTFLOAT_LIBRARIES} | ||
| 423 | zigcpp | ||
| 424 | ) | ||
| 417 | if(NOT MSVC) | 425 | if(NOT MSVC) |
| 418 | target_link_libraries(zig_cpp LINK_PUBLIC ${LIBXML2}) | 426 | target_link_libraries(zigstage1 LINK_PUBLIC ${LIBXML2}) |
| 419 | endif() | 427 | endif() |
| 420 | 428 | ||
| 421 | if(ZIG_DIA_GUIDS_LIB) | 429 | if(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}) |
| 423 | endif() | 431 | endif() |
| 424 | 432 | ||
| 425 | if(MSVC OR MINGW) | 433 | if(MSVC OR MINGW) |
| 426 | target_link_libraries(zig_cpp LINK_PUBLIC version) | 434 | target_link_libraries(zigstage1 LINK_PUBLIC version) |
| 427 | endif() | 435 | endif() |
| 428 | 436 | ||
| 429 | add_executable(zig0 ${ZIG0_SOURCES}) | 437 | add_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 | ) |
| 434 | target_link_libraries(zig0 zig_cpp) | 442 | target_link_libraries(zig0 zigstage1) |
| 435 | 443 | ||
| 436 | if(MSVC) | 444 | if(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 | ) |
| 490 | target_link_libraries(zig "${ZIG1_OBJECT}" zig_cpp) | 498 | target_link_libraries(zig "${ZIG1_OBJECT}" zigstage1) |
| 491 | if(MSVC) | 499 | if(MSVC) |
| 492 | target_link_libraries(zig ntdll.lib) | 500 | target_link_libraries(zig ntdll.lib) |
| 493 | elseif(MINGW) | 501 | elseif(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 { |
| 270 | fn addCppLib(b: *Builder, lib_exe_obj: anytype, cmake_binary_dir: []const u8, lib_name: []const u8) void { | 270 | fn 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 { |
| 352 | fn configureStage2(b: *Builder, exe: anytype, ctx: Context, need_cpp_includes: bool) !void { | 352 | fn 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"); |
| 74 | 74 | ||
| 75 | try argv_list.append("--cache"); | 75 | try argv_list.append("--enable-cache"); |
| 76 | try argv_list.append("on"); | ||
| 77 | 76 | ||
| 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" | ||
| 17 | 16 | ||
| 18 | #if __GNUC__ >= 8 | 17 | #if __GNUC__ >= 8 |
| 19 | #pragma GCC diagnostic push | 18 | #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 be | 2185 | // Take ownership of the err_unit ASTUnit object so that it won't be |
| 2187 | // free'd when we return, invalidating the error message pointers | 2186 | // 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; |
| 2190 | 2189 | ||
| 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 |
| 2204 | 2203 | ||
| 2205 | llvm::StringRef msg_str_ref = it->getMessage(); | 2204 | llvm::StringRef msg_str_ref = it->getMessage(); |
| 2206 | 2205 | ||
| 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)); |
| 2209 | 2211 | ||
| 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 | } |
| 2244 | 2246 | ||
| 2245 | *errors_ptr = errors.items; | 2247 | *errors_ptr = errors; |
| 2246 | *errors_len = errors.length; | ||
| 2247 | 2248 | ||
| 2248 | return nullptr; | 2249 | return nullptr; |
| 2249 | } | 2250 | } |