emscripten-core / emsdk

Emscripten SDK
http://emscripten.org
Other
3k stars 682 forks source link

(bazel) cc-toolchain-wasm does not have mandatory providers: TemplateVariableInfo #1378

Closed allsey87 closed 4 months ago

allsey87 commented 5 months ago

While wasm_cc_binary works nicely, I feel like I am quite in the dark when it comes to figuring out build a cmake or autotools based project inside of Bazel + Emscripten. For example, I am currently trying to get libffi to build inside Bazel using this script and have come up with the following:

# WORKSPACE
LIBFFI_COMMIT = "f08493d249d2067c8b3207ba46693dd858f95db3"
LIBFFI_BUILD_FILE_CONTENT = """
package(default_visibility = ['//visibility:public'])
filegroup(
    name = "all",
    srcs = glob(["**"]),
)
"""

http_archive(
    name = "libffi_src",
    sha256 = "0c4e5647b79e21b900eb872dd98a3e0a66be12b36ad89677f61fd901a2615778",
    url = "https://github.com/libffi/libffi/archive/{}.tar.gz".format(LIBFFI_COMMIT),
    build_file_content = LIBFFI_BUILD_FILE_CONTENT,
    strip_prefix = "libffi-{}".format(LIBFFI_COMMIT),
)
#BUILD
genrule(
    name = "libffi",
    srcs = ["@libffi_src//:all"],
    cmd = "cd external/libffi_src && ./testsuite/emscripten/build.sh  --wasm-bigint",
    # tools = [
    #     "@emscripten_bin_linux//:compiler_files",
    #     "@emsdk//emscripten_toolchain:compiler_files"
    # ],
    toolchains = ["@emsdk//emscripten_toolchain:cc-toolchain-wasm"],
    outs = ["libffi.a"]
)

However, this is reporting error:

ERROR: /workspaces/builder-bazel/main-emscripten/BUILD:38:8: in toolchains attribute of genrule rule //main-emscripten:libffi: '@@emsdk//emscripten_toolchain:cc-toolchain-wasm' does not have mandatory providers: 'TemplateVariableInfo'
ERROR: /workspaces/builder-bazel/main-emscripten/BUILD:38:8: Analysis of target '//main-emscripten:libffi' failed
ERROR: Analysis of target '//main-emscripten:libffi' failed; build aborted
INFO: Elapsed time: 0.044s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully

Am I do something wrong here or is there an issue with the toolchain configuration?

walkingeyerobot commented 4 months ago

try passing --platforms=@emsdk//:platform_wasm and set the toolchains attribute of your genrule to @bazel_tools//tools/cpp:current_cc_toolchain

allsey87 commented 4 months ago

This works although for completeness, I would add that it doesn't seem like there is a need to pass @bazel_tools//tools/cpp:current_cc_toolchain to the toolchains attribute of the genrule if --platforms=@emsdk//:platform_wasm was already specified.

For the moment, I have just placed build --platforms=@emsdk//:platform_wasm in my .bazelrc since my whole workspace is targeting Emscripten.