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
…#4750)
  • Loading branch information
kinke authored and adamdruppe committed Sep 20, 2024
1 parent f1ed8e5 commit f1171f0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ldc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# LDC master

#### Big news
- Frontend, druntime and Phobos are at version [2.110.0](https://dlang.org/changelog/2.110.0.html). (#4707, #4737, #4749)
- LLVM for prebuilt packages bumped to v18.1.8 (incl. macOS arm64). (#4712)
- 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 ldc/driver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,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 ldc/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 f1171f0

Please sign in to comment.