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

[bazel] Switch to platforms-based toolchain resolution #1036

Merged
merged 4 commits into from
Nov 8, 2022

Conversation

jfirebaugh
Copy link
Contributor

Fixes #984. However, the way I have done it requires --incompatible_enable_cc_toolchain_resolution and no longer supports --crosstool_top=.... I'm not sure how to support both at the same time. If that's necessary, can someone give me pointers on how to do it?

@jfirebaugh
Copy link
Contributor Author

It looks like test-bazel-mac runs a version of bazel that does not include @platforms//cpu:wasm32. I think this is what #766 (comment) was referring to. What's the preferred way to fix this?

@zaucy
Copy link
Contributor

zaucy commented May 21, 2022

@jfirebaugh if you rebase now with #1049 merged in the bazel mac CI should pass!

@jfirebaugh
Copy link
Contributor Author

Done.

Does emsdk need to continue to support both toolchain and non-toolchain (--crosstool_top=...) based resolution?

@walkingeyerobot
Copy link
Collaborator

I'm very sorry I haven't reviewed this yet but I will soon. Thanks very much for the PR!

@walkingeyerobot
Copy link
Collaborator

Ok, this looks great. My one comments is I'd like the bazelrc file restored and to contain the following:

build:wasm --incompatible_enable_cc_toolchain_resolution
build:wasm --platforms=@emsdk//:platform_wasm

I believe this will allow anyone who has a build working with --config=wasm to have their build continue working.

@walkingeyerobot
Copy link
Collaborator

Thanks very much for this!

As this is a breaking change, I'm going to hold off on merging it for just a bit while I figure out how to best communicate this.

@walkingeyerobot
Copy link
Collaborator

Ok, after a bit of testing, it looks like we can support both the old crosstool_top way and the new platforms stuff. If we add back in the transition passing compiler, cpu, and crosstool_top, everything should still work for platforms.

I'm sorry this has been such a lengthy review. This is an excellent change; I just want to be careful so as to break as few users as possible.


load("@emsdk//:toolchains.bzl", "register_emscripten_toolchains")

register_emscripten_toolchains()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can/should we fold these two into a single step?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like other rulesets tend to keep them separate. E.g. rules_go has go_rules_dependencies and go_register_toolchains , rules_nodejs has build_bazel_rules_nodejs_dependencies and node_repositories, rules_rust has rules_rust_dependencies and rust_register_toolchains.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I saw that #1068 spells this emsdk_register_toolchains. Based on other rulesets, it does seem like the prevailing convention is to prefix with the language or toolset, rather than the verb register. However, I would propose that we retain consistency with emscripten_deps, and therefore spell this emscripten_register_toolchains. @walkingeyerobot @jun-sheaf WDYT?

Choose a reason for hiding this comment

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

Hey @jfirebaugh! Your observation is correct. But just some information regarding this, I have upstreamed this to internal already. Hopefully by August I can get the internal toolchain open-sourced.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What does "upstreamed to internal" mean?

Choose a reason for hiding this comment

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

I meant the patch has already been published within Google (the internal repo).

"//command_line_option:custom_malloc": "@emsdk//emscripten_toolchain:malloc",
}

_wasm_transition = transition(
implementation = _wasm_transition_impl,
inputs = [
"//command_line_option:compiler",
"//command_line_option:cpu",
"//command_line_option:crosstool_top",
Copy link
Collaborator

Choose a reason for hiding this comment

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

compiler, cpu, and crosstool_top need to be in outputs, not inputs. They can in fact be removed from inputs as we don't need to read them. This will fix the failing CI

Choose a reason for hiding this comment

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

This will not fix the CI. You need to set the incompatible toolchain flag. See #1060.

@jrandolf
Copy link

Just found this PR. We've been using #1060 for a while internally, so we wanted to upstream those updates. I've noticed this PR misses out on some parts. Specifically, we should label the toolchain as wasm32 (since that is what it is) and also fix the static linker flags. All of this is already done in #1060 (I've also downstreamed some of the changes here to there).
.

@walkingeyerobot
Copy link
Collaborator

Just found this PR. We've been using #1060 for a while internally, so we wanted to upstream those updates. I've noticed this PR misses out on some parts. Specifically, we should label the toolchain as wasm32 (since that is what it is) and also fix the static linker flags. All of this is already done in #1060 (I've also downstreamed some of the changes here to there). .

Thanks for the PR! I'm happy with the state this PR is in (sans the small fix I commented on), so I'd like to get this in before reviewing yours.

@jrandolf
Copy link

Just found this PR. We've been using #1060 for a while internally, so we wanted to upstream those updates. I've noticed this PR misses out on some parts. Specifically, we should label the toolchain as wasm32 (since that is what it is) and also fix the static linker flags. All of this is already done in #1060 (I've also downstreamed some of the changes here to there). .

Thanks for the PR! I'm happy with the state this PR is in (sans the small fix I commented on), so I'd like to get this in before reviewing yours.

I'd recommend taking a look at #1060 before moving forward with this one. There are some non-trivial fixes there and also improvements to the implementation. We also want it upstreamed sooner so we can check back out to @emsdk/main.

@sbc100 sbc100 changed the title Switch to platforms-based toolchain resolution [bazel] Switch to platforms-based toolchain resolution Jun 17, 2022
@jfirebaugh
Copy link
Contributor Author

jfirebaugh commented Jun 18, 2022 via email

@jfirebaugh
Copy link
Contributor Author

jfirebaugh commented Aug 19, 2022

Ping @walkingeyerobot -- I've made the requested changes.

@HappyCerberus
Copy link

Hi, I tried using this patch, but run into a problem. I had to comment out this from emscripten_deps.bzl:

    if "emscripten_bin_mac_arm64" not in excludes:
        http_archive(
            name = "emscripten_bin_mac_arm64",
            strip_prefix = "install",
            url = emscripten_url.format("mac", revision.hash, "-arm64", "tbz2"),
            sha256 = revision.sha_mac_arm64,
            build_file_content = BUILD_FILE_CONTENT_TEMPLATE.format(bin_extension = ""),
            type = "tar.bz2",
        )

Without removing it I was getting the following error:

                sha256 = revision.sha_mac_arm64,
Error: 'struct' value has no field or method 'sha_mac_arm64'
Available attributes: hash, sha_linux, sha_mac, sha_win

@jfirebaugh
Copy link
Contributor Author

@HappyCerberus Are you sure it's related to this patch? It looks like you're using an emscripten version that doesn't provide an arm64 macOS build. Judging by revisions.bzl, 3.1.2 was the first version that supported it:

emsdk/bazel/revisions.bzl

Lines 124 to 136 in c220895

"3.1.2": struct(
hash = "6626e25d6d866cf283147ca68d54ac9326fe399f",
sha_linux = "4fb53364a2ba1de8978445aa26b2204bfd215b41da5d7df04f231040b197010a",
sha_mac = "a8e347accb1ff402d96a128912ac8cda1731611c9f89095fee0ad39a6a18bbc3",
sha_mac_arm64 = "4374f5c852d0403b0a3b0e9dc8a3856a340e9d82ecf0f20aa8b36c6179d31fc8",
sha_win = "e96f6ab8252fefa42f461676311d4c4e2d96fdc2e876ece07d9d7a49ef31aef0",
),
"3.1.1": struct(
hash = "5ee64de9809592480da01372880ea11debd6c740",
sha_linux = "ba94c5ecabacbedc89665a742c37c4c132c739aea46aa66fd744cb72b260c870",
sha_mac = "8b5f8cec55af0e6816a08d8d1e8b873f96d0e0504fdd6e8deb2fc024957d1aa7",
sha_win = "6cbe976aff6155cf1c48707f0520b5aa6a7770860e9b1964bfca3e5923ce7225",
),

@HappyCerberus
Copy link

@jfirebaugh Thanks. I did not realize this was it. Retested and it works now.

Perhaps would make sense to remove the older revisions from the revisions file, since the code doesn't work with them anyway?

@walkingeyerobot
Copy link
Collaborator

It's been awhile, and I apologize for that. I would like to get this merged. If you could please rebase so that we can get CI to pass (I think that's the problem anyway) then we can go ahead and merge.

Fixes emscripten-core#984. However, this requires `--incompatible_enable_cc_toolchain_resolution` and no longer supports `--crosstool_top=...`. I'm not sure how to support both at the same time.
@walkingeyerobot walkingeyerobot enabled auto-merge (squash) November 8, 2022 22:08
@dschuff dschuff disabled auto-merge November 8, 2022 22:19
@dschuff dschuff merged commit 0050633 into emscripten-core:main Nov 8, 2022
@jfirebaugh jfirebaugh deleted the jfirebaugh/fix-984 branch November 8, 2022 22:27
lewing pushed a commit to dotnet/emsdk that referenced this pull request Feb 7, 2023
* [bazel] Set CLOSURE_COMPILER to workaround RBE+symlinks issue (emscripten-core#1037)

* [bazel] Set CLOSURE_COMPILER to workaround RBE+symlinks issue

* space

* specify node_js

* 3.1.10 (emscripten-core#1046)

* Optimize sandbox performance (emscripten-core#1045)

* Optimize sandbox performance

Link just the files needed to compile, link, or archive, rather than the entire directory tree. This drastically improves build times on macOS, where the sandbox is known to be slow (bazelbuild/bazel#8230).

* Linux wants clang to link

* all_files not needed?

* Linux wants llc

* And llvm-ar

* Templated build_file_content

* include node modules glob with linker files. also some minor formatting fixes. (emscripten-core#1052)

* Using bazelisk on macOS CI (emscripten-core#1049)

* Explicit outputs for wasm_cc_binary (emscripten-core#1047)

* Explicit outputs for wasm_cc_binary

* Backwards compatibility

* data_runfiles restore

* restore test_bazel.sh

* Using wrong path on accident

* two separate rules for legacy support

* Added name attribute to wasm_cc_binary rule

* 3.1.11 (emscripten-core#1053)

* 3.1.12 (emscripten-core#1054)

* 3.1.13 (emscripten-core#1055)

* [bazel] Add additional files necessary for building with closure and on RBE (emscripten-core#1057)

* 3.1.14 (emscripten-core#1061)

* 3.1.15 (emscripten-core#1066)

* Pin `latest` to a specific version for arm64-linux (emscripten-core#1065)

Fixes: emscripten-core#1040

* 3.1.16 (emscripten-core#1071)

* 3.1.17 (emscripten-core#1076)

* Exclude msys from path fix function. (emscripten-core#1078)

Fixes: #911

* 3.1.18 (emscripten-core#1081)

* 3.1.18

* Update LLVM include path in Bazel files

* Version 3.1.18-2 (emscripten-core#1083)

3.1.18 had a bad release binary on ARM64 Mac so push an updated version of the release.

* 3.1.19 (emscripten-core#1090)

* Add EMSDK_QUIET to make emsdk_env less chatting (emscripten-core#1091)

Without this the recommended way to silence emsdk_env was to pipe its
stderr to /dev/null.. but then you also loose potentially useful error
message.

Fixes: #946

* 3.1.20 (emscripten-core#1095)

* Add double-quotes to allow spaces in path (emscripten-core#1097)

* 3.1.21 (emscripten-core#1101)

* Update latest-arm64-linux to 3.1.21 (emscripten-core#1102)

* Update XCode version on CircleCI (emscripten-core#1103)

12.2 is being deprecated

* 3.1.22 (emscripten-core#1107)

* 3.1.23 (emscripten-core#1111)

* Avoid exporting EM_CONFIG for modern SDK versions (emscripten-core#1110)

Newer versions of emscipten, starting all the way back in 1.39.13, can
automatically locate the `.emscripten` config file that emsdk creates so
there is no need for the explicit EM_CONFIG environment variable.  Its
redundant and adds unnessary noisce/complexity.

Really, adding emcc to the PATH is all the is needed these days.

One nice thing about this change is that it allows folks to run
whichever emcc they want to and have it just work, even if they have
configured emsdk.   Without this change, if I activate emsdk and I run
`some/other/emcc` then emsdk's `EM_CONFIG` will still be present and
override the configuration embedded in `some/other/emcc`.

e.g. in the same shell, with emsdk activated, I can run both these
commands and have them both just work as expected.

```
$ emcc --version
$ /path/to/my/emcc --version
```

* Use x64 version for Windows on Arm (emscripten-core#1115)

* 3.1.24 (emscripten-core#1122)

* 3.1.25 (emscripten-core#1130)

* [bazel] Switch to platforms-based toolchain resolution (emscripten-core#1036)

* remove "name" attribute from bazel rules (emscripten-core#1131)

* 3.1.26 (emscripten-core#1134)

* Update remote_docker version in CircleCI config (emscripten-core#1117)

20.10.17 is the current default.

* docker image: Change base to Ubuntu 22.04 LTS (jammy) (emscripten-core#1135)

Done to upgrade from CMake 3.16.3 to 3.22.1. CMake 3.21 or newer is needed to build the Qt 6.4.1 sources with emscripten.

Also update to libidn12 to resolve an "Unable to locate package libidn11" error.

* 3.1.27 (emscripten-core#1139)

* Use constants for fixed paths. NFC (emscripten-core#1140)

* Add standalone_wasm feature to bazel emscripten_toolchain (emscripten-core#1145)

* 3.1.28 (emscripten-core#1149)

* Upgrade to rules_nodejs 5.8.0 (emscripten-core#1150)

Fixes emscripten-core#1020

* 3.1.29 (emscripten-core#1160)

* Pin Windows CI to Bazel 5.4.0 (emscripten-core#1163)

* Remove reference to fastcomp-latest. NFC (emscripten-core#1164)

fastcomp can only be install using explicit versions names so this name
doesn't work.

* Remove fastcomp SDK and fastcomp build rules. NFC (emscripten-core#1165)

Folks that want to work with fastcomp will now need to use an older
checkout of emsdk.

* 3.1.30 (emscripten-core#1167)

* Bump emscripten to 3.1.30

* Bump clang version

* Do not include test directory

* Update eng/emsdk.proj

Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com>

---------

Co-authored-by: Kevin Lubick <kjlubick@users.noreply.github.com>
Co-authored-by: Sam Clegg <sbc@chromium.org>
Co-authored-by: John Firebaugh <john.firebaugh@gmail.com>
Co-authored-by: walkingeyerobot <mitch@thefoley.net>
Co-authored-by: Ezekiel Warren <zaucy@users.noreply.github.com>
Co-authored-by: Heejin Ahn <aheejin@gmail.com>
Co-authored-by: Tim Ebbeke <Tim06TR@gmail.com>
Co-authored-by: Derek Schuff <dschuff@chromium.org>
Co-authored-by: Joel Van Eenwyk <joel.vaneenwyk@gmail.com>
Co-authored-by: Pierrick Bouvier <101587250+pbo-linaro@users.noreply.github.com>
Co-authored-by: Trevor Hickey <TrevorJamesHickey@gmail.com>
Co-authored-by: Fredrik Orderud <forderud@users.noreply.github.com>
Co-authored-by: Robbert van Ginkel <570934+robbertvanginkel@users.noreply.github.com>
Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com>
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.

Bazel: @emsdk is broken with --incompatible_enable_cc_toolchain_resolution
7 participants