Skip to content

Commit e3a0187

Browse files
authored
Merge pull request #3704 from kinke/dll2
CMake: Support BUILD_SHARED_LIBS for Windows too
2 parents 5ecf764 + 8704601 commit e3a0187

9 files changed

+178
-67
lines changed

.azure-pipelines/5-integration_test.yml

+9-6
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@ steps:
1414
- bash: |
1515
set -ex
1616
cd ..
17-
installed/bin/ldc2 hello.d -m64 -of=hello64 -link-defaultlib-shared
18-
./hello64
17+
if [ "$CI_OS" = "windows" ]; then
18+
# Add druntime/Phobos DLL dir to PATH
19+
export PATH="$PWD/installed/bin:$PATH"
20+
fi
21+
installed/bin/ldc2 hello.d -link-defaultlib-shared
22+
./hello
1923
if [ "$CI_OS" = "linux" ]; then
20-
installed/bin/ldc2 hello.d -m32 -of=hello32 -link-defaultlib-shared
21-
./hello32
24+
installed/bin/ldc2 hello.d -m32 -link-defaultlib-shared
25+
./hello
2226
fi
2327
displayName: Run hello-world integration test with shared libs
24-
condition: and(succeeded(), ne(variables['CI_OS'], 'windows'))
2528

2629
- bash: |
2730
set -ex
@@ -40,7 +43,7 @@ steps:
4043
cd ..
4144
if [ "$CI_OS" = "windows" ]; then
4245
# Add ldc-jit.dll dir to PATH
43-
export PATH="$PWD/installed/lib:$PATH"
46+
export PATH="$PWD/installed/bin:$PATH"
4447
fi
4548
installed/bin/ldc2 -enable-dynamic-compile -run $BUILD_SOURCESDIRECTORY/tests/dynamiccompile/array.d
4649
displayName: Run dynamic-compile integration test

.azure-pipelines/windows-merge.yml

+8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ steps:
3737
mv lib lib64
3838
cp -r ../ldc2-*-x86/lib .
3939
mv lib lib32
40+
cp ../ldc2-*-x86/bin/*.dll ../ldc2-*-x86/bin/*.pdb lib32/
4041
displayName: Extract & merge artifacts
4142
- powershell: |
4243
cd ldc2-*-multilib
@@ -68,6 +69,13 @@ steps:
6869
%ARTIFACT_NAME%\bin\ldc2 -v -run hello.d || exit /b
6970
%ARTIFACT_NAME%\bin\ldc2 -v -m32 -run hello.d
7071
displayName: Run 32/64-bit hello-world smoke test with MSVC auto-detection
72+
- script: |
73+
echo on
74+
set PATH=%ARTIFACT_NAME%\bin;%PATH%
75+
%ARTIFACT_NAME%\bin\ldc2 -link-defaultlib-shared -run hello.d || exit /b
76+
set PATH=%ARTIFACT_NAME%\lib32;%PATH%
77+
%ARTIFACT_NAME%\bin\ldc2 -link-defaultlib-shared -m32 -run hello.d
78+
displayName: Run 32/64-bit hello-world smoke test with shared libs
7179

7280
# Pack, build installer & publish artifacts
7381
- script: |

.azure-pipelines/windows.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ steps:
7676
clang-cl --version
7777
mkdir bootstrap-ldc
7878
cd bootstrap-ldc
79-
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
79+
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
8080
ninja -j4 || exit /b
8181
bin\ldc2 --version
8282
displayName: Build bootstrap LDC
@@ -116,7 +116,8 @@ steps:
116116
- script: |
117117
cd ..
118118
:: git's usr/bin/bash, unlike its bin/bash, leaves PATH as-is
119-
set PATH=C:\Program Files\Git\usr\bin;%PATH%
119+
:: also add druntime/Phobos DLL dir to PATH
120+
set PATH=%CD%\build\lib;C:\Program Files\Git\usr\bin;%PATH%
120121
call "%LDC_VSDIR%\Common7\Tools\VsDevCmd.bat" -arch=%ARCH%
121122
set DMD_TESTSUITE_MAKE_ARGS=-j4
122123
cd build
@@ -125,8 +126,8 @@ steps:
125126
condition: succeededOrFailed()
126127
- script: |
127128
cd ..
128-
:: Add libcurl.dll dir to PATH
129-
set PATH=%CD%\libcurl\ldc2;C:\Program Files\Git\usr\bin;%PATH%
129+
:: Add druntime/Phobos/libcurl.dll dir to PATH
130+
set PATH=%CD%\build\lib;%CD%\libcurl\ldc2;C:\Program Files\Git\usr\bin;%PATH%
130131
call "%LDC_VSDIR%\Common7\Tools\VsDevCmd.bat" -arch=%ARCH%
131132
cd build
132133
ctest -j4 --output-on-failure -E "dmd-testsuite|lit-tests|ldc2-unittest"

driver/linker-msvc.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ int linkObjToBinaryMSVC(llvm::StringRef outputPath,
144144
args.push_back(objfile);
145145
}
146146

147+
// add precompiled rt.dso_windows object file (in lib directory) when linking
148+
// against shared druntime
149+
if (!defaultLibNames.empty() && linkAgainstSharedDefaultLibs()) {
150+
args.push_back("dso_windows.obj");
151+
}
152+
147153
// .res/.def files
148154
if (global.params.resfile.length)
149155
args.push_back(global.params.resfile.ptr);

driver/linker.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ llvm::StringRef getMscrtLibName(const bool *useInternalToolchain) {
246246
if (useInternal) {
247247
return "vcruntime140";
248248
} else {
249-
// default to static release variant
250-
return linkFullyStatic() != llvm::cl::BOU_FALSE ? "libcmt" : "msvcrt";
249+
return linkAgainstSharedDefaultLibs() ? "msvcrt" : "libcmt";
251250
}
252251
}
253252

0 commit comments

Comments
 (0)