Author Topic: 64-bit Windows build  (Read 1477 times)

0 Members and 1 Guest are viewing this topic.

Online Simon

  • Administrator
  • Posts: 3005
    • View Profile
    • Lix
64-bit Windows build
« on: April 01, 2018, 09:07:15 AM »
The homepage's Lix download for Windows is a 32-bit executable. Building 64-bit Windows executables from D source is possible, but hard. I'll continue to ship 32-bit builds.

Problems of 32-bit: Windows D Lix 32-bit may crash on huge maps (width x height >= 2.8 million pixels). Our theory is that it allocates so much VRAM that it begins swapping the VRAM to RAM, and 32-bit Lix cannot address more than 2 GB of RAM. My workaround is to print a warning over the level preview on huge maps, but still allow to play these maps. Post on the D forums about trouble with the 32-bit GC.

64-bit Lix would still be a chubby glutton who belongs into a diet camp, but at least 64-bit Lix won't crash on large maps, and overall RAM consumption is less. No idea why. And any Windows computer younger than 12 years can run 64-bit apps.

Reqires fat MSVS: While 32-bit builds with dmd and its included optlink, 64-bit need a different linker. It looks like the only working 64-bit linker comes with Microsoft Visual Studio (MSVS), a proprietary IDE + SDK + toolchain that requires 5 GB to even install. Maybe you don't need the IDE itself, only the toolchain and the SDK, but it's still a sizable chunk. The Community edition may be gratis, but you're subjected to licensing terms that seem crazy when you're accustomed to free-and-open-source.

MinGW + D = crash: A possible alternative for MSVS is the MinGW toolchain. I've used that in the past to compile C++ Lix and am moderately familiar with it. It offers gcc, g++, make, and ld for Windows, and probably some other useful tools. This wiki entry explains installing dmd, but it doesn't explain the MinGW toolchain, or how it interacts with dmd.

One direct test with MinGW and the MS build tools made Windows 64-bit Lix crash at runtime. No stacktracke, but we didn't enter it with a debugger. The offered MinGW variant still uses VC++ 2010 redistributable, maybe that's the problem for running the app.

NuGet DLLs/LIBs are good: To run Lix, you need Allegro 5 DLLs (I ship them with the binary Windows download), and to build Lix, you must create LIBs from the DLLs. Recently, I've tried to update the DLLs. Suddenly, the Allgero DLLs required extra DLLs (not from Allgero) that weren't needed before, therefore I've postponed updating Allgero. But Allegro offers NuGet packages both for 32-bit and 64-bit, you can extract DLLs with readily-made LIBs from those, and they don't require any extra DLLs. I should use these in the binary download.

All of this research is not by me, but by Forestidia. Thanks for your research! Please nudge me to fix any mistakes above.

-- Simon
« Last Edit: December 27, 2020, 04:03:53 PM by Simon »

Offline Forestidia86

  • Posts: 615
  • inactive
    • View Profile
Re: 64-bit Windows build: It's hard
« Reply #1 on: September 18, 2020, 10:29:56 PM »
Since version 1.13.0 ldc self-sufficiently creates 64bit builds on Win, user only needs a particular Visual C++ runtime, which most should have.
Apparently even dmd is self-sufficient since version 2.079. For an successful build you need to put 64bit Allegro libs in the lib64 folder. For suppression of console window change in dub.json the line
Code: [Select]
"lflags-windows-dmd": ["-L/subsystem:windows"], to two lines
Code: [Select]
"lflags-windows-x86-dmd": ["-L/subsystem:windows"],
"lflags-windows-x86_64-dmd": ["-subsystem:windows", "-entry:mainCRTStartup"],

as of version 2.093.1
« Last Edit: December 27, 2020, 04:00:26 PM by Forestidia86 »

Offline Forestidia86

  • Posts: 615
  • inactive
    • View Profile
Re: 64-bit Windows build
« Reply #2 on: December 27, 2020, 04:00:35 PM »
Since version 1.13.0 ldc self-sufficiently creates 64bit builds on Win, user only needs a particular Visual C++ runtime, which most should have.
Apparently even dmd is self-sufficient since version 2.079. For an successful build you need to put 64bit Allegro libs in the lib64 folder. For suppression of console window change in dub.json the line
Code: [Select]
"lflags-windows-dmd": ["-L/subsystem:windows"], to two lines
Code: [Select]
"lflags-windows-x86-dmd": ["-L/subsystem:windows"],
"lflags-windows-x86_64-dmd": ["-subsystem:windows", "-entry:mainCRTStartup"],

as of version 2.093.1

It is possible that dmd at some future time updates the linker so that there as with ldc the wmain C entry point is then the correct one. Then the linker flag for dmd 64bit becomes the same as the ldc one ('wmain' instead of 'main').

Versions of ldc older than 1.21.0 had still the main C entry point as above. Change was through that pull request for v. 1.21.0.
« Last Edit: December 27, 2020, 04:04:03 PM by Simon »

Offline Forestidia86

  • Posts: 615
  • inactive
    • View Profile
Re: 64-bit Windows build
« Reply #3 on: December 27, 2020, 09:49:45 PM »
Since version 1.13.0 ldc self-sufficiently creates 64bit builds on Win, user only needs a particular Visual C++ runtime, which most should have.
Apparently even dmd is self-sufficient since version 2.079. For an successful build you need to put 64bit Allegro libs in the lib64 folder. For suppression of console window change in dub.json the line
Code: [Select]
"lflags-windows-dmd": ["-L/subsystem:windows"], to two lines
Code: [Select]
"lflags-windows-x86-dmd": ["-L/subsystem:windows"],
"lflags-windows-x86_64-dmd": ["-subsystem:windows", "-entry:mainCRTStartup"],

as of version 2.093.1

It is possible that dmd at some future time updates the linker so that there as with ldc the wmain C entry point is then the correct one. Then the linker flag for dmd 64bit becomes the same as the ldc one ('wmain' instead of 'main').

Versions of ldc older than 1.21.0 had still the main C entry point as above. Change was through that pull request for v. 1.21.0.

The wmain C entry point seems to be part of the ldc variant of druntime, so I don't know if it ever gets a thing for dmd. As a non-programmer I can't fully assess that, but I think I got led astray by the fact that it manifests itself in the linker flag. So probably unrelated to the linker but rather to the library. (?)

Online Simon

  • Administrator
  • Posts: 3005
    • View Profile
    • Lix
Re: 64-bit Windows build
« Reply #4 on: December 28, 2020, 08:08:21 PM »
Thanks for the investigation and the theory!

The entry point will likely depend on the runtime. It's possible that LDC and DMD come each with their own, different, C and D runtimes.

When the program starts, execution begins not in Lix; the D runtime first sets up things like the garbage collector, then runs Lix's main(). Now, I haven't researched enough what (w)mainCRTStartup is; it sounds like the entry point for the C runtime, not the D runtime, which then in turn jumps into the D runtime.

For the future, I'll keep possible changes of the runtime entry point names in mind.

-- Simon