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

0 Members and 1 Guest are viewing this topic.

Online Simon

  • Administrator
  • Posts: 3170
    • 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: 682
  • 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: 682
  • 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: 682
  • 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: 3170
    • 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

Offline Forestidia86

  • Posts: 682
  • inactive
    • View Profile
Re: 64-bit Windows build
« Reply #5 on: March 22, 2021, 08:23:37 PM »
ldc 1.25 has upgraded the linker lld (to v11.0.1) and the upgraded linker lets even Hello World programs fail on Win 7 ('lld-link: error: failed to write the output file: permission denied') and Wine 6.4 ('lld-link: error: failed to write the output file: Path is invalid.'). Win 8.1 seems still fine for building with ldc/lld-link.

See issue at ldc
See issue at LLVM
See possible fix at LLVM(?)
See the upper possible fix at github

See similiar bug at LLVM
« Last Edit: April 01, 2021, 08:08:08 PM by Forestidia86 »

Offline Forestidia86

  • Posts: 682
  • inactive
    • View Profile
Re: 64-bit Windows build
« Reply #6 on: April 02, 2021, 03:58:43 PM »
(One of) the maintainer(s) of ldc doesn't think that the possible fix works for the Win7/Wine issue. See new issue to integrate fix.
I'm not convinced but don't know either. Basically I read that as a wontfix but at some time LLVM will get the upgrade with the possible fix and later it will be so probably integrated in ldc. No clue how long that will take.

I personally haven't gotten the workaround to work with dub. Maybe it could be helpful with dmd in the future in case there the problem occurs as well.

Until version 1.24 ldc should still work for Win 7 and Wine users.
« Last Edit: April 02, 2021, 04:55:03 PM by Forestidia86 »

Offline Forestidia86

  • Posts: 682
  • inactive
    • View Profile
Re: 64-bit Windows build
« Reply #7 on: April 03, 2021, 12:32:48 AM »
It seems that the possible fix will be part of 12.0.0 of LLVM.

Offline Forestidia86

  • Posts: 682
  • inactive
    • View Profile
Re: 64-bit Windows build
« Reply #8 on: April 15, 2021, 09:30:05 PM »
Good news: 12.0.0 of LLVM is released, unclear when it gets part of ldc.

If I have suitable bindings build, I could get Lix to build with a variant of the workaround by integrating in the dub.json file:
Code: [Select]
"dflags-ldc2": ["--linker=lld-link"],probably better:
Code: [Select]
"dflags-windows-x86_64-ldc2": ["--linker=lld-link"],
Unfortunately not any build bindings seem to work. It is tedious even with suitable bindings build.

Each binding that has to be build has its own dub.json.
Building the bindings with ldc 1.25.x went into the problem that the called argument '-lib' seems to override or similiar effect the dflag.
If I copied the command line that 'dub -v' provided and deleted '-lib' it complained about "subsystem must be defined". Maybe the mixing of compiler and linker, maybe sth. else.

I didn't get to work a direct integration of lld-link in the config file of ldc.
« Last Edit: April 15, 2021, 09:43:19 PM by Forestidia86 »

Offline Forestidia86

  • Posts: 682
  • inactive
    • View Profile
Re: 64-bit Windows build
« Reply #9 on: April 30, 2021, 01:32:00 AM »
ldc 1.26 is released and --version still unfortunately says that it is LLVM 11.0.1 based, although they have in their LLVM fork already 1.12.0. Maybe for the next version 1.27.

Offline Forestidia86

  • Posts: 682
  • inactive
    • View Profile
Re: 64-bit Windows build
« Reply #10 on: May 16, 2021, 07:43:09 PM »
Wine v. 6.7 seems to build with LDC 1.25.1, so the LLVM 11.0.1 linker problem only applies to Win 7 in the end.

Offline Forestidia86

  • Posts: 682
  • inactive
    • View Profile
Re: 64-bit Windows build
« Reply #11 on: June 05, 2021, 09:19:56 PM »
Good news: ldc 1.27.0-beta1 is out and based on LLVM 12.0.0.

It works on Win7 and I assume that will apply to older versions of Wine as well.
Edit: It doesn't work for older versions of Wine unfortunately.
« Last Edit: June 09, 2021, 07:03:56 PM by Forestidia86 »