Skip to content

Commit 1f0c36e

Browse files
authored
Emscripten: Predefine versions as for a regular Linux musl platform (#4750)
1 parent 58280f5 commit 1f0c36e

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Android: NDK for prebuilt package bumped from r26d to r27. (#4711)
77
- ldc2.conf: %%ldcconfigpath%% placeholder added - specifies the directory where current configuration file is located. (#4717)
88
- Add support for building against a system copy of zlib through `-DPHOBOS_SYSTEM_ZLIB=ON`. (#4742)
9+
- Emscripten: The compiler now mimicks a musl Linux platform wrt. extra predefined versions (`linux`, `Posix`, `CRuntime_Musl`, `CppRuntime_LLVM`). (#4750)
910

1011
#### Platform support
1112

driver/main.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,12 @@ void registerPredefinedTargetVersions() {
923923
break;
924924
case llvm::Triple::Emscripten:
925925
VersionCondition::addPredefinedGlobalIdent("Emscripten");
926+
// Emscripten uses musl and libc++, so mimic a musl Linux platform:
927+
VersionCondition::addPredefinedGlobalIdent("linux");
928+
VersionCondition::addPredefinedGlobalIdent("Posix");
929+
VersionCondition::addPredefinedGlobalIdent("CRuntime_Musl");
930+
VersionCondition::addPredefinedGlobalIdent("CppRuntime_LLVM");
931+
VersionCondition::addPredefinedGlobalIdent("CppRuntime_Clang"); // legacy
926932
break;
927933
default:
928934
if (triple.getEnvironment() == llvm::Triple::Android) {

tests/codegen/emscripten.d

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// REQUIRES: target_WebAssembly
2+
3+
// RUN: %ldc -mtriple=wasm32-unknown-emscripten -c %s
4+
5+
6+
// test predefined versions:
7+
8+
version (Emscripten) {} else static assert(0);
9+
version (linux) {} else static assert(0);
10+
version (Posix) {} else static assert(0);
11+
version (CRuntime_Musl) {} else static assert(0);
12+
version (CppRuntime_LLVM) {} else static assert(0);
13+
14+
15+
// verify that some druntime C bindings are importable:
16+
17+
import core.stdc.stdio;
18+
19+
extern(C) void _start() {
20+
puts("Hello world");
21+
}

0 commit comments

Comments
 (0)