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

Improve dub interop with webassembly #3004

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

LunaTheFoxgirl
Copy link

Adds missing wasm platform and arch specifiers for wasm32, wasm64 and emscripten.

Copy link

github-actions bot commented Mar 8, 2025

✅ PR OK, no changes in deprecations or warnings

Total deprecations: 0

Total warnings: 0

Build statistics:

 statistics (-before, +after)
 executable size=5334536 bin/dub
-rough build time=60s
+rough build time=61s
Full build output
DUB version 1.39.0-beta.1, built on Dec 15 2024
LDC - the LLVM D compiler (1.40.0):
  based on DMD v2.110.0 and LLVM 19.1.3
  built with LDC - the LLVM D compiler (1.40.0)
  Default target: x86_64-unknown-linux-gnu
  Host CPU: znver3
  http://dlang.org - http://wiki.dlang.org/LDC


  Registered Targets:
    aarch64     - AArch64 (little endian)
    aarch64_32  - AArch64 (little endian ILP32)
    aarch64_be  - AArch64 (big endian)
    amdgcn      - AMD GCN GPUs
    arm         - ARM
    arm64       - ARM64 (little endian)
    arm64_32    - ARM64 (little endian ILP32)
    armeb       - ARM (big endian)
    avr         - Atmel AVR Microcontroller
    bpf         - BPF (host endian)
    bpfeb       - BPF (big endian)
    bpfel       - BPF (little endian)
    hexagon     - Hexagon
    lanai       - Lanai
    loongarch32 - 32-bit LoongArch
    loongarch64 - 64-bit LoongArch
    mips        - MIPS (32-bit big endian)
    mips64      - MIPS (64-bit big endian)
    mips64el    - MIPS (64-bit little endian)
    mipsel      - MIPS (32-bit little endian)
    msp430      - MSP430 [experimental]
    nvptx       - NVIDIA PTX 32-bit
    nvptx64     - NVIDIA PTX 64-bit
    ppc32       - PowerPC 32
    ppc32le     - PowerPC 32 LE
    ppc64       - PowerPC 64
    ppc64le     - PowerPC 64 LE
    r600        - AMD GPUs HD2XXX-HD6XXX
    riscv32     - 32-bit RISC-V
    riscv64     - 64-bit RISC-V
    sparc       - Sparc
    sparcel     - Sparc LE
    sparcv9     - Sparc V9
    spirv       - SPIR-V Logical
    spirv32     - SPIR-V 32-bit
    spirv64     - SPIR-V 64-bit
    systemz     - SystemZ
    thumb       - Thumb
    thumbeb     - Thumb (big endian)
    ve          - VE
    wasm32      - WebAssembly 32-bit
    wasm64      - WebAssembly 64-bit
    x86         - 32-bit X86: Pentium-Pro and above
    x86-64      - 64-bit X86: EM64T and AMD64
    xcore       - XCore
    xtensa      - Xtensa 32
   Upgrading project in /home/runner/work/dub/dub/
    Starting Performing "release" build using /opt/hostedtoolcache/dc/ldc2-1.40.0/x64/ldc2-1.40.0-linux-x86_64/bin/ldc2 for x86_64.
    Building dub 1.39.0-rc.1+commit.42.g23206a02: building configuration [application]
     Linking dub
STAT:statistics (-before, +after)
STAT:executable size=5334536 bin/dub
STAT:rough build time=61s

@kassane
Copy link

kassane commented Mar 8, 2025

Wouldn't it be enough to use ldc2 triple target for now?

With this new target being added, would it affect pre/pos commands build?

I even commented on the need to run commands through dub for the wasm32/64 or emscripten target.

@LunaTheFoxgirl
Copy link
Author

Wouldn't it be enough to use ldc2 triple target for now?

With this new target being added, would it affect pre/pos commands build?

I even commented on the need to run commands through dub for the wasm32/64 or emscripten target.

* [Cross-compiling should use host platform for pre/post commands #2664 (comment)](https://github.com/dlang/dub/issues/2664#issuecomment-2661096178)

It'll only affect platform specifications, making them actually work. Since before you couldn't make a configuration exclusive to eg. wasm32 or wasm64, or exclusive to emscripten.

@LunaTheFoxgirl LunaTheFoxgirl changed the title Add missing wasm platform+arch specifiers Improve dub interop with webassembly Mar 8, 2025
@LunaTheFoxgirl
Copy link
Author

Okay, this PR is growing a bit in size, wasm32 and wasm64 only works with relocatable objects, so added a case to ensure this when compiling with the object target type.

@LunaTheFoxgirl
Copy link
Author

Wouldn't it be enough to use ldc2 triple target for now?

With this new target being added, would it affect pre/pos commands build?

I even commented on the need to run commands through dub for the wasm32/64 or emscripten target.

* [Cross-compiling should use host platform for pre/post commands #2664 (comment)](https://github.com/dlang/dub/issues/2664#issuecomment-2661096178)

So despite the extra updates; this does not add any new arch types, all it does is handle the result from the triple better by conforming to wasm requirements (such as objects being relocatable, wasm32 and wasm64 having slightly different linker flags, etc.)

// as wasm-ld only works on relocatable objects.
if (p.canFind("wasm")) {
settings.addDFlags("--disable-linker-strip-dead");
settings.addLFlags("-r");
Copy link
Member

Choose a reason for hiding this comment

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

this doesn't quite seem like the right place to add the dflags per platform, since there is also no other such check here, but I haven't been able to check the code in other compiler wrappers here yet, perhaps consider just disregarding this comment

Copy link
Author

Choose a reason for hiding this comment

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

This requirement only applies to the object target type. Couldn't find anywhere better to put it given that .o files have to be reloctable and can't be section gc'd. If these flags aren't there for the object type then you will be unable to use wasm-ld and/or emscripten to link your module with eg. Emscripten ports or other external libraries.

@WebFreak001
Copy link
Member

I think we should probably add some tests for webassembly as well since it's quite easy to test, would you like to add that in this PR?

Perhaps @Geod24 also has things to say here otherwise LGTM

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