Skip to content

Commit

Permalink
[add tests]
Browse files Browse the repository at this point in the history
  • Loading branch information
kinke committed Aug 18, 2023
1 parent c555639 commit 49643e9
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
# FIXME: DMD fails a few tests on Windows; remove them for now
if [[ '${{ matrix.dc }}' = dmd* ]]; then
# DLL support is lacking
rm -rf test/{1-dynLib-simple,2-dynLib-dep,2-dynLib-with-staticLib-dep}
rm -rf test/{1-dynLib-simple,2-dynLib-dep,2-dynLib-with-staticLib-dep,dynLib-monolith}
# Unicode in paths too
rm -rf test/issue130-unicode-СНА*
# ImportC probably requires set-up MSVC environment variables
Expand Down
16 changes: 16 additions & 0 deletions test/dynLib-monolith.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

DIR=$(dirname "${BASH_SOURCE[0]}")
. "$DIR"/common.sh

if [[ "$DC" != ldc* ]]; then
echo "Skipping test, needs LDC"
exit 0
fi

# enforce a full build (2 static libs, 1 dynamic one) and collect -v output
output=$("$DUB" build -v -f --root "$DIR"/dynLib-monolith)

if [[ $(grep -c -- '-fvisibility=hidden' <<<"$output") -ne 3 ]]; then
die $LINENO "Didn't find 3 occurrences of '-fvisibility=hidden' in the verbose dub output!" "$output"
fi
Empty file added test/dynLib-monolith/.no_run
Empty file.
Empty file added test/dynLib-monolith/.no_test
Empty file.
15 changes: 15 additions & 0 deletions test/dynLib-monolith/dub.sdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name "dynlib-monolith"
description "A 'monolithic' dynamic library, linking all dependencies statically (except for shared druntime/Phobos) and exporting select symbols explicitly via 'export'"
targetType "dynamicLibrary"
dependency "inner_dep" path="inner_dep"

# With LDC, `-fvisibility=hidden` is passed down for compiling all dependencies.
dflags "-fvisibility=hidden" platform="ldc"
dflags "-fvisibility=hidden" platform="gdc"
# not supported by DMD

# With LDC on Windows, code ending up in a DLL is compiled with
# `-fvisibility=public -dllimport=all` by default. So we additionally need
# to override `-dllimport` to use the shared druntime/Phobos DLLs (used by
# default for dynamic libraries), which is also passed down to all deps:
dflags "-dllimport=defaultLibsOnly" platform="windows-ldc"
4 changes: 4 additions & 0 deletions test/dynLib-monolith/inner_dep/dub.sdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name "inner_dep"
description "A static library depending on another static library"
targetType "staticLibrary"
dependency "staticlib-simple" path="../../1-staticLib-simple"
7 changes: 7 additions & 0 deletions test/dynLib-monolith/inner_dep/source/inner_dep/mod.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module inner_dep.mod;

void innerDepFunction()
{
import staticlib.app;
entry();
}
7 changes: 7 additions & 0 deletions test/dynLib-monolith/source/library.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module library;

export void foo()
{
import inner_dep.mod;
innerDepFunction();
}
Empty file.
11 changes: 11 additions & 0 deletions test/exe-shared-defaultlib/dub.sdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name "exe-shared-defaultlib"
description "An executable with a statically linked dep, linked against *shared* druntime/Phobos"
targetType "executable"
dependency "staticlib-simple" path="../1-staticLib-simple/"

# With LDC on Windows, `-link-defaultlib-shared` is passed down for compiling
# staticlib-simple (for an implicit `-dllimport=defaultLibsOnly`).
dflags "-link-defaultlib-shared" platform="ldc"

# no libphobos2.dll/dylib with DMD on Windows/Mac
dflags "-defaultlib=libphobos2.so" platform="linux-dmd"
7 changes: 7 additions & 0 deletions test/exe-shared-defaultlib/source/app.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module app;
import staticlib.app;

void main()
{
entry();
}

0 comments on commit 49643e9

Please sign in to comment.