diff --git a/source/dub/compilers/buildsettings.d b/source/dub/compilers/buildsettings.d index beebd0f..16de290 100644 --- a/source/dub/compilers/buildsettings.d +++ b/source/dub/compilers/buildsettings.d @@ -277,9 +277,10 @@ deprecationErrors = 1<<19, /// Stop compilation upon usage of deprecated features (-de) property = 1<<20, /// DEPRECATED: Enforce property syntax (-property) profileGC = 1<<21, /// Profile runtime allocations + pic = 1<<22, /// Generate position independent code // for internal usage - _docs = 1<<22, // Write ddoc to docs - _ddox = 1<<23, // Compile docs.json + _docs = 1<<23, // Write ddoc to docs + _ddox = 1<<24 // Compile docs.json } struct BuildOptions { @@ -326,4 +327,5 @@ | BuildOption.noBoundsCheck | BuildOption.profile | BuildOption.ignoreUnknownPragmas | BuildOption.syntaxOnly | BuildOption.warnings | BuildOption.warningsAsErrors | BuildOption.ignoreDeprecations | BuildOption.deprecationWarnings - | BuildOption.deprecationErrors | BuildOption.property | BuildOption.profileGC; + | BuildOption.deprecationErrors | BuildOption.property | BuildOption.profileGC + | BuildOption.pic; diff --git a/source/dub/compilers/dmd.d b/source/dub/compilers/dmd.d index 0295a64..b13736e 100644 --- a/source/dub/compilers/dmd.d +++ b/source/dub/compilers/dmd.d @@ -20,7 +20,6 @@ import std.exception; import std.file; import std.process; -import std.random; import std.typecons; @@ -117,7 +116,7 @@ } version (Posix) { - if (settings.targetType == TargetType.dynamicLibrary) + if (settings.options & BuildOption.pic) settings.addDFlags("-fPIC"); } diff --git a/source/dub/compilers/gdc.d b/source/dub/compilers/gdc.d index 7a20f54..0d5d3cf 100644 --- a/source/dub/compilers/gdc.d +++ b/source/dub/compilers/gdc.d @@ -20,7 +20,6 @@ import std.exception; import std.file; import std.process; -import std.random; import std.typecons; @@ -119,7 +118,7 @@ settings.lflags = null; } - if (settings.targetType == TargetType.dynamicLibrary) + if (settings.options & BuildOption.pic) settings.addDFlags("-fPIC"); assert(fields & BuildSetting.dflags); diff --git a/source/dub/compilers/ldc.d b/source/dub/compilers/ldc.d index 8953e5e..df8c2de 100644 --- a/source/dub/compilers/ldc.d +++ b/source/dub/compilers/ldc.d @@ -20,7 +20,6 @@ import std.exception; import std.file; import std.process; -import std.random; import std.typecons; @@ -117,7 +116,7 @@ settings.lflags = null; } - if (settings.targetType == TargetType.dynamicLibrary) + if (settings.options & BuildOption.pic) settings.addDFlags("-relocation-model=pic"); assert(fields & BuildSetting.dflags); diff --git a/source/dub/generators/generator.d b/source/dub/generators/generator.d index 7938cc7..7865d9e 100644 --- a/source/dub/generators/generator.d +++ b/source/dub/generators/generator.d @@ -188,6 +188,10 @@ main_files ~= buildsettings.mainSourceFile; } + // set pic for dynamic library builds. + if (buildsettings.targetType == TargetType.dynamicLibrary) + buildsettings.addOptions(BuildOption.pic); + logDiagnostic("Generate target %s (%s %s %s)", pack.name, buildsettings.targetType, buildsettings.targetPath, buildsettings.targetName); if (is_target) targets[pack.name] = TargetInfo(pack, [pack], configs[pack.name], buildsettings, null); diff --git a/test/1-dynLib-simple/.no_build b/test/1-dynLib-simple/.no_build deleted file mode 100644 index 72679d2..0000000 --- a/test/1-dynLib-simple/.no_build +++ /dev/null @@ -1 +0,0 @@ -Remove me when bug with dynamic libs get fixed. diff --git a/test/1-dynLib-simple/.no_build_gdc b/test/1-dynLib-simple/.no_build_gdc new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/1-dynLib-simple/.no_build_gdc diff --git a/test/1-dynLib-simple/.no_build_ldc2 b/test/1-dynLib-simple/.no_build_ldc2 new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/1-dynLib-simple/.no_build_ldc2 diff --git a/test/1-dynLib-simple/.no_run b/test/1-dynLib-simple/.no_run new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/1-dynLib-simple/.no_run diff --git a/test/2-dynLib-with-staticLib-dep/.no_build_gdc b/test/2-dynLib-with-staticLib-dep/.no_build_gdc new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/2-dynLib-with-staticLib-dep/.no_build_gdc diff --git a/test/2-dynLib-with-staticLib-dep/.no_build_ldc2 b/test/2-dynLib-with-staticLib-dep/.no_build_ldc2 new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/2-dynLib-with-staticLib-dep/.no_build_ldc2 diff --git a/test/2-dynLib-with-staticLib-dep/.no_run b/test/2-dynLib-with-staticLib-dep/.no_run new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/2-dynLib-with-staticLib-dep/.no_run diff --git a/test/2-dynLib-with-staticLib-dep/dub.json b/test/2-dynLib-with-staticLib-dep/dub.json new file mode 100644 index 0000000..f0b6043 --- /dev/null +++ b/test/2-dynLib-with-staticLib-dep/dub.json @@ -0,0 +1,7 @@ +{ + "name": "dynlib-with-staticlib-dep", + "targetType": "dynamicLibrary", + "dependencies": { + "staticlib-simple": { "path": "../1-staticLib-simple/" } + } +} diff --git a/test/2-dynLib-with-staticLib-dep/source/dynlib/app.d b/test/2-dynLib-with-staticLib-dep/source/dynlib/app.d new file mode 100644 index 0000000..9741cae --- /dev/null +++ b/test/2-dynLib-with-staticLib-dep/source/dynlib/app.d @@ -0,0 +1,8 @@ +module dynlib.app; +import std.stdio; +import staticlib.app; + +void foo() +{ + entry(); +} diff --git a/test/run-unittest.sh b/test/run-unittest.sh index 838c8a9..1bb40f7 100755 --- a/test/run-unittest.sh +++ b/test/run-unittest.sh @@ -28,6 +28,7 @@ DC=dmd fi +DC_BIN=$(basename "$DC") CURR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) for script in $(ls $CURR_DIR/*.sh); do @@ -39,8 +40,10 @@ for pack in $(ls -d $CURR_DIR/*/); do if [ -e $pack/.min_frontend ] && [ ! -z "$FRONTEND" -a "$FRONTEND" \< $(cat $pack/.min_frontend) ]; then continue; fi + # First we build the packages - if [ ! -e $pack/.no_build ]; then # For sourceLibrary + if [ ! -e $pack/.no_build ] && [ ! -e $pack/.no_build_$DC_BIN ]; then # For sourceLibrary + build=1 if [ -e $pack/.fail_build ]; then log "Building $pack, expected failure..." $DUB build --force --root=$pack --compiler=$DC 2>/dev/null && logError "Error: Failure expected, but build passed." @@ -48,16 +51,18 @@ log "Building $pack..." $DUB build --force --root=$pack --compiler=$DC || logError "Build failure." fi + else + build=0 fi - # We run the ones that are supposed to be ran - if [ ! -e $pack/.no_build ] && [ ! -e $pack/.no_run ]; then + # We run the ones that are supposed to be run + if [ $build -eq 1 ] && [ ! -e $pack/.no_run ] && [ ! -e $pack/.no_run_$DC_BIN ]; then log "Running $pack..." $DUB run --force --root=$pack --compiler=$DC || logError "Run failure." fi # Finally, the unittest part - if [ ! -e $pack/.no_build ] && [ ! -e $pack/.no_test ]; then + if [ $build -eq 1 ] && [ ! -e $pack/.no_test ] && [ ! -e $pack/.no_test_$DC_BIN ]; then log "Testing $pack..." $DUB test --force --root=$pack --compiler=$DC || logError "Test failure." fi