Skip to content

Commit

Permalink
LDC: Don't keep around temporary object files for static libs (#2690)
Browse files Browse the repository at this point in the history
* LDC: Don't keep around temporary object files for static libs

This was a workaround for older LDC versions. Since LDC v1.25,
`-cleanup-obj` implies that the temporary object files are placed
into a unique temp directory (per compiler invocation), so that
object file collisions across parallel dub invocations cannot happen
anymore.
  • Loading branch information
kinke authored Jun 13, 2024
1 parent cb3c523 commit 6610ddf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
16 changes: 11 additions & 5 deletions source/dub/compilers/ldc.d
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ config /etc/ldc2.conf (x86_64-pc-linux-gnu)

void prepareBuildSettings(ref BuildSettings settings, const scope ref BuildPlatform platform, BuildSetting fields = BuildSetting.all) const
{
import std.format : format;
enforceBuildRequirements(settings);

// Keep the current dflags at the end of the array so that they will overwrite other flags.
Expand All @@ -118,9 +117,6 @@ config /etc/ldc2.conf (x86_64-pc-linux-gnu)
settings.addDFlags(t[1]);
}

// since LDC always outputs multiple object files, avoid conflicts by default
settings.addDFlags("--oq", format("-od=%s/obj", settings.targetPath));

if (!(fields & BuildSetting.versions)) {
settings.addDFlags(settings.versions.map!(s => "-d-version="~s)().array());
settings.versions = null;
Expand Down Expand Up @@ -241,7 +237,17 @@ config /etc/ldc2.conf (x86_64-pc-linux-gnu)
case TargetType.executable: break;
case TargetType.library:
case TargetType.staticLibrary:
settings.addDFlags("-lib");
// -oq: name object files uniquely (so the files don't collide)
settings.addDFlags("-lib", "-oq");
// -cleanup-obj (supported since LDC v1.1): remove object files after archiving to static lib
if (platform.frontendVersion >= 2071) {
settings.addDFlags("-cleanup-obj");
}
if (platform.frontendVersion < 2095) {
// Since LDC v1.25, -cleanup-obj defaults to a unique temp -od directory
// We need to resort to a unique-ish -od directory before that
settings.addDFlags("-od=" ~ settings.targetPath ~ "/obj");
}
break;
case TargetType.dynamicLibrary:
settings.addDFlags("-shared");
Expand Down
17 changes: 6 additions & 11 deletions test/removed-dub-obj.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@
. $(dirname "${BASH_SOURCE[0]}")/common.sh
cd ${CURR_DIR}/removed-dub-obj

DUB_CACHE_PATH="$HOME/.dub/cache/removed-dub-obj/"
DUB_CACHE_PATH="$HOME/.dub/cache/removed-dub-obj"

rm -rf $DUB_CACHE_PATH
rm -rf "$DUB_CACHE_PATH"

${DUB} build --compiler=${DC}

[ -d "$DUB_CACHE_PATH/obj" ] && die $LINENO "$DUB_CACHE_PATH/obj was found"
[ -d "$DUB_CACHE_PATH" ] || die $LINENO "$DUB_CACHE_PATH not found"

if [[ ${DC} == *"ldc"* ]]; then
if [ ! -f $DUB_CACHE_PATH/~master/build/library-*/obj/test.o* ]; then
ls -lR $DUB_CACHE_PATH
die $LINENO '$DUB_CACHE_PATH/~master/build/library-*/obj/test.o* was not found'
fi
fi

exit 0
numObjectFiles=$(find "$DUB_CACHE_PATH" -type f -iname '*.o*' | wc -l)
# note: fails with LDC < v1.1
[ "$numObjectFiles" -eq 0 ] || die $LINENO "Found left-over object files in $DUB_CACHE_PATH"

0 comments on commit 6610ddf

Please sign in to comment.