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

Compiling for WebAssembly uses host file extensions #1749

Closed
skoppe opened this issue Aug 7, 2019 · 5 comments
Closed

Compiling for WebAssembly uses host file extensions #1749

skoppe opened this issue Aug 7, 2019 · 5 comments

Comments

@skoppe
Copy link
Contributor

skoppe commented Aug 7, 2019

System information

  • dub version: (e.g. dub 1.15.0)
  • OS Platform and distribution: cross-platform
  • compiler version (e.g. ldc2-1.16.0 2.086.1)

Bug Description

Dub isn't aware of the webassembly target and uses host file extensions for static libraries and the final binary. On windows this means the static libraries are named .lib, while ldc expect wasm libraries to have the .a extensions, and the final binary is named .exe. On Linux the final binary has no .wasm extension.

How to reproduce?

  • install ldc2 >= 1.15.0
  • ensure ldc2 --version shows wasm32 target (I use dlang2/ldc-ubuntu:1.16.0 docker image)
  • start empty dub project
  • replace app.d with this:
extern(C) void _start() {}
  • and dub.sdl with this:
name "wasm-file-extension"
description "A minimal D application."
authors "Sebastiaan Koppe"
copyright "Copyright © 2019, Sebastiaan Koppe"
license "proprietary"
buildRequirements "allowWarnings"
dflags "-mtriple=wasm32-unknown-unknown-wasm" "-betterC" "-fvisibility=hidden"
configuration "library" {
targetType "library"
}
configuration "executable" {
targetType "executable"
}
  • and compile with:

dub build --build=release --config=executable
dub build --build=release --config=library

Expected Behavior

On windows the library config should result in an wasm-file-extension.a file. And the executable config should result in a wasm-file-extension.wasm file.

On linux the executable config should result in a wasm-file-extension.wasm file.

@andre2007
Copy link
Contributor

I think there are different ways to solve this. Either by a new build options "wasm" which would be a rather small fix, or by having a complete solution as described here
#228

@wilzbach
Maybe this could be tackled by AOC as part of the multi language support
(https://forum.dlang.org/thread/fhtfxkidkeaetdkquatn@forum.dlang.org).

@skoppe
Copy link
Contributor Author

skoppe commented Aug 7, 2019

I don't know about a new build option, I feel it doesn't fit the bill. I have to look at the code to really propose something, but a new entry for $ARCH seems to be in the right direction. But I don't yet see how dub can infer we are targeting wasm.

@andre2007
Copy link
Contributor

@skoppe please see this pull request regarding the triple for wasm
#1541

@skoppe
Copy link
Contributor Author

skoppe commented Aug 8, 2019

Yeah, I think using triples works great. Do you know if anybody is moving forward on that? I see several issues going back to 2014 about extending arch or using triples.

@andre2007
Copy link
Contributor

There might be a chance that this year someone will work on AOC on "multi language support for Dub" (https://forum.dlang.org/thread/fhtfxkidkeaetdkquatn@forum.dlang.org).
The triple support in general could be a part of that.

But beside of this I am not aware that someone at the moment is active at all on enhancing dub. If there would be a pull by someone ;) the chances are very very high that it is accepted.

kinke added a commit to kinke/dub that referenced this issue Aug 17, 2019
By simply treating all non-empty strings except for special `x86[_64]`
as `-mtriple` values.
E.g., `dub --arch=wasm32-unknown-unknown-wasm` to cross-compile to
WebAssembly. This dub switch is already used when probing the compiler,
so the build platform detection works as expected.

Also add `wasm` as detected platform and use the .wasm executable file
extension (for ldc2).

This fixes dlang#1749 when moving the `-mtriple` option from the dub config
file to the dub command line.
kinke added a commit to kinke/dub that referenced this issue Aug 17, 2019
By treating all 'architectures' containing a `-` as `-mtriple` values.
E.g., `dub --arch=wasm32-unknown-unknown-wasm` to cross-compile to
WebAssembly. This dub switch is already used when probing the compiler,
so the build platform detection works as expected.

Also add `wasm` as detected platform and use the .wasm executable file
extension (for ldc2).

This fixes dlang#1749 when moving the `-mtriple` option from the dub config
file to the dub command line.
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

No branches or pull requests

2 participants