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

Conversation

ryuukk
Copy link
Contributor

@ryuukk ryuukk commented Aug 23, 2024

I just had this thought after seeing this: https://forum.dlang.org/post/[email protected]

Haven't tested yet, but i submit the PR otherwise i'll forget

And i can't compile ldc from source:

cmake -G Ninja ../ -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PWD/../install-ldc

/usr/bin/ld: cannot find -lLLVMSymbolize: No such file or directory

@ryuukk
Copy link
Contributor Author

ryuukk commented Aug 23, 2024

I managed to build ldc from source, and i managed to produce a wasm file with that:

./bin/ldc2 -mtriple=wasm32-emscripten-none -L-allow-undefined bin/app.d

import std;


extern(C) void _start()
{
    writeln("hi");
}

I'll try to do the same with druntime and phobos

// Emscripten reimplements Posix APIs
VersionCondition::addPredefinedGlobalIdent("linux");
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("linux");
VersionCondition::addPredefinedGlobalIdent("Posix");
VersionCondition::addPredefinedGlobalIdent("CRuntime_Musl");
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("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?

@kinke
Copy link
Member

kinke commented Sep 9, 2024

Superseded by #4750.

@kinke kinke closed this Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants