Skip to content

Commit

Permalink
Emscripten: Predefine versions as for a regular Linux musl platform
Browse files Browse the repository at this point in the history
  • Loading branch information
kinke committed Sep 8, 2024
1 parent d562736 commit d1a731a
Show file tree
Hide file tree
Showing 3 changed files with 25 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 regular musl Linux platform wrt. extra predefined versions (`linux`, `Posix` and `CRuntime_Musl`). (#4750)

#### Platform support

Expand Down
4 changes: 4 additions & 0 deletions driver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,10 @@ void registerPredefinedTargetVersions() {
break;
case llvm::Triple::Emscripten:
VersionCondition::addPredefinedGlobalIdent("Emscripten");
// Emscripten uses musl, so mimic a musl Linux platform:
VersionCondition::addPredefinedGlobalIdent("linux");
VersionCondition::addPredefinedGlobalIdent("Posix");
VersionCondition::addPredefinedGlobalIdent("CRuntime_Musl");
break;
default:
if (triple.getEnvironment() == llvm::Triple::Android) {
Expand Down
20 changes: 20 additions & 0 deletions tests/codegen/emscripten.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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);


// verify that some druntime C bindings are importable:

import core.stdc.stdio;

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

0 comments on commit d1a731a

Please sign in to comment.