Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake: Support BUILD_SHARED_LIBS for Windows too #3704

Merged
merged 18 commits into from
May 23, 2021
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
b088c33
CMake: Support BUILD_SHARED_LIBS for Windows too
kinke Apr 24, 2021
1cd829a
CMake: Link Windows druntime & Phobos DLLs against *dynamic* MSVCRT
kinke Apr 26, 2021
0980bcd
Windows: Link against dynamic MSVCRT when linking against shared drun…
kinke Apr 29, 2021
3029698
CMake: Get shared test runners to link on Windows
kinke Apr 30, 2021
1605f8d
CMake: Install shared .dll/.pdb files into bin dir
kinke May 1, 2021
35d9179
CMake: Link special rt.dso_windows module into Phobos DLL and shared …
kinke May 2, 2021
b29798d
CMake: Make sure shared Phobos test runners on Windows depend on/load…
kinke May 3, 2021
0d1baa1
CMake: Copy & install special dso_windows.obj object file to lib dir
kinke May 3, 2021
f6db2b1
Windows: Link rt.dso_windows object file automatically into each bina…
kinke May 3, 2021
2c7cd45
Windows: Default to dllexport with -shared, and enforce dllimport wit…
kinke May 3, 2021
7a6580d
CMake: Compile rt.dso_windows separately to enable binaries without a…
kinke May 3, 2021
f82564d
Azure CI: Add druntime/Phobos DLL dir to PATH to fix dmd-testsuite's …
kinke May 3, 2021
f5999aa
druntime: Fix test/shared integration test on Windows
kinke May 3, 2021
72bc5f2
CMake: Enforce .pdb generation for debug druntime/Phobos DLLs
kinke May 4, 2021
5b8dbed
Azure CI: Fix shared libs integration test for Win32
kinke May 4, 2021
8ff99d8
druntime: Fix race condition for debug/release 'shared' integration t…
kinke May 21, 2021
d0526f9
Phobos: Fix std.format.internal.write for druntime DLL
kinke May 23, 2021
8704601
Azure CI Windows: Add shared libs smoke test for multilib package
kinke May 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions .azure-pipelines/5-integration_test.yml
Original file line number Diff line number Diff line change
@@ -14,14 +14,17 @@ steps:
- bash: |
set -ex
cd ..
installed/bin/ldc2 hello.d -m64 -of=hello64 -link-defaultlib-shared
./hello64
if [ "$CI_OS" = "windows" ]; then
# Add druntime/Phobos DLL dir to PATH
export PATH="$PWD/installed/bin:$PATH"
fi
installed/bin/ldc2 hello.d -link-defaultlib-shared
./hello
if [ "$CI_OS" = "linux" ]; then
installed/bin/ldc2 hello.d -m32 -of=hello32 -link-defaultlib-shared
./hello32
installed/bin/ldc2 hello.d -m32 -link-defaultlib-shared
./hello
fi
displayName: Run hello-world integration test with shared libs
condition: and(succeeded(), ne(variables['CI_OS'], 'windows'))

- bash: |
set -ex
@@ -40,7 +43,7 @@ steps:
cd ..
if [ "$CI_OS" = "windows" ]; then
# Add ldc-jit.dll dir to PATH
export PATH="$PWD/installed/lib:$PATH"
export PATH="$PWD/installed/bin:$PATH"
fi
installed/bin/ldc2 -enable-dynamic-compile -run $BUILD_SOURCESDIRECTORY/tests/dynamiccompile/array.d
displayName: Run dynamic-compile integration test
8 changes: 8 additions & 0 deletions .azure-pipelines/windows-merge.yml
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@ steps:
mv lib lib64
cp -r ../ldc2-*-x86/lib .
mv lib lib32
cp ../ldc2-*-x86/bin/*.dll ../ldc2-*-x86/bin/*.pdb lib32/
displayName: Extract & merge artifacts
- powershell: |
cd ldc2-*-multilib
@@ -68,6 +69,13 @@ steps:
%ARTIFACT_NAME%\bin\ldc2 -v -run hello.d || exit /b
%ARTIFACT_NAME%\bin\ldc2 -v -m32 -run hello.d
displayName: Run 32/64-bit hello-world smoke test with MSVC auto-detection
- script: |
echo on
set PATH=%ARTIFACT_NAME%\bin;%PATH%
%ARTIFACT_NAME%\bin\ldc2 -link-defaultlib-shared -run hello.d || exit /b
set PATH=%ARTIFACT_NAME%\lib32;%PATH%
%ARTIFACT_NAME%\bin\ldc2 -link-defaultlib-shared -m32 -run hello.d
displayName: Run 32/64-bit hello-world smoke test with shared libs

# Pack, build installer & publish artifacts
- script: |
9 changes: 5 additions & 4 deletions .azure-pipelines/windows.yml
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ steps:
clang-cl --version
mkdir bootstrap-ldc
cd bootstrap-ldc
cmake -G Ninja %BUILD_SOURCESDIRECTORY% -DCMAKE_C_COMPILER:PATH=clang-cl.exe -DCMAKE_CXX_COMPILER:PATH=clang-cl.exe -DCMAKE_BUILD_TYPE=Release -DLLVM_ROOT_DIR=%CD%/../llvm -DD_COMPILER=%CD%/../host-ldc/bin/ldmd2 -DBUILD_LTO_LIBS=ON
cmake -G Ninja %BUILD_SOURCESDIRECTORY% -DCMAKE_C_COMPILER:PATH=clang-cl.exe -DCMAKE_CXX_COMPILER:PATH=clang-cl.exe -DCMAKE_BUILD_TYPE=Release -DLLVM_ROOT_DIR=%CD%/../llvm -DD_COMPILER=%CD%/../host-ldc/bin/ldmd2 -DBUILD_SHARED_LIBS=OFF -DBUILD_LTO_LIBS=ON
ninja -j4 || exit /b
bin\ldc2 --version
displayName: Build bootstrap LDC
@@ -116,7 +116,8 @@ steps:
- script: |
cd ..
:: git's usr/bin/bash, unlike its bin/bash, leaves PATH as-is
set PATH=C:\Program Files\Git\usr\bin;%PATH%
:: also add druntime/Phobos DLL dir to PATH
set PATH=%CD%\build\lib;C:\Program Files\Git\usr\bin;%PATH%
call "%LDC_VSDIR%\Common7\Tools\VsDevCmd.bat" -arch=%ARCH%
set DMD_TESTSUITE_MAKE_ARGS=-j4
cd build
@@ -125,8 +126,8 @@ steps:
condition: succeededOrFailed()
- script: |
cd ..
:: Add libcurl.dll dir to PATH
set PATH=%CD%\libcurl\ldc2;C:\Program Files\Git\usr\bin;%PATH%
:: Add druntime/Phobos/libcurl.dll dir to PATH
set PATH=%CD%\build\lib;%CD%\libcurl\ldc2;C:\Program Files\Git\usr\bin;%PATH%
call "%LDC_VSDIR%\Common7\Tools\VsDevCmd.bat" -arch=%ARCH%
cd build
ctest -j4 --output-on-failure -E "dmd-testsuite|lit-tests|ldc2-unittest"
6 changes: 6 additions & 0 deletions driver/linker-msvc.cpp
Original file line number Diff line number Diff line change
@@ -144,6 +144,12 @@ int linkObjToBinaryMSVC(llvm::StringRef outputPath,
args.push_back(objfile);
}

// add precompiled rt.dso_windows object file (in lib directory) when linking
// against shared druntime
if (!defaultLibNames.empty() && linkAgainstSharedDefaultLibs()) {
args.push_back("dso_windows.obj");
}

// .res/.def files
if (global.params.resfile.length)
args.push_back(global.params.resfile.ptr);
3 changes: 1 addition & 2 deletions driver/linker.cpp
Original file line number Diff line number Diff line change
@@ -246,8 +246,7 @@ llvm::StringRef getMscrtLibName(const bool *useInternalToolchain) {
if (useInternal) {
return "vcruntime140";
} else {
// default to static release variant
return linkFullyStatic() != llvm::cl::BOU_FALSE ? "libcmt" : "msvcrt";
return linkAgainstSharedDefaultLibs() ? "msvcrt" : "libcmt";
}
}

198 changes: 146 additions & 52 deletions runtime/CMakeLists.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion runtime/DRuntimeIntegrationTests.cmake
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ if(MULTILIB AND "${TARGET_SYSTEM}" MATCHES "APPLE")
set(druntime_path "${CMAKE_BINARY_DIR}/lib${LIB_SUFFIX}/libdruntime-ldc.a")
endif()
else()
set(shared_druntime_path "$<TARGET_FILE:druntime-ldc${SHARED_LIB_SUFFIX}>")
set(shared_druntime_path "$<TARGET_LINKER_FILE:druntime-ldc${SHARED_LIB_SUFFIX}>")
if(${BUILD_SHARED_LIBS} STREQUAL "ON")
set(druntime_path ${shared_druntime_path})
else()
2 changes: 1 addition & 1 deletion runtime/druntime
Submodule druntime updated 1 files
+10 −10 test/shared/Makefile
2 changes: 1 addition & 1 deletion runtime/phobos