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

Add "Posix" global version conditional for Emscripten targets #4738

Closed
wants to merge 2 commits into from
Closed
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
18 changes: 18 additions & 0 deletions driver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,8 +752,26 @@ void registerPredefinedTargetVersions() {
VersionCondition::addPredefinedGlobalIdent("D_HardFloat");
break;
case llvm::Triple::wasm32:
VersionCondition::addPredefinedGlobalIdent("WebAssembly");
if (triple.getOS() == llvm::Triple::Emscripten) {
// Emscripten reimplements Posix APIs
VersionCondition::addPredefinedGlobalIdent("linux");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linux probably also incorrect?

VersionCondition::addPredefinedGlobalIdent("Posix");
VersionCondition::addPredefinedGlobalIdent("CRuntime_Musl");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this correct? Musl? that is more than just posix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emscripten uses musl, musl is POSIX compliant

Copy link
Member

@kinke kinke Aug 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm interesting. Do you have a link to confirm this? I found emscripten-core/emscripten#13006 which seems to support this.

The proper place to add the musl-compatible predefined versions is

ldc/driver/main.cpp

Lines 921 to 923 in dd0ff1e

case llvm::Triple::Emscripten:
VersionCondition::addPredefinedGlobalIdent("Emscripten");
break;

VersionCondition::addPredefinedGlobalIdent("X86_Any");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

X86 for sure is wrong

VersionCondition::addPredefinedGlobalIdent("X86");
}
break;
case llvm::Triple::wasm64:
VersionCondition::addPredefinedGlobalIdent("WebAssembly");
if (triple.getOS() == llvm::Triple::Emscripten) {
// Emscripten reimplements Posix APIs
VersionCondition::addPredefinedGlobalIdent("linux");
VersionCondition::addPredefinedGlobalIdent("Posix");
VersionCondition::addPredefinedGlobalIdent("CRuntime_Musl");
VersionCondition::addPredefinedGlobalIdent("X86_Any");
VersionCondition::addPredefinedGlobalIdent("X86_64");
}
break;
#if LDC_LLVM_VER >= 1600
case llvm::Triple::loongarch32:
Expand Down