ldc icon indicating copy to clipboard operation
ldc copied to clipboard

Implement --cppstdlib

Open omerfirmak opened this issue 3 years ago • 12 comments

This flag allows user to select from GCC/Clang C++ runtimes on Linux similar to --stdlib on clang.

omerfirmak avatar May 02 '21 10:05 omerfirmak

cc @Geod42

This will probably will be implemented upstream too

thewilsonator avatar May 02 '21 13:05 thewilsonator

I think that should be done through mtriple tho, if possible at all ?

Geod24 avatar May 03 '21 14:05 Geod24

AFAICS, llvm::triple does not have support for this. Even clang has a separate flag for it.

omerfirmak avatar May 03 '21 22:05 omerfirmak

Then I guess -cppstdlib it is. What do you think @kinke ?

Geod24 avatar May 04 '21 08:05 Geod24

I'd prefer that this be done upstream and then adapted for LDC as a) DMD will need this too, and b) target.d and the command line processing for target specific things has changed a lot recently and this will only add to that.

thewilsonator avatar May 04 '21 09:05 thewilsonator

I'd prefer that this be done upstream and then adapted for LDC as a) DMD will need this too, and b) target.d and the command line processing for target specific things has changed a lot recently and this will only add to that.

Is there a consensus over this?

omerfirmak avatar May 06 '21 19:05 omerfirmak

Sorry for the late reply, but this PR popped up while I was on vacation. - I'm not a big fan of a new switch, nor of extending the 'triple' in some LDC-specific, non-LLVM-compatible way. Mainly because it's only useful for the few core.stdcpp modules and the according CppRuntime_* versions they require. If it was about linking only, that's already covered via -Xcc=--stdlib=... etc. The problem with the druntime modules is that they are precompiled using a specific CppRuntime_*, so a user cannot simply take a prebuilt LDC package and change the C++ runtime on the fly and expect everything to work; druntime has to be recompiled.

Extracting the few C++ stdlib bindings into a separate dub package, with e.g. dub configurations enabling to switch between libstdc++ and libc++ would IMO make much more sense.

Wrt. triples in general, even a C++ runtime addition wouldn't define a target platform sufficiently. We have to guess the used C compiler (gcc/clang) in some ABI-specific parts, where clang skips empty-struct parameters while gcc doesn't etc.

kinke avatar May 30 '21 16:05 kinke

Sorry for the late reply, but this PR popped up while I was on vacation. - I'm not a big fan of a new switch, nor of extending the 'triple' in some LDC-specific, non-LLVM-compatible way. Mainly because it's only useful for the few core.stdcpp modules and the according CppRuntime_* versions they require. If it was about linking only, that's already covered via -Xcc=--stdlib=... etc. The problem with the druntime modules is that they are precompiled using a specific CppRuntime_*, so a user cannot simply take a prebuilt LDC package and change the C++ runtime on the fly and expect everything to work; druntime has to be recompiled.

Extracting the few C++ stdlib bindings into a separate dub package, with e.g. dub configurations enabling to switch between libstdc++ and libc++ would IMO make much more sense.

I agree about not adding this to the triple. Splitting the stdlib bindings into a separate package makes sense, I think so too, but still requires a compiler change to not set a CppRuntime_* version at all and let the user explicitly -d-version=.. it (e.g. inside ldc2.conf file). Adding a commandline flag or removing the hardcoded CppRuntime_* version (and put it in ldc2.conf by default) are the only short term solutions I see.

JohanEngelen avatar May 30 '21 17:05 JohanEngelen

I fully agree with you guys, but Andrei didn't: https://github.com/dlang/druntime/pull/2286#issuecomment-416704437 I guess I will have to email him.

Geod24 avatar May 31 '21 00:05 Geod24

@kinke : I just found out that no CppRuntime is defined on Musl. Is that on purpose ?

Geod24 avatar Jun 11 '21 08:06 Geod24

Just no idea about the dominant C++ library for musl, uclibc, some BSDs… - I preferred defining none over a wild guess, in the hopes that people using such platforms would notice and open according PRs when trying to use core.stdcpp, instead of seeing crashes if the guess was bad. [Here, just in case: https://github.com/ldc-developers/ldc/blob/780d2966e99ebac168f7bd79ef8f1e5512573fd9/driver/main.cpp#L782]

kinke avatar Jun 11 '21 11:06 kinke

Will do that soon (currently testing https://github.com/bosagora/docker-agora-builder/commit/e7fab4679eaff5c8149665a1385fd0ab4881d76f )

Geod24 avatar Jun 11 '21 11:06 Geod24