Skip to content

[WASM] Add minimal support for targeting wasm32-unknown-unknown-wasm. #20684

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

Closed

Conversation

ddunbar
Copy link
Contributor

@ddunbar ddunbar commented Nov 20, 2018

  • This is nothing beyond preventing the compiler from rejecting this target
    triple.

  • There doesn't yet appear to be a well-defined convention around a triple
    which detects WASM based on an "OS" field, so we use the "wasm" indicator in
    the environment component.

 - This is nothing beyond preventing the compiler from rejecting this target
   triple.

 - There doesn't yet appear to be a well-defined convention around a triple
   which detects WASM based on an "OS" field, so we use the "wasm" indicator in
   the environment component.
@ddunbar ddunbar requested a review from DougGregor November 20, 2018 18:29
@ddunbar
Copy link
Contributor Author

ddunbar commented Nov 20, 2018

@swift-ci please smoke test

@gottesmm
Copy link
Contributor

This needs tests.

@ddunbar
Copy link
Contributor Author

ddunbar commented Nov 20, 2018

@gottesmm it isn’t worth adding tests yet because nothing works until a few more patches land. Also, we have entire platforms (Haiku) with no discernible tests. 😛

One it starts to work, this will be implicitly covered by real tests that actually cover interesting behavior.

@gottesmm
Copy link
Contributor

@ddunbar I think the example of Haiku is irrelevant to this. That to me is a weak argument to not add a test. And the driver accepting a triple /is/ interesting behavior. The specific test that I would like to be added is something that shows the driver can parse the triple and not fail. Consider the following command line:

Michaels-MacBook-Pro-8:tmp gottesmm$ xcrun swiftc -target wasm32-unknown-unknown-wasm test.swift -c -###
<unknown>:0: error: unknown target 'wasm32-unknown-unknown-wasm'

With your change, this should no longer fail, no? That is the test I am asking for (one for 32 and one for 64).

@ddunbar
Copy link
Contributor Author

ddunbar commented Nov 20, 2018

@gottesmm sure, I could add that, but I really don't think it adds much value for a platform and level of support that is incredibly experimental and might change. I do think having an end-to-end test once it is possible to actually compile something is useful, and at that point it will basically cover the same code. Testing before then just to me feels like testing the exact implementation.

If you are super passionate about it I will add it though! 🤷‍♂️

@gottesmm
Copy link
Contributor

I would be fine with that as long as you have a test of some sort relatively soon (maybe something that produces sil or llvm-ir). If Haiku truly doesn't have any tests (as you say), it is unfortunate and something that we should attempt to avoid for wasm.

@MaxDesiatov
Copy link
Contributor

Hi @ddunbar @DougGregor, is there anything that prevents this PR from being merged? Thanks!

@@ -192,6 +192,8 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
addPlatformConditionValue(PlatformConditionKind::OS, "PS4");
else if (Target.isOSHaiku())
addPlatformConditionValue(PlatformConditionKind::OS, "Haiku");
else if (Target.isOSBinFormatWasm())
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that we should use the OSBinFormat check here. The problem is that WASM supports both ELF and WASM as object file formats, so if someone does wasm-unknown-none-elf that is going to give an error. I think that we can check if the "architecture" is wasm, and use that to indicate that we are targeting WASM.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not anymore.

But I agree that the 'os' platform condition shouldn't be determined by the file format. If we're going to present wasm as an OS, I think it should be a kind of "default" we use when the triple's arch is wasm32/64 and the OS & vendor are both unknown. It's not exactly the same, but IMO that would be closer to what clang does.

@turbolent
Copy link

Hi @ddunbar @DougGregor again, is there anything that prevents this PR from being merged? It's been another month. Thank you!

@gottesmm
Copy link
Contributor

I am against this even more than before. There has been no movement on this PR which suggests to me that any tests that were said to be added for this will not be coming in a timely way. This PR should have some sort of tests. Maybe that means we should wait until we can write an actual test for this to land...

@turbolent
Copy link

How does one add such a test?

@CodaFi
Copy link
Contributor

CodaFi commented Nov 18, 2019

@turbolent I think a simple test would be the one in test/Misc/target_cpu.swift. Even if WASM targets don't have a coherent notion of CPU for the unknown part of the triple, the CHECK line will at least not match the error we emit for an unknown triple if you write it correctly

error: unknown target 'wasm32-unknown-unknown-wasm'

I'm going to hold this PR open for the time being, but if there's no movement here in a while I'm going to close it out and convert it into an SR for another contributor to pick up and take over the goal line.

@MaxDesiatov
Copy link
Contributor

@CodaFi can #27860 be considered as this same work picked up by another contributor? It also has tests added

@CodaFi
Copy link
Contributor

CodaFi commented Dec 2, 2019

Yeah, definitely. Now that LLVM supports wasi in triples, we don't need this.

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.

8 participants