diff --git a/script/prepare-llvm-linux.sh b/script/prepare-llvm-linux.sh index 7de25d43c3..9457049c5f 100755 --- a/script/prepare-llvm-linux.sh +++ b/script/prepare-llvm-linux.sh @@ -36,9 +36,11 @@ OPTIONS=() echo -n " -DLEAN_STANDALONE=ON" echo -n " -DCMAKE_C_COMPILER=$PWD/stage1/bin/clang -DCMAKE_CXX_COMPILER=$PWD/llvm/bin/clang++ -DLEAN_CXX_STDLIB='-Wl,-Bstatic -lc++ -lc++abi -Wl,-Bdynamic'" # allow C++ code to include /usr since it needs quite a few more headers -# set sysroot for both C++ and C to make sure we have all necessary runtime files, but don't embed in `leanc` so users can still link to system libs -echo -n " -DLEAN_EXTRA_CXX_FLAGS='--sysroot $PWD/llvm -I/usr/include -I/usr/include/x86_64-linux-gnu'" -echo -n " -DLEANC_INTERNAL_FLAGS='-I ROOT/include/clang' -DLEANC_OPTS='--sysroot $PWD/stage1' -DLEANC_CC=ROOT/bin/clang" +# set sysroot for clang to make sure we have all necessary runtime files +echo -n " -DLEAN_EXTRA_CXX_FLAGS='--sysroot $PWD/llvm -isystem /usr/include -isystem /usr/include/x86_64-linux-gnu'" +# ... but don't embed in `leanc` so users can still link to system libs, while using `-nostdinc` to make sure headers are not visible by default +# (in particular, not to `#include_next` in the clang headers) +echo -n " -DLEANC_INTERNAL_FLAGS='-nostdinc -isystem ROOT/include/clang' -DLEANC_CC=ROOT/bin/clang" echo -n " -DLEANC_INTERNAL_LINKER_FLAGS='-L ROOT/lib -L ROOT/lib/glibc ROOT/lib/glibc/libc_nonshared.a -Wl,--as-needed -static-libgcc -Wl,-Bstatic -lgmp -lunwind -Wl,-Bdynamic -fuse-ld=lld'" # do not set `LEAN_CC` for tests echo -n " -DLEAN_TEST_VARS=''" diff --git a/script/prepare-llvm-macos.sh b/script/prepare-llvm-macos.sh index 939076c600..de40caec8d 100755 --- a/script/prepare-llvm-macos.sh +++ b/script/prepare-llvm-macos.sh @@ -35,9 +35,7 @@ echo -n " -DLEAN_STANDALONE=ON" # and the custom clang++ outputs a myriad of warnings when consuming the SDK echo -n " -DCMAKE_C_COMPILER=$PWD/stage1/bin/clang" echo -n " -DGMP_LIBRARIES=lib/libgmp.a -DGMP_INCLUDE_DIR=/usr/local/opt/gmp/include" -# set sysroot for C to make sure we have all necessary runtime files, but don't embed in `leanc` so users can still link to system libs -# need no-macro-redefined for weird clang stdint.h -echo -n " -DLEANC_INTERNAL_FLAGS='-I ROOT/include/clang -Wno-macro-redefined' -DLEANC_OPTS='--sysroot $PWD/stage1' -DLEANC_CC=ROOT/bin/clang" +echo -n " -DLEANC_INTERNAL_FLAGS='-nostdinc -isystem ROOT/include/clang' -DLEANC_CC=ROOT/bin/clang" echo -n " -DLEANC_INTERNAL_LINKER_FLAGS='-L ROOT/lib -L ROOT/lib/libc -fuse-ld=lld'" # do not set `LEAN_CC` for tests echo -n " -DLEAN_TEST_VARS=''" diff --git a/script/prepare-llvm-mingw.sh b/script/prepare-llvm-mingw.sh index 899d57cd92..954c526bbe 100644 --- a/script/prepare-llvm-mingw.sh +++ b/script/prepare-llvm-mingw.sh @@ -35,11 +35,8 @@ cp /clang64/x86_64-w64-mingw32/lib/lib{m,bcrypt,mingw32,moldname,mingwex,msvcrt, echo -n " -DLEAN_STANDALONE=ON" echo -n " -DCMAKE_C_COMPILER=$PWD/stage1/bin/clang.exe -DCMAKE_CXX_COMPILER=$PWD/llvm/bin/clang++.exe -DLEAN_CXX_STDLIB='-lc++ -lc++abi'" echo -n " -DSTAGE0_CMAKE_C_COMPILER=clang -DSTAGE0_CMAKE_CXX_COMPILER=clang++" -# allow C++ code to include /usr since it needs quite a few more headers -# allow C++ code to include /usr since it needs quite a few more headers -# set sysroot for both C++ and C to make sure we have all necessary runtime files, but don't embed in `leanc` so users can still link to system libs -echo -n " -DLEAN_EXTRA_CXX_FLAGS='--sysroot $PWD/llvm -I/clang64/include/ -I/clang64/x86_64-w64-mingw32/include/'" -echo -n " -DLEANC_INTERNAL_FLAGS='-I ROOT/include/clang' -DLEANC_OPTS='--sysroot $PWD/stage1' -DLEANC_CC=ROOT/bin/clang.exe" +echo -n " -DLEAN_EXTRA_CXX_FLAGS='--sysroot $PWD/llvm -isystem /clang64/include/ -isystem /clang64/x86_64-w64-mingw32/include/'" +echo -n " -DLEANC_INTERNAL_FLAGS='-nostdinc -isystem ROOT/include/clang' -DLEANC_OPTS='--sysroot $PWD/stage1' -DLEANC_CC=ROOT/bin/clang.exe" echo -n " -DLEANC_INTERNAL_LINKER_FLAGS='-L ROOT/lib -static-libgcc -Wl,-Bstatic -lgmp -lunwind -Wl,-Bdynamic -lucrtbase -fuse-ld=lld'" # do not set `LEAN_CC` for tests echo -n " -DAUTO_THREAD_FINALIZATION=OFF -DSTAGE0_AUTO_THREAD_FINALIZATION=OFF"