Skip to content

emsdk trying to build eigen using emsdk is throwing assert sys.argv[1][0] == '@', sys.argv in link_wrapper.py #1535

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

Open
bakkiraju opened this issue Mar 5, 2025 · 2 comments
Assignees
Labels
bazel Issues related to Bazel toolchain

Comments

@bakkiraju
Copy link

bakkiraju commented Mar 5, 2025

I have the foreign_cc_rules bazel based rule to build eigen like this

maybe(
        http_archive,
        name = "com_gitlab_libeigen_eigen",
        sha256 = "b4c198460eba6f28d34894e3a5710998818515104d6e74e5cc331ce31e46e626",
        strip_prefix = "eigen-3.4.0",
        urls = [
            "https://jfrog.goriv.co/artifactory/gitlab-mirror/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.bz2",
            "https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.bz2",
        ],
        build_file_content =
            """
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")

filegroup(
    name = "eigen_all",
    srcs = glob(["**"]),
)

cmake(
    name = "eigen",
    lib_source = ":eigen_all",
    out_headers_only = True,
    out_include_dir = "include/eigen3",
    alwayslink = True,
    install = True,
    visibility = ["//visibility:public"],
)
""",
    )

when I try to build it with emsdk, i see link_wrapper.py throwing assertion shown below, is emsdk supposed to work with foreign_rules ?

> _____ BEGIN BUILD LOGS _____
> 
> Bazel external C/C++ Rules. Building library eigen
> 
> Environment:______________
> BUILD_SCRIPT=bazel-out/wasm-fastbuild-ST-b4dbd4a2bfc4/bin/external/com_gitlab_libeigen_eigen/eigen_foreign_cc/build_script.sh
> EXT_BUILD_ROOT=/home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware
> BUILD_LOG=bazel-out/wasm-fastbuild-ST-b4dbd4a2bfc4/bin/external/com_gitlab_libeigen_eigen/eigen_foreign_cc/CMake.log
> PWD=/home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware
> BUILD_WRAPPER_SCRIPT=bazel-out/wasm-fastbuild-ST-b4dbd4a2bfc4/bin/external/com_gitlab_libeigen_eigen/eigen_foreign_cc/wrapper_build_script.sh
> TMPDIR=/tmp
> EXT_BUILD_DEPS=/home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/bazel-out/wasm-fastbuild-ST-b4dbd4a2bfc4/bin/external/com_gitlab_libeigen_eigen/eigen.ext_build_deps
> NODE_JS_PATH=external/nodejs_linux_amd64/bin/node
> GOPROXY=jfrog.goriv.co/artifactory/rivian-golang-remote
> BUILD_TMPDIR=/home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/bazel-out/wasm-fastbuild-ST-b4dbd4a2bfc4/bin/external/com_gitlab_libeigen_eigen/eigen.build_tmpdir
> SHLVL=2
> EM_CONFIG_PATH=external/emscripten_cache/emscripten_config
> EM_BIN_PATH=external/emscripten_bin_linux
> INSTALLDIR=/home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/bazel-out/wasm-fastbuild-ST-b4dbd4a2bfc4/bin/external/com_gitlab_libeigen_eigen/eigen
> PATH=/home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware:/bin:/usr/bin:/usr/local/bin
> EMCC_WASM_BACKEND=1
> _=/bin/env
> __________________________
> + /home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/external/cmake-3.23.2-linux-x86_64/bin/cmake -DCMAKE_TOOLCHAIN_FILE=/home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/bazel-out/wasm-fastbuild-ST-b4dbd4a2bfc4/bin/external/com_gitlab_libeigen_eigen/eigen.build_tmpdir/crosstool_bazel.cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/bazel-out/wasm-fastbuild-ST-b4dbd4a2bfc4/bin/external/com_gitlab_libeigen_eigen/eigen -DCMAKE_PREFIX_PATH=/home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/bazel-out/wasm-fastbuild-ST-b4dbd4a2bfc4/bin/external/com_gitlab_libeigen_eigen/eigen.ext_build_deps -DCMAKE_RANLIB= -DCMAKE_MAKE_PROGRAM=/home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/bazel-out/k8-opt-exec-2B5CBBC6-ST-3d23eae1a3b9/bin/external/rules_foreign_cc/toolchains/make/bin/make -G 'Unix Makefiles' /home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/external/com_gitlab_libeigen_eigen
> -- The C compiler identification is Clang 21.0.0
> -- The CXX compiler identification is Clang 21.0.0
> -- Detecting C compiler ABI info
> -- Detecting C compiler ABI info - done
> -- Check for working C compiler: /home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/external/emsdk/emscripten_toolchain/emcc.sh - skipped
> -- Detecting C compile features
> -- Detecting C compile features - done
> -- Detecting CXX compiler ABI info
> -- Detecting CXX compiler ABI info - failed
> -- Check for working CXX compiler: /home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/external/emsdk/emscripten_toolchain/emcc.sh
> -- Check for working CXX compiler: /home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/external/emsdk/emscripten_toolchain/emcc.sh - broken
> CMake Error at /home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/external/cmake-3.23.2-linux-x86_64/share/cmake-3.23/Modules/CMakeTestCXXCompiler.cmake:62 (message):
>   The C++ compiler
> 
>     "/home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/external/emsdk/emscripten_toolchain/emcc.sh"
> 
>   is not able to compile a simple test program.
> 
>   It fails with the following output:
> 
>     Change Dir: /home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/bazel-out/wasm-fastbuild-ST-b4dbd4a2bfc4/bin/external/com_gitlab_libeigen_eigen/eigen.build_tmpdir/CMakeFiles/CMakeTmp
>     
>     Run Build Command(s):/home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/bazel-out/k8-opt-exec-2B5CBBC6-ST-3d23eae1a3b9/bin/external/rules_foreign_cc/toolchains/make/bin/make -f Makefile cmTC_72731/fast && /home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/bazel-out/k8-opt-exec-2B5CBBC6-ST-3d23eae1a3b9/bin/external/rules_foreign_cc/toolchains/make/bin/make  -f CMakeFiles/cmTC_72731.dir/build.make CMakeFiles/cmTC_72731.dir/build
>     make[1]: Entering directory '/home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/bazel-out/wasm-fastbuild-ST-b4dbd4a2bfc4/bin/external/com_gitlab_libeigen_eigen/eigen.build_tmpdir/CMakeFiles/CMakeTmp'
>     Building CXX object CMakeFiles/cmTC_72731.dir/testCXXCompiler.cxx.o
>     /home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/external/emsdk/emscripten_toolchain/emcc.sh --sysroot=/home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/external/emscripten_bin_linux/emscripten/cache/sysroot   --sysroot=/home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/external/emscripten_bin_linux/emscripten/cache/sysroot -fdiagnostics-color -fno-exceptions -fno-strict-aliasing -funsigned-char -no-canonical-prefixes -std=gnu++17 -nostdinc -nostdinc++ -fomit-frame-pointer -O0 -Wall -iwithsysroot/include/c++/v1 -iwithsysroot/include/compat -iwithsysroot/include -isystem /home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/external/emscripten_bin_linux/lib/clang/21/include -Wno-builtin-macro-redefined -D__DATE__=\"redacted\" -D__TIMESTAMP__=\"redacted\" -D__TIME__=\"redacted\"  -MD -MT CMakeFiles/cmTC_72731.dir/testCXXCompiler.cxx.o -MF CMakeFiles/cmTC_72731.dir/testCXXCompiler.cxx.o.d -o CMakeFiles/cmTC_72731.dir/testCXXCompiler.cxx.o -c /home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/bazel-out/wasm-fastbuild-ST-b4dbd4a2bfc4/bin/external/com_gitlab_libeigen_eigen/eigen.build_tmpdir/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
>     Linking CXX executable cmTC_72731
>     /home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/external/cmake-3.23.2-linux-x86_64/bin/cmake -E cmake_link_script CMakeFiles/cmTC_72731.dir/link.txt --verbose=1
>     /home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/external/emsdk/emscripten_toolchain/emcc_link.sh --sysroot=/home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/external/emscripten_bin_linux/emscripten/cache/sysroot -fdiagnostics-color -fno-exceptions -fno-strict-aliasing -funsigned-char -no-canonical-prefixes -std=gnu++17 -nostdinc -nostdinc++ -fomit-frame-pointer -O0 -Wall -iwithsysroot/include/c++/v1 -iwithsysroot/include/compat -iwithsysroot/include -isystem /home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/external/emscripten_bin_linux/lib/clang/21/include -Wno-builtin-macro-redefined -D__DATE__=\"redacted\" -D__TIMESTAMP__=\"redacted\" -D__TIME__=\"redacted\"  --sysroot=/home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/external/emscripten_bin_linux/emscripten/cache/sysroot -fdiagnostics-color -fno-strict-aliasing -funsigned-char -no-canonical-prefixes -s PRINTF_LONG_DOUBLE=1 --oformat=js -O0  CMakeFiles/cmTC_72731.dir/testCXXCompiler.cxx.o -o cmTC_72731 
>     Traceback (most recent call last):
>       File "/home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/external/emsdk/emscripten_toolchain/link_wrapper.py", line 25, in <module>
>         assert sys.argv[1][0] == '@', sys.argv
>     AssertionError: ['/home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/external/emsdk/emscripten_toolchain/link_wrapper.py', '--sysroot=/home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/external/emscripten_bin_linux/emscripten/cache/sysroot', '-fdiagnostics-color', '-fno-exceptions', '-fno-strict-aliasing', '-funsigned-char', '-no-canonical-prefixes', '-std=gnu++17', '-nostdinc', '-nostdinc++', '-fomit-frame-pointer', '-O0', '-Wall', '-iwithsysroot/include/c++/v1', '-iwithsysroot/include/compat', '-iwithsysroot/include', '-isystem', '/home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/external/emscripten_bin_linux/lib/clang/21/include', '-Wno-builtin-macro-redefined', '-D__DATE__="redacted"', '-D__TIMESTAMP__="redacted"', '-D__TIME__="redacted"', '--sysroot=/home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/external/emscripten_bin_linux/emscripten/cache/sysroot', '-fdiagnostics-color', '-fno-strict-aliasing', '-funsigned-char', '-no-canonical-prefixes', '-s', 'PRINTF_LONG_DOUBLE=1', '--oformat=js', '-O0', 'CMakeFiles/cmTC_72731.dir/testCXXCompiler.cxx.o', '-o', 'cmTC_72731']
>     make[1]: *** [CMakeFiles/cmTC_72731.dir/build.make:100: cmTC_72731] Error 1
>     make[1]: Leaving directory '/home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/bazel-out/wasm-fastbuild-ST-b4dbd4a2bfc4/bin/external/com_gitlab_libeigen_eigen/eigen.build_tmpdir/CMakeFiles/CMakeTmp'
>     make: *** [Makefile:127: cmTC_72731/fast] Error 2
>     
>     
> 
>   
> 
>   CMake will not be able to correctly generate this project.
> Call Stack (most recent call first):
>   CMakeLists.txt:4 (project)
> 
> 
> -- Configuring incomplete, errors occurred!
> See also "/home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/bazel-out/wasm-fastbuild-ST-b4dbd4a2bfc4/bin/external/com_gitlab_libeigen_eigen/eigen.build_tmpdir/CMakeFiles/CMakeOutput.log".
> See also "/home/ubuntu/.cache/bazel/_bazel_ubuntu/da60117de278b86dbfdc966eb6b65723/sandbox/linux-sandbox/10/execroot/firmware/bazel-out/wasm-fastbuild-ST-b4dbd4a2bfc4/bin/external/com_gitlab_libeigen_eigen/eigen.build_tmpdir/CMakeFiles/CMakeError.log".
> _____ END BUILD LOGS _____
> rules_foreign_cc: Build wrapper script location: bazel-out/wasm-fastbuild-ST-b4dbd4a2bfc4/bin/external/com_gitlab_libeigen_eigen/eigen_foreign_cc/wrapper_build_script.sh
> rules_foreign_cc: Build script location: bazel-out/wasm-fastbuild-ST-b4dbd4a2bfc4/bin/external/com_gitlab_libeigen_eigen/eigen_foreign_cc/build_script.sh
> rules_foreign_cc: Build log location: bazel-out/wasm-fastbuild-ST-b4dbd4a2bfc4/bin/external/com_gitlab_libeigen_eigen/eigen_foreign_cc/CMake.log
> 
@sbc100 sbc100 added the bazel Issues related to Bazel toolchain label Mar 5, 2025
@bakkiraju
Copy link
Author

@walkingeyerobot / @kripken Any other existing examples that build a foreign_rules_cc based bazel target using emsdk ?, want to check if I am missing anything or configuring the toolchain incorrectly. Thanks.

@walkingeyerobot
Copy link
Collaborator

Unfortunately I don't have any experience with foreign_rules_cc. I think I remember someone else experimenting with it or asking about it, but I'm having trouble digging that up and ultimately I don't think they were able to get it to work.

I suspect the script at bazel/emscripten_toolchain/env.sh isn't going to work for foreign_rules_cc. It's intended only for use with the toolchain and the wasm_cc_binary rule provided in this repo. If you want to use foreign_rules_cc, I would avoid using bazel things in this directory and just try to use emcc directly as your compiler and linker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bazel Issues related to Bazel toolchain
Projects
None yet
Development

No branches or pull requests

3 participants