ldc icon indicating copy to clipboard operation
ldc copied to clipboard

static Windows build

Open ghost opened this issue 2 years ago • 10 comments

Using this program:

import stdio = std.stdio;

void main() {
   stdio.writeln("hello world");
}

and this command:

ldc2 app.d

I do not get a static build. Namely, the file vcruntime140.dll is required. So I tried this:

ldc2 -static app.d

same result. It seems LDC includes the static library:

    Directory: D:\ldc2\lib\mingw

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        2022-07-20  1:10 PM          32542 vcruntime140.lib

so it would appear it should be possible to do what I am trying to do.

ghost avatar Sep 23 '23 13:09 ghost

You need a Visual C++ installation, then the MSVC runtime can be linked statically (and is by default for non-DLLs). See the 2nd-last paragraph in README.txt.

kinke avatar Sep 24 '23 09:09 kinke

have you guys considered using another Windows DLL, thats already pre installed? this would solve the issue of having to download a redistributable, or even having to install the full Visual Studio or whatever.

this is whats done by the Go programming language, as well as Rust. this is the one thing keeping me from getting into D development, because this detail makes distributing D programs harder than other languages.

ghost avatar Sep 24 '23 11:09 ghost

Oh, it's you again.

kinke avatar Sep 24 '23 13:09 kinke

have you guys considered using another Windows DLL, thats already pre installed? this would solve the issue of having to download a redistributable, or even having to install the full Visual Studio or whatever.

this is whats done by the Go programming language, as well as Rust. this is the one thing keeping me from getting into D development, because this detail makes distributing D programs harder than other languages.

I think it's a license issue iirc. Do you know how Go and Rust solves it?

But the easiest fix is to just have a Visual C++ installation on your system.

Imperatorn avatar Oct 27 '23 05:10 Imperatorn

I carried out some tests using ldc2 + zig cc (replacing clang-cl) [target msvc] and got this result:

https://gist.github.com/kassane/2a181fa4dfe66dbd283f3ad7a941ca2b

kassane avatar Nov 02 '23 22:11 kassane

Iirc the licensing is tricky. That's why you need the vc redist.

Imperatorn avatar Nov 02 '23 22:11 Imperatorn

someone finds something similar to Xwin that ALSO downloads the Microsoft compiler.

https://github.com/mstorsjo/msvc-wine?tab=readme-ov-file#use-with-clanglld-in-msvc-mode

kassane avatar Nov 03 '23 10:11 kassane

https://github.com/mstorsjo/msvc-wine?tab=readme-ov-file#use-with-clanglld-in-msvc-mode

this doesn't seem to be any better than the option presented in the Gist. it just seems to use Clang to compile instead of Zig, which I would guess is actually a larger download. so unless I am misunderstanding, the Gist option while not great, seems to be the best option currently.

3052 avatar Nov 03 '23 23:11 3052

I agree. Currently, the Zig toolchain has become convenient due to its small size and facilitation.

If LDC chose MinGW, Zig also offers native integration (currently, default target), although it does not have winpthreads included.

However the dependencies below are statically binary linked. This occurs with zig c++, but not functional for msvc.

What was presented in the gist would be something nostdlib++.

C ABI src: https://github.com/ziglang/zig/tree/master/lib/libc/mingw

C++ ABI/C++EH ABI src: https://github.com/ziglang/zig/tree/master/lib/libcxx src: https://github.com/ziglang/zig/tree/master/lib/libunwind

I don't know how BetterC supports disabling d_runtime. But Zig also has a custom compiler runtime (ziglang does not have an lib ABI).

LLVM-libcompiler-rt rewritten in zig. src: https://github.com/ziglang/zig/tree/master/lib/compiler_rt

kassane avatar Nov 03 '23 23:11 kassane

OK after talking with Martin Storsjö, it seems vsdownload.py does download the Microsoft compiler as well, so that might actually be a better option than the Gist

3052 avatar Nov 04 '23 15:11 3052