Skip to content

Conversation

@owenv
Copy link
Contributor

@owenv owenv commented Oct 17, 2020

This is an initial implementation of a WebAssembly toolchain. It shares a lot of similarities with the GenericUnixToolchain, but it doesn't support dynamic libraries and other features like sanitizers, profiling, etc. Overall, there are enough differences that trying to subclass GenericUnixToolchain seemed potentially error-prone.

The functionality in this PR goes a bit beyond the current Wasm support in the main Swift repo. I tested this change by installing swift-driver into a toolchain snapshot from the SwiftWasm fork and then verifying I could compile a basic working program.

@owenv
Copy link
Contributor Author

owenv commented Oct 17, 2020

@swift-ci please test

Comment on lines 16 to 22
// On ELF/WASM platforms there's no built in autolinking mechanism, so we
// pull the info we need from the .o files directly and pass them as an
// argument input file to the linker.
// FIXME: Also handle Cygwin and MinGW
guard inputs.count > 0 && targetTriple.objectFormat == .elf && lto == nil else {
guard inputs.count > 0 &&
[.elf, .wasm].contains(targetTriple.objectFormat) &&
lto == nil else {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

From what I understand we probably won't need autolink-extract for Wasm long-term, but this is pretty harmless in the meantime

public func makeLinkerOutputFilename(moduleName: String, type: LinkOutputType) -> String {
switch type {
case .executable:
return moduleName
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure if this should always have the .wasm extension

@owenv owenv requested review from DougGregor and artemcm October 17, 2020 18:35
@owenv
Copy link
Contributor Author

owenv commented Oct 17, 2020

@owenv owenv marked this pull request as ready for review October 17, 2020 18:41
Copy link
Contributor

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

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

Fantastic, thank you for implementing this!

@owenv
Copy link
Contributor Author

owenv commented Oct 17, 2020

@swift-ci please test

@owenv
Copy link
Contributor Author

owenv commented Oct 17, 2020

@swift-ci please test

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

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

Woah, cool! Splitting this out from the generic Unix toolchain seems to make sense here

@owenv
Copy link
Contributor Author

owenv commented Oct 18, 2020

The latest push fixes a small merge conflict, but otherwise there aren't any changes

@swift-ci please test

@owenv owenv merged commit 6dc8b16 into swiftlang:main Oct 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants