Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emscripten: Predefine versions as for a regular musl Linux platform #4750

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}