Skip to content

Commit d1a731a

Browse files
committed
Emscripten: Predefine versions as for a regular Linux musl platform
1 parent d562736 commit d1a731a

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
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 regular musl Linux platform wrt. extra predefined versions (`linux`, `Posix` and `CRuntime_Musl`). (#4750)
910

1011
#### Platform support
1112

driver/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,10 @@ void registerPredefinedTargetVersions() {
923923
break;
924924
case llvm::Triple::Emscripten:
925925
VersionCondition::addPredefinedGlobalIdent("Emscripten");
926+
// Emscripten uses musl, so mimic a musl Linux platform:
927+
VersionCondition::addPredefinedGlobalIdent("linux");
928+
VersionCondition::addPredefinedGlobalIdent("Posix");
929+
VersionCondition::addPredefinedGlobalIdent("CRuntime_Musl");
926930
break;
927931
default:
928932
if (triple.getEnvironment() == llvm::Triple::Android) {

tests/codegen/emscripten.d

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
13+
14+
// verify that some druntime C bindings are importable:
15+
16+
import core.stdc.stdio;
17+
18+
extern(C) void _start() {
19+
puts("Hello world");
20+
}

0 commit comments

Comments
 (0)