diff --git a/changelog/dmd-mscoff-default.dd b/changelog/dmd-mscoff-default.dd new file mode 100644 index 0000000..5fc0c11 --- /dev/null +++ b/changelog/dmd-mscoff-default.dd @@ -0,0 +1,16 @@ +DUB will no longer use OPTLINK as default on Windows + +DMD's $(LINK2 https://digitalmars.com/ctg/optlink.html, OPTLINK) has many limitations. Apart from long-standing issues in the underlying DigitalMars runtime, +the maximum number of symbols is limited as well, which is why most big DUB +libraries can't be compiled with OPTLINK for years. This has been a cause of +grief and pain for many users and impacted the newcomer experience severly. + +With this release, `dub` will no longer use `OPTLINK` as default on Windows, but +use `-m32mscoff` (MSCOFF) on 32-bit Windows systems and `-m64` (MSCOFF) on 64-bit +Windows. + +Users can still manually instruct `dub` to use OPTLINK with the `--arch=x86` switch of `dub`: + +$(CONSOLE +> dub --arch=x86 +) diff --git a/source/dub/compilers/dmd.d b/source/dub/compilers/dmd.d index ac0a459..a628076 100644 --- a/source/dub/compilers/dmd.d +++ b/source/dub/compilers/dmd.d @@ -22,6 +22,24 @@ import std.process; import std.typecons; +// Determines whether the specified process is running under WOW64 or an Intel64 of x64 processor. +version (Windows) +private Nullable!bool isWow64() { + // See also: https://docs.microsoft.com/de-de/windows/desktop/api/sysinfoapi/nf-sysinfoapi-getnativesysteminfo + import core.sys.windows.windows : GetNativeSystemInfo, SYSTEM_INFO, PROCESSOR_ARCHITECTURE_AMD64; + + static Nullable!bool result; + + // A process's architecture won't change over while the process is in memory + // Return the cached result + if (!result.isNull) + return result; + + SYSTEM_INFO systemInfo; + GetNativeSystemInfo(&systemInfo); + result = systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64; + return result; +} class DMDCompiler : Compiler { private static immutable s_options = [ @@ -86,7 +104,14 @@ string[] arch_flags; switch (arch_override) { default: throw new Exception("Unsupported architecture: "~arch_override); - case "": break; + case "": + // Don't use Optlink by default on Windows + version (Windows) { + const is64bit = isWow64(); + if (!is64bit.isNull) + arch_flags = [is64bit ? "-m64" : "-m32mscoff"]; + } + break; case "x86": arch_flags = ["-m32"]; break; case "x86_64": arch_flags = ["-m64"]; break; case "x86_mscoff": arch_flags = ["-m32mscoff"]; break;