Skip to content

Commit d633c46

Browse files
dkorpelclaude
andcommitted
test runner: build dshell harness with compiler under test
The dshell prebuilt library and per-test driver were built with the host compiler (e.g. LDC 1.23 on the VisualD CI), which is too old to parse the current druntime/Phobos sources (short '=>' function bodies etc.), causing parse errors when their imports were analyzed. They also import Phobos and link against each other, so build both with the compiler under test using PHOBOS_DFLAGS instead, matching the pre-druntime-only behaviour. Also strip the benign LNK4255 'multiple objects of the same name' linker warning: druntime.lib is built as one 'dmd -lib' archive and contains several objects sharing a basename (memory.obj etc.), so the MS linker warns when linking with -g, leaking into tests that expect no output. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent e349d67 commit d633c46

2 files changed

Lines changed: 23 additions & 10 deletions

File tree

compiler/test/run.d

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,23 @@ void ensureToolsExists(const string[string] env, const TestTool[] tools ...)
337337
}
338338

339339
string[] buildCommand;
340+
string[string] buildEnv = null;
340341
if (tool.linksWithTests)
341342
{
343+
// The dshell library imports Phobos and is linked against the tests,
344+
// so it must be built by the compiler under test (the host compiler
345+
// may be too old to parse the current druntime/Phobos) using the
346+
// Phobos DFLAGS rather than the druntime-only default.
342347
buildCommand = [
343-
hostDMD,
348+
env["DMD"],
349+
"-conf=",
344350
"-m"~env["MODEL"],
345351
"-of" ~ targetBin,
346352
"-c",
347353
sourceFile
348354
] ~ getPicFlags(env);
355+
buildEnv = env.dup;
356+
buildEnv["DFLAGS"] = env.get("PHOBOS_DFLAGS", "");
349357
}
350358
else
351359
{
@@ -359,7 +367,7 @@ void ensureToolsExists(const string[string] env, const TestTool[] tools ...)
359367

360368
writefln("Executing: %-(%s %)", buildCommand);
361369
stdout.flush();
362-
if (spawnProcess(buildCommand, null).wait)
370+
if (spawnProcess(buildCommand, buildEnv).wait)
363371
{
364372
stderr.writefln("failed to build '%s'", targetBin);
365373
atomicOp!"+="(failCount, 1);

compiler/test/tools/d_do_test.d

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,6 +1845,12 @@ int tryMain(string[] args)
18451845

18461846
compile_output = compile_output.unifyNewLine();
18471847
compile_output = std.regex.replaceAll(compile_output, regex(`^DMD v2\.[0-9]+.*\n? DEBUG$`, "m"), "");
1848+
// druntime.lib is built as a single library with `dmd -lib`, so
1849+
// it contains several object files with the same basename (e.g.
1850+
// memory.obj from core.memory and rt.memory). The MS linker emits
1851+
// a benign LNK4255 warning about this when linking with `-g`;
1852+
// strip it so it doesn't fail tests that expect no output.
1853+
compile_output = std.regex.replaceAll(compile_output, regex(`^.*warning LNK4255:.*\n?`, "m"), "");
18481854
compile_output = std.string.strip(compile_output);
18491855
// replace test_result path with fixed ones
18501856
compile_output = compile_output.replace(result_path, resultsDirReplacement);
@@ -2355,15 +2361,18 @@ static this()
23552361
auto outfile = File(output_file, "w");
23562362
enum keepFilesOpen = Config.retainStdout | Config.retainStderr;
23572363

2358-
// dshell scripts are test-harness code that should not be driven by the
2359-
// compiler under test, but by a stable host compiler.
2364+
// dshell scripts import Phobos (std.process etc.) and link against the
2365+
// prebuilt dshell library, so build them with the compiler under test and
2366+
// the Phobos DFLAGS: the host compiler may be too old to parse the current
2367+
// druntime/Phobos sources, and the prebuilt library is built by the
2368+
// compiler under test too, so both must agree.
23602369
environment["DFLAGS"] = envData.phobosDflags;
23612370

23622371
//
23632372
// compile the test
23642373
//
23652374
{
2366-
const compile = [envData.hostDmd, "-m"~envData.model] ~
2375+
const compile = [envData.dmd, "-conf=", "-m"~envData.model] ~
23672376
envData.picFlag ~ [
23682377
"-od" ~ testOutDir,
23692378
"-of" ~ testScriptExe,
@@ -2377,13 +2386,9 @@ static this()
23772386
];
23782387
outfile.writeln("[COMPILE_TEST] ", escapeShellCommand(compile));
23792388
outfile.flush();
2380-
// Build with the host compiler's own configuration: clear DFLAGS so the
2381-
// druntime-only flags (and the Phobos PHOBOS_DFLAGS) don't leak in here.
2382-
auto compileEnv = environment.toAA();
2383-
compileEnv.remove("DFLAGS");
23842389
// Note that spawnprocess closes the file, so it will need to be re-opened
23852390
// below when we run the test
2386-
auto compileProc = std.process.spawnProcess(compile, stdin, outfile, outfile, compileEnv, keepFilesOpen);
2391+
auto compileProc = std.process.spawnProcess(compile, stdin, outfile, outfile, null, keepFilesOpen);
23872392
const exitCode = wait(compileProc);
23882393
if (exitCode != 0)
23892394
{

0 commit comments

Comments
 (0)