diff --git a/CMakeLists.txt b/CMakeLists.txt index 08c2cf4761..1c9f374d29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -570,6 +570,14 @@ set(ZIG_C_HEADER_FILES "xtestintrin.h" ) +if(MSVC) + set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK") + if (IS_DIRECTORY ${MSVC_DIA_SDK_DIR}) + set(ZIG_DIA_GUIDS_LIB "${MSVC_DIA_SDK_DIR}/lib/amd64/diaguids.lib") + string(REGEX REPLACE "\\\\" "\\\\\\\\" ZIG_DIA_GUIDS_LIB_ESCAPED "${ZIG_DIA_GUIDS_LIB}") + endif() +endif() + set(ZIG_LIB_DIR "lib/zig") set(C_HEADERS_DEST "${ZIG_LIB_DIR}/include") set(ZIG_STD_DEST "${ZIG_LIB_DIR}/std") @@ -631,6 +639,10 @@ target_link_libraries(zig LINK_PUBLIC ${LLVM_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ) +if(ZIG_DIA_GUIDS_LIB) + target_link_libraries(zig LINK_PUBLIC ${ZIG_DIA_GUIDS_LIB}) +endif() + if(MSVC OR MINGW) target_link_libraries(zig LINK_PUBLIC version) endif() diff --git a/README.md b/README.md index afe680e5fe..87b737e580 100644 --- a/README.md +++ b/README.md @@ -154,8 +154,7 @@ make install `ZIG_LIBC_LIB_DIR` and `ZIG_LIBC_STATIC_LIB_DIR` are unused. ``` -brew install cmake -brew install llvm@6 +brew install cmake llvm@6 brew outdated llvm@6 || brew upgrade llvm@6 mkdir build cd build diff --git a/build.zig b/build.zig index 679c88bb71..9f66cf8728 100644 --- a/build.zig +++ b/build.zig @@ -35,55 +35,67 @@ pub fn build(b: &Builder) { const test_step = b.step("test", "Run all the tests"); - if (findLLVM(b)) |llvm| { - // find the stage0 build artifacts because we're going to re-use config.h and zig_cpp library - const build_info = b.exec([][]const u8{b.zig_exe, "BUILD_INFO"}); - var index: usize = 0; - const cmake_binary_dir = nextValue(&index, build_info); - const cxx_compiler = nextValue(&index, build_info); - const lld_include_dir = nextValue(&index, build_info); - const lld_libraries = nextValue(&index, build_info); - const std_files = nextValue(&index, build_info); - const c_header_files = nextValue(&index, build_info); + // find the stage0 build artifacts because we're going to re-use config.h and zig_cpp library + const build_info = b.exec([][]const u8{b.zig_exe, "BUILD_INFO"}); + var index: usize = 0; + const cmake_binary_dir = nextValue(&index, build_info); + const cxx_compiler = nextValue(&index, build_info); + const llvm_config_exe = nextValue(&index, build_info); + const lld_include_dir = nextValue(&index, build_info); + const lld_libraries = nextValue(&index, build_info); + const std_files = nextValue(&index, build_info); + const c_header_files = nextValue(&index, build_info); + const dia_guids_lib = nextValue(&index, build_info); - var exe = b.addExecutable("zig", "src-self-hosted/main.zig"); - exe.setBuildMode(mode); - exe.addIncludeDir("src"); - exe.addIncludeDir(cmake_binary_dir); - addCppLib(b, exe, cmake_binary_dir, "zig_cpp"); - if (lld_include_dir.len != 0) { - exe.addIncludeDir(lld_include_dir); - var it = mem.split(lld_libraries, ";"); - while (it.next()) |lib| { - exe.addObjectFile(lib); - } - } else { - addCppLib(b, exe, cmake_binary_dir, "embedded_lld_elf"); - addCppLib(b, exe, cmake_binary_dir, "embedded_lld_coff"); - addCppLib(b, exe, cmake_binary_dir, "embedded_lld_lib"); + const llvm = findLLVM(b, llvm_config_exe); + + var exe = b.addExecutable("zig", "src-self-hosted/main.zig"); + exe.setBuildMode(mode); + exe.addIncludeDir("src"); + exe.addIncludeDir(cmake_binary_dir); + addCppLib(b, exe, cmake_binary_dir, "zig_cpp"); + if (lld_include_dir.len != 0) { + exe.addIncludeDir(lld_include_dir); + var it = mem.split(lld_libraries, ";"); + while (it.next()) |lib| { + exe.addObjectFile(lib); } - dependOnLib(exe, llvm); + } else { + addCppLib(b, exe, cmake_binary_dir, "embedded_lld_elf"); + addCppLib(b, exe, cmake_binary_dir, "embedded_lld_coff"); + addCppLib(b, exe, cmake_binary_dir, "embedded_lld_lib"); + } + dependOnLib(exe, llvm); - if (!exe.target.isWindows()) { - const libstdcxx_path_padded = b.exec([][]const u8{cxx_compiler, "-print-file-name=libstdc++.a"}); - const libstdcxx_path = ??mem.split(libstdcxx_path_padded, "\r\n").next(); - exe.addObjectFile(libstdcxx_path); - - exe.linkSystemLibrary("pthread"); - } - - exe.linkSystemLibrary("c"); - - b.default_step.dependOn(&exe.step); - b.default_step.dependOn(docs_step); - test_step.dependOn(&exe.step); - - b.installArtifact(exe); - installStdLib(b, std_files); - installCHeaders(b, c_header_files); + if (exe.target.getOs() == builtin.Os.linux) { + const libstdcxx_path_padded = b.exec([][]const u8{cxx_compiler, "-print-file-name=libstdc++.a"}); + const libstdcxx_path = ??mem.split(libstdcxx_path_padded, "\r\n").next(); + exe.addObjectFile(libstdcxx_path); + exe.linkSystemLibrary("pthread"); + } else if (exe.target.isDarwin()) { + exe.linkSystemLibrary("c++"); } + if (dia_guids_lib.len != 0) { + exe.addObjectFile(dia_guids_lib); + } + + exe.linkSystemLibrary("c"); + + b.default_step.dependOn(&exe.step); + b.default_step.dependOn(docs_step); + + const skip_self_hosted = b.option(bool, "skip-self-hosted", "Main test suite skips building self hosted compiler") ?? false; + if (!skip_self_hosted) { + test_step.dependOn(&exe.step); + } + const verbose_link_exe = b.option(bool, "verbose-link", "Print link command for self hosted compiler") ?? false; + exe.setVerboseLink(verbose_link_exe); + + b.installArtifact(exe); + installStdLib(b, std_files); + installCHeaders(b, c_header_files); const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter"); const with_lldb = b.option(bool, "with-lldb", "Run tests in LLDB to get a backtrace if one fails") ?? false; @@ -142,20 +154,7 @@ const LibraryDep = struct { includes: ArrayList([]const u8), }; -fn findLLVM(b: &Builder) -> ?LibraryDep { - const llvm_config_exe = b.findProgram( - [][]const u8{"llvm-config-5.0", "llvm-config"}, - [][]const u8{ - "C:/Libraries/llvm-5.0.0/bin", - "/c/msys64/mingw64/bin", - "c:/msys64/mingw64/bin", - "/usr/local/opt/llvm@5/bin", - "/mingw64/bin", - }) %% |err| - { - warn("unable to find llvm-config: {}\n", err); - return null; - }; +fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> LibraryDep { const libs_output = b.exec([][]const u8{llvm_config_exe, "--libs", "--system-libs"}); const includes_output = b.exec([][]const u8{llvm_config_exe, "--includedir"}); const libdir_output = b.exec([][]const u8{llvm_config_exe, "--libdir"}); @@ -223,8 +222,19 @@ pub fn installCHeaders(b: &Builder, c_header_files: []const u8) { fn nextValue(index: &usize, build_info: []const u8) -> []const u8 { const start = *index; - while (build_info[*index] != '\n' and build_info[*index] != '\r') : (*index += 1) { } - const result = build_info[start..*index]; - *index += 1; - return result; + while (true) : (*index += 1) { + switch (build_info[*index]) { + '\n' => { + const result = build_info[start..*index]; + *index += 1; + return result; + }, + '\r' => { + const result = build_info[start..*index]; + *index += 2; + return result; + }, + else => continue, + } + } } diff --git a/ci/appveyor/appveyor.yml b/ci/appveyor/appveyor.yml index 2009f92e43..0cae78027b 100644 --- a/ci/appveyor/appveyor.yml +++ b/ci/appveyor/appveyor.yml @@ -6,4 +6,4 @@ build_script: after_build: - '%APPVEYOR_BUILD_FOLDER%\ci\appveyor\after_build.bat' cache: - - 'llvm+clang-5.0.0-win64-msvc-release.tar.xz' + - 'llvm+clang-5.0.1-win64-msvc-release.tar.xz' diff --git a/ci/appveyor/build_script.bat b/ci/appveyor/build_script.bat index 3fa82a9b54..235b0e515e 100644 --- a/ci/appveyor/build_script.bat +++ b/ci/appveyor/build_script.bat @@ -7,7 +7,7 @@ SET "PATH=C:\msys64\mingw64\bin;C:\msys64\usr\bin;%PATH%" SET "MSYSTEM=MINGW64" SET "APPVEYOR_CACHE_ENTRY_ZIP_ARGS=-m0=Copy" -bash -lc "cd ${APPVEYOR_BUILD_FOLDER} && if [ -s ""llvm+clang-6.0.0-win64-msvc-release.tar.xz"" ]; then echo 'skipping LLVM download'; else wget 'https://s3.amazonaws.com/superjoe/temp/llvm%%2bclang-6.0.0-win64-msvc-release.tar.xz'; fi && tar xf llvm+clang-6.0.0-win64-msvc-release.tar.xz" || exit /b +bash -lc "cd ${APPVEYOR_BUILD_FOLDER} && if [ -s ""llvm+clang-6.0.0-win64-msvc-release.tar.xz"" ]; then echo 'skipping LLVM download'; else wget 'https://s3.amazonaws.com/ziglang.org/deps/llvm%%2bclang-6.0.0-win64-msvc-release.tar.xz'; fi && tar xf llvm+clang-6.0.0-win64-msvc-release.tar.xz" || exit /b SET "PATH=%PREVPATH%" @@ -15,12 +15,16 @@ SET "MSYSTEM=%PREVMSYSTEM%" SET "ZIGBUILDDIR=%APPVEYOR_BUILD_FOLDER%\build-msvc-release" SET "ZIGPREFIXPATH=%APPVEYOR_BUILD_FOLDER%\llvm+clang-6.0.0-win64-msvc-release" +call "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64 +call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64 +>>>>>>> origin/master + mkdir %ZIGBUILDDIR% cd %ZIGBUILDDIR% cmake.exe .. -Thost=x64 -G"Visual Studio 14 2015 Win64" "-DCMAKE_INSTALL_PREFIX=%ZIGBUILDDIR%" "-DCMAKE_PREFIX_PATH=%ZIGPREFIXPATH%" -DCMAKE_BUILD_TYPE=Release "-DZIG_LIBC_INCLUDE_DIR=C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt" "-DZIG_LIBC_LIB_DIR=C:\Program Files (x86)\Windows Kits\10\bin\x64\ucrt" "-DZIG_LIBC_STATIC_LIB_DIR=C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\ucrt\x64" || exit /b msbuild /p:Configuration=Release INSTALL.vcxproj || exit /b -bin\zig.exe build --build-file ..\build.zig test || exit /b +bin\zig.exe build --build-file ..\build.zig test -Dverbose-link || exit /b @echo "MSVC build succeeded, proceeding with MinGW build" cd %APPVEYOR_BUILD_FOLDER% diff --git a/ci/travis_osx_script b/ci/travis_osx_script index a55132395b..db3992aa8e 100755 --- a/ci/travis_osx_script +++ b/ci/travis_osx_script @@ -9,17 +9,4 @@ cmake .. -DCMAKE_PREFIX_PATH=/usr/local/opt/llvm@5/ -DCMAKE_INSTALL_PREFIX=$(pwd make VERBOSE=1 make install -# TODO: we run the tests separately because when run all together there is some -# mysterious issue where after N child process spawns it crashes. I've been -# unable to reproduce the issue on my macbook - it only happens on Travis. -# ./zig build --build-file ../build.zig test - -./zig build --build-file ../build.zig test-behavior --verbose -./zig build --build-file ../build.zig test-std --verbose -./zig build --build-file ../build.zig test-compiler-rt --verbose -./zig build --build-file ../build.zig test-compare-output --verbose -./zig build --build-file ../build.zig test-build-examples --verbose -./zig build --build-file ../build.zig test-compile-errors --verbose -./zig build --build-file ../build.zig test-asm-link --verbose -./zig build --build-file ../build.zig test-debug-safety --verbose -./zig build --build-file ../build.zig test-translate-c --verbose +./zig build --build-file ../build.zig test diff --git a/doc/home.html.in b/doc/home.html.in index 3b2ef3407b..dd98222aa2 100644 --- a/doc/home.html.in +++ b/doc/home.html.in @@ -50,6 +50,7 @@

Reading Material