Skip to content

Commit

Permalink
Emscripten: Predefine versions as for a regular Linux musl platform (l…
Browse files Browse the repository at this point in the history
  • Loading branch information
kinke authored Sep 9, 2024
1 parent 58280f5 commit 1f0c36e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Android: NDK for prebuilt package bumped from r26d to r27. (#4711)
- ldc2.conf: %%ldcconfigpath%% placeholder added - specifies the directory where current configuration file is located. (#4717)
- Add support for building against a system copy of zlib through `-DPHOBOS_SYSTEM_ZLIB=ON`. (#4742)
- Emscripten: The compiler now mimicks a musl Linux platform wrt. extra predefined versions (`linux`, `Posix`, `CRuntime_Musl`, `CppRuntime_LLVM`). (#4750)

#### Platform support

Expand Down
6 changes: 6 additions & 0 deletions driver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,12 @@ void registerPredefinedTargetVersions() {
break;
case llvm::Triple::Emscripten:
VersionCondition::addPredefinedGlobalIdent("Emscripten");
// Emscripten uses musl and libc++, so mimic a musl Linux platform:
VersionCondition::addPredefinedGlobalIdent("linux");
VersionCondition::addPredefinedGlobalIdent("Posix");
VersionCondition::addPredefinedGlobalIdent("CRuntime_Musl");
VersionCondition::addPredefinedGlobalIdent("CppRuntime_LLVM");
VersionCondition::addPredefinedGlobalIdent("CppRuntime_Clang"); // legacy
break;
default:
if (triple.getEnvironment() == llvm::Triple::Android) {
Expand Down
21 changes: 21 additions & 0 deletions tests/codegen/emscripten.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// REQUIRES: target_WebAssembly

// RUN: %ldc -mtriple=wasm32-unknown-emscripten -c %s


// test predefined versions:

version (Emscripten) {} else static assert(0);
version (linux) {} else static assert(0);
version (Posix) {} else static assert(0);
version (CRuntime_Musl) {} else static assert(0);
version (CppRuntime_LLVM) {} else static assert(0);


// verify that some druntime C bindings are importable:

import core.stdc.stdio;

extern(C) void _start() {
puts("Hello world");
}

0 comments on commit 1f0c36e

Please sign in to comment.