emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.91k stars 3.32k forks source link

error: unknown target triple 'asmjs-unknown-emscripten', please use -triple or -arch #2166

Closed warrenseine closed 10 years ago

warrenseine commented 10 years ago

This error just appeared on code that used to work, I guess this is related to fastcomp being enabled by default.

I'm using:

Should I use custom LLVM builds even if I don't need fastcomp?

kripken commented 10 years ago

We should document this better, sorry for the confusion. What is happening is that fastcomp also has a new target, but that is not in the stock 3.3 builds. You can however both disable fastcomp and use the old target, with

EMCC_FAST_COMPILER=0 EMCC_LLVM_TARGET=le32-unknown-nacl emcc [..]
kripken commented 10 years ago

On second thought, we should just use the old triple when fastcomp is disabled. So you should not need to change the triple as well when disabling it. I'll make that change now.

Thanks for filing this, somehow I missed this particular case.

kripken commented 10 years ago

Pushed.

tsvisabo commented 5 years ago

Using emscripten-1.38.27 and still getting this error when compiling a simple "hello-world.cc" file as in this example: https://docs.bazel.build/versions/master/tutorial/cc-toolchain-config.html

I am using Bazel and created an emcc.sh file that do the follows:

"#!/bin/bash

set -euo pipefail

export LLVM_ROOT='external/emscripten_clang' export EMSCRIPTEN_NATIVE_OPTIMIZER='external/emscripten_clang/optimizer' export BINARYEN_ROOT='external/emscripten_clang/' export NODE_JS='' export EMSCRIPTEN_ROOT='external/emscripten_toolchain' export SPIDERMONKEY_ENGINE='' export EM_EXCLUSIVE_CACHE_ACCESS=1 export EMCC_SKIP_SANITY_CHECK=1 export EMCC_WASM_BACKEND=0 export EM_BUILD_VERBOSE=3

python external/emscripten_toolchain/emcc.py "$@"

find . -name "*.d" -exec sed -i '2d' {} \;"

sbc100 commented 5 years ago

Can you print the full command line and the full output?

The first thing I would do is remove EMCC_SKIP_SANITY_CHECK. By settings this you are skipping over the check the emscripten does on the version of llvm you have in external/emscripten_clang. Most likely you have the wrong version there.

You can also remove EMCC_WASM_BACKEND and EMSCRIPTEN_ROOT (the former is a internal-only setting, the latter is completely ignored).

tsvisabo commented 5 years ago

Of course, and thanks for your reply! Command line is bazel's build command: "bazel build --sandbox_debug --verbose_failures --spawn_strategy=standalone --crosstool_top=//toolchain:emscripten --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --cpu=asmjs //:helloworld.js"

And this is the output: "ERROR: /home/tsvi/IOTA_DEV/entangled/BUILD:6:1: C++ compilation of rule '//:helloworld.js' failed (Exit 1): emcc.sh failed: error executing command (cd /home/tsvi/.cache/bazel/_bazel_tsvi/9194043dbd55a599c9568f5a8b5663c8/execroot/org_iota_entangled && \ exec env - \ PATH=/home/tsvi/.local/share/umake/bin:/home/tsvi/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin:/home/tsvi/go:/home/tsvi/go/bin:/home/tsvi/.go/bin \ PWD=/proc/self/cwd \ toolchain/emcc.sh -MD -MF bazel-out/asmjs-fastbuild/bin/_objs/helloworld.js/hello-world.d '-frandom-seed=bazel-out/asmjs-fastbuild/bin/_objs/helloworld.js/hello-world.o' -iquote . -iquote bazel-out/asmjs-fastbuild/genfiles -iquote bazel-out/asmjs-fastbuild/bin -iquote external/bazel_tools -iquote bazel-out/asmjs-fastbuild/genfiles/external/bazel_tools -iquote bazel-out/asmjs-fastbuild/bin/external/bazel_tools -isystem external/emscripten_toolchain/system/include/libcxx -isystem external/emscripten_toolchain/system/include/libc '-std=c++1z' -c hello-world.cc -o bazel-out/asmjs-fastbuild/bin/_objs/helloworld.js/hello-world.o) Execution platform: @bazel_tools//platforms:host_platform error: unknown target triple 'asmjs-unknown-emscripten', please use -triple or -arch shared:ERROR: compiler frontend failed to generate LLVM bitcode, halting Target //:helloworld.js failed to build"

Removing both EMSCRIPTEN_ROOT and EMCC_WASM_BACKEND indeed does not change the output,

sbc100 commented 5 years ago

The key error here is fastcomp in use, but LLVM has not been built with the JavaScript backend as a target, llc reports: llc reports: (no targets could be identified: [Errno 2] No such file or directory)

This means its having trouble running llc from external/emscripten_clang/llc .. does this file exist? We should probably make the error nicer when it can't find llc at all.

tsvisabo commented 5 years ago

Seems like this binary file exists under: /.cache/bazel/_bazel_tsvi/9194043dbd55a599c9568f5a8b5663c8/external/emscripten_clang

tsvisabo commented 5 years ago

Ok, when removing EMCC_SKIP_SANITY_CHECK i get:

"WARNING:root:LLVM version appears incorrect (seeing "6.0", expected "4.0") INFO:root:Blocking on process 15373: ['/usr/bin/nodejs', '/home/tsvi/.cache/bazel/_bazel_tsvi/9194043dbd55a599c9568f5a8b5663c8/external/emscripten_toolchain/src/hello_world.js'] until it finishes. INFO:root:Process 15373 finished after 0.0422451496124 seconds. Exit code: 0 CRITICAL:root:fastcomp in use, but LLVM has not been built with the JavaScript backend as a target, llc reports: (no targets could be identified: [Errno 2] No such file or directory) CRITICAL:root:you can fall back to the older (pre-fastcomp) compiler core, although that is not recommended, see http://kripken.github.io/emscripten-site/docs/building_from_source/LLVM-Backend.html INFO:root:(Emscripten: Running sanity checks) CRITICAL:root:Cannot find /usr/bin/llvm-link, check the paths in ~/.emscripten " how do i fix that?"

sbc100 commented 5 years ago

I see several problems here.

Firstly: LLVM version appears incorrect (seeing "6.0", expected "4.0"). The seems very suspicious. Emscripen has been expecting version 6.0 of llvm for a long time. This makes me think you might be using a very old version of emscripten. Looks like 1.37.29 was the last version to use llvm 4.0.

Secondly llc cannot be found: (no targets could be identified: [Errno 2] No such file or directory). It tried to discover if was built with JS support by running llc --version but the binary was found.

Check your emscripten version, check your llvm version and check your LLVM_ROOT.

sbc100 commented 5 years ago

Also, BINARYEN_ROOT and LLVM_ROOT don't normally do any thing in the environment. Those are names of the config settings.

In the default-generated .emscripten file they can be overridden using BINARYEN and LLVM in the environment.. but I don't know that your config file look like. You might be better off setting all those value directly in the config rather than trying to use env vars.

tsvisabo commented 5 years ago

So it's checking llvm-link in usr/bin though i do this: export LLVM_ROOT='external/emscripten_clang'

emscripten versions are 1.37.22 for both clang and toolchain, global llvm is 6.0

tsvisabo commented 5 years ago

After using emscripten 1.38.31

I get only this:

shared:CRITICAL: fastcomp in use, but LLVM has not been built with the JavaScript backend as a target, llc reports: (no targets could be identified: [Errno 2] No such file or directory)

sbc100 commented 5 years ago

I recommend setting LLVM_ROOT in the emscripten config file. Setting that in the environment does not work (unless you have code in your config file that reads it out of the environment).

tsvisabo commented 5 years ago

Thanks, that seem to help, Now i get this when Linking:

emcc:WARNING: ignoring unsupported linker flag:-S system_libs:WARNING: retrieving port: binaryen from https://github.com/WebAssembly/binaryen/archive/version_82.zip system_libs:WARNING: unpacking port: binaryen cache:INFO: generating port: binaryen_tag_version_82.txt... (this will be cached in "/home/tsvi/.emscripten_cache/asmjs/binaryen_tag_version_82.txt" for subsequent builds) root:INFO: building port: binaryen shared:ERROR: 'cmake -DCMAKE_BUILD_TYPE=Release .' failed: [Errno 2] No such file or directory system_libs:ERROR: a problem occurred when using an emscripten-ports library. try to runemcc --clear-portsand then run this command again Target //:helloworld.js failed to build

sbc100 commented 5 years ago

Looks like you are missing a cmake installation.

If you are using emsdk then it shouldn't be building binaryen from source. If you are not using emsdk then you can build binaryen yourself and set BINARYEN_ROOT in your config.. or you can let it be auto-compiled. Either way you need cmake installed if you want to build it.

tsvisabo commented 5 years ago

Thanks again, cmake installed, now i get this error from running the emcc.py script:

emcc:WARNING: ignoring unsupported linker flag: -S Traceback (most recent call last): File "external/emscripten_toolchain/emcc.py", line 3308, in sys.exit(run(sys.argv)) File "external/emscripten_toolchain/emcc.py", line 1776, in run extra_files_to_link += systemlibs.calculate([f for , f in sorted(temp_files)] + extra_files_to_link, intemp, stdout=None, stderr_=None, forced=forced_stdlibs) File "/home/tsvi/.cache/bazel/_bazel_tsvi/9194043dbd55a599c9568f5a8b5663c8/external/emscripten_toolchain/tools/system_libs.py", line 594, in calculate symbolses = shared.Building.parallel_llvm_nm([os.path.abspath(t) for t in temp_files]) File "/home/tsvi/.cache/bazel/_bazel_tsvi/9194043dbd55a599c9568f5a8b5663c8/external/emscripten_toolchain/tools/shared.py", line 1712, in parallel_llvm_nm object_contents = pool.map(g_llvm_nm_uncached, files) File "/usr/lib/python2.7/multiprocessing/pool.py", line 253, in map return self.map_async(func, iterable, chunksize).get() File "/usr/lib/python2.7/multiprocessing/pool.py", line 572, in get raise self._value OSError: [Errno 2] No such file or directory

tsvisabo commented 5 years ago

Also, running emcc -version yields:

"cache:INFO: generating system asset: is_vanilla.txt... (this will be cached in "/home/tsvi/.emscripten_cache/is_vanilla.txt" for subsequent builds) cache:INFO: - ok shared:ERROR: 'external/emscripten_clang/clang++ --version' failed: [Errno 2] No such file or directory"

tsvisabo commented 5 years ago

Well, in any case, configuration problem is solved by fixing paths of BINARYEN_ROOT and LLVM_ROOT, but still remain to be solved, if i am trying to compile an hello-world example that includes , i get: "external/emscripten_toolchain/system/include/libcxx/__locale:418:32: error: use of undeclared identifier '_CTYPE_R' "

StevenSYT commented 4 years ago

Well, in any case, configuration problem is solved by fixing paths of BINARYEN_ROOT and LLVM_ROOT, but still remain to be solved, if i am trying to compile an hello-world example that includes , i get: "external/emscripten_toolchain/system/include/libcxx/__locale:418:32: error: use of undeclared identifier '_CTYPE_R' "

I am following the tutorial too, this is due to the flag_groups are not properly set. I tried this flag_groups from tensorflow tfjs and it worked for me.

toolchain_include_directories_feature = feature(
        name = "toolchain_include_directories",
        enabled = True,
        flag_sets = [
            flag_set(
                actions = all_compile_actions,
                flag_groups = [
                    flag_group(
                        flags = [
                            "-isystem",
                            "external/emsdk/emsdk/upstream/emscripten/system/include/libcxx",
                            "-isystem",
                            "external/emsdk/emsdk/upstream/emscripten/system/lib/libcxxabi/include",
                            "-isystem",
                            "external/emsdk/emsdk/upstream/emscripten/system/include/compat",
                            "-isystem",
                            "external/emsdk/emsdk/upstream/emscripten/system/include",
                            "-isystem",
                            "external/emsdk/emsdk/upstream/emscripten/system/include/libc",
                            "-isystem",
                            "external/emsdk/emsdk/upstream/emscripten/system/lib/libc/musl/arch/emscripten",
                            "-isystem",
                            "external/emsdk/emsdk/upstream/emscripten/system/local/include",
                        ],
                    ),
                ],
            ),
        ],
    )