Skip to content

Commit 15d0182

Browse files
kinkethewilsonator
authored andcommitted
dub build: Fix cross-compilation
The build of the lexer dub subpackage requires running and building a little config.d tool as custom pregenerate command. Forwarding the target architecture via `--arch=$DUB_ARCH` to the nested dub build of config.d was added in dlang#9275, to fix cross- compilation, but in reality broke it. Not specifying the architecture explicitly for the little helper build lets the compiler pick the default one, the host's native platform in practice, which is guaranteed to be runnable on that compiling **host**, independent from the **target** platform for the main dub build. Suppose one cross-compiles the dmd:lexer subpackage from x86_64 to AArch64 - an AArch64 config.d executable will hardly run on the x86_64 host, and won't be able to generate the `VERSION` and `SYSCONFDIR.imp` string-import files as pre- requisite of the build. Side note: using little separately-built .d tools/scripts as build helpers for autogenerating little VERSION files etc. is IMO bad practice - when cross-compiling, you require a D compiler that can a) cross-compile, and b) build successfully for the native platform too. Not sure this approach will e.g. ever work with GDC, where you have different toolchains for each host->target combination.
1 parent 83adb8a commit 15d0182

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

config.d

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,14 @@ void main(const string[] args)
2020
const outputDirectory = args[1];
2121
const versionFile = args[2];
2222

23-
version (Posix)
24-
const sysConfigDirectory = args[3];
25-
2623
mkdirRecurse(outputDirectory);
2724
const version_ = generateVersion(versionFile);
2825

2926
updateIfChanged(buildPath(outputDirectory, "VERSION"), version_);
3027

31-
version (Posix)
28+
if (args.length > 3)
3229
{
30+
const sysConfigDirectory = args[3];
3331
const path = buildPath(outputDirectory, "SYSCONFDIR.imp");
3432
updateIfChanged(path, sysConfigDirectory);
3533
}

dub.sdl

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ description "The DMD compiler"
33
authors "Walter Bright"
44
copyright "Copyright © 1999-2018, The D Language Foundation"
55
license "BSL-1.0"
6+
toolchainRequirements dub=">=1.29.0" # can use $DUB_EXE etc. in custom commands
67

78
targetType "none"
89
dependency ":frontend" version="*"
@@ -50,17 +51,9 @@ subPackage {
5051
"CallbackAPI" \
5152
"DMDLIB"
5253

53-
preGenerateCommands `
54-
"$${DUB_EXE}" \
55-
--arch=$${DUB_ARCH} \
56-
--compiler=$${DC} \
57-
--single "$${DUB_PACKAGE_DIR}config.d" \
58-
-- "$${DUB_PACKAGE_DIR}generated/dub" \
59-
"$${DUB_PACKAGE_DIR}VERSION" \
60-
/etc
61-
` platform="posix"
62-
63-
preGenerateCommands `"%DUB_EXE%" --arch=%DUB_ARCH% --compiler="%DC%" --single "%DUB_PACKAGE_DIR%config.d" -- "%DUB_PACKAGE_DIR%generated/dub" "%DUB_PACKAGE_DIR%VERSION"` platform="windows"
54+
# generate files `generated/dub/{VERSION,SYSCONFDIR.imp}` for string-imports
55+
# by building & running the config.d tool
56+
preGenerateCommands `"$DUB_EXE" "--compiler=$DC" --single "${DUB_PACKAGE_DIR}config.d" -- "${DUB_PACKAGE_DIR}generated/dub" "${DUB_PACKAGE_DIR}VERSION" /etc`
6457

6558
stringImportPaths \
6659
"compiler/src/dmd/res" \

0 commit comments

Comments
 (0)