Fail to build hello-world example with emscripten following bazel tutorial

70 views
Skip to first unread message

Tsvi Sabo

unread,
May 20, 2019, 5:01:32 AM5/20/19
to emscripten-discuss
Following this tutorial:
And after fixing some of the configuration's paths,
i manage to build a really simple `hello-world` `c` file, but when i follow the example completely, and include some cpp headers such as <ctime>, i get the following:

"In file included from /home/tsvi/IOTA_DEV/entangled/hello-world.cc:2:
In file included from external/emscripten_toolchain/system/include/libcxx/iostream:38:
In file included from external/emscripten_toolchain/system/include/libcxx/ios:216:
external/emscripten_toolchain/system/include/libcxx/__locale:417:32: error: use of undeclared identifier '_CTYPE_S'
    static const mask space  = _CTYPE_S;"


So, i am guessing, it might be using wrong include paths of clang after all?
How do i fix this?
Thanks

Floh

unread,
May 20, 2019, 5:39:04 AM5/20/19
to emscripten-discuss
Wow, that looks overly complicated (I guess that's Bazel's fault).

If you are on a Mac, the easiest way to get a working emscripten environment is via homebrew:

> brew install emscripten

On Linux, check whether the emscripten SDK is provided by your distro's package manager, otherwise (or if on Windows), follow the steps described here to install the emscripten SDK:


...and to test whether this worked, write a small hello.c:

#include <stdio.h>
int main() {
    printf("Hello World!\n");
    return 0;
}

...then run:

> emcc hello.c -o hello.html
...

..this should produce 3 files: hello.html, hello.js and hello.wasm

...to test whether the produced application works:

> emrun hello.html
Starting browser: open http://localhost:6931/hello.html
...

...this should open the system's default browser and show the emscripten standard demo page, at the bottom of the page there should be a "Hello World!" message in a text output field.

From there, move to more complex stuff. But I would move to build systems only when you're sure that the emscripten installation itself works.

Build systems just add more things that can go wrong, and the additional "obfuscation layer" (which the build systems add on top of the compiler toolchain) can make it harder to find the actual problems.

Cheers,
-Floh.

Tsvi Sabo

unread,
May 20, 2019, 5:55:52 AM5/20/19
to emscripte...@googlegroups.com
Thanks a lot for your reply, will try it, but the reason i was using the Bazel to pull and build emscripten rather than installing
the SDK is that i would like to have a Bazel target which i can build with emscripten on any platform,
you think that's possible?

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/9cff3f50-bee1-43ac-be9b-f7076024d47e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

IOTA Foundation
c/o Nextland
Strassburgerstraße 55
10405 Berlin, Germany

Board of Directors: Sergey Ivancheglo, Serguei Popov, Ralf Rottmann, Dominik Schiener, David Sønstebø

ID/Company No.: 3416/1234/2

Tsvi Sabo

unread,
May 20, 2019, 7:05:54 AM5/20/19
to emscripte...@googlegroups.com
I think i might have a hint for how to solve it,
I am missing some standard library files, and there's a way to generate those running:
"python embuilder.py build dlmalloc libcxx libc gl libcxxabi libcxx_noexcept wasm-libc"
from `external/emscripten_toolchain`
but when i do that, i get:

embuilder:INFO: building and verifying dlmalloc
embuilder:INFO: ...success
embuilder:INFO: building and verifying libcxx
embuilder:ERROR: unfamiliar build target: libcxx

Any idea?

Tsvi Sabo

unread,
May 20, 2019, 7:26:18 AM5/20/19
to emscripte...@googlegroups.com
An update in case anyone was looking into it,
`cxx` changed to `c++` and `wasm-libc` to `libc-wasm` so a correct way to run the script now is:

`python embuilder.py build dlmalloc libc++ libc gl libc++abi libc++_noexcept libc-wasm`




Tsvi Sabo

unread,
May 20, 2019, 8:40:35 AM5/20/19
to emscripte...@googlegroups.com
Tried to add to the `cc_toolchain_config.bzl` the missing include dir as `-isystem` flag,

Now i get this:

cache:INFO: generating system library: libc-extras.bc... (this will be cached in "/home/tsvi/.emscripten_cache/asmjs/libc-extras.bc" for subsequent builds)
Traceback (most recent call last):
  File "external/emscripten_toolchain/emcc.py", line 3308, in <module>
    sys.exit(run(sys.argv))
  File "external/emscripten_toolchain/emcc.py", line 1776, in run
    extra_files_to_link += system_libs.calculate([f for _, f in sorted(temp_files)] + extra_files_to_link, in_temp, stdout_=None, stderr_=None, forced=forced_stdlibs)
  File "/home/tsvi/.cache/bazel/_bazel_tsvi/9194043dbd55a599c9568f5a8b5663c8/external/emscripten_toolchain/tools/system_libs.py", line 757, in calculate
    add_library(lib)
  File "/home/tsvi/.cache/bazel/_bazel_tsvi/9194043dbd55a599c9568f5a8b5663c8/external/emscripten_toolchain/tools/system_libs.py", line 718, in add_library
    libfile = shared.Cache.get(name, do_create)
  File "/home/tsvi/.cache/bazel/_bazel_tsvi/9194043dbd55a599c9568f5a8b5663c8/external/emscripten_toolchain/tools/cache.py", line 135, in get
    shutil.copyfile(temp, cachename)
  File "/usr/lib/python2.7/shutil.py", line 97, in copyfile
    with open(dst, 'wb') as fdst:
IOError: [Errno 30] Read-only file system: '/home/tsvi/.emscripten_cache/asmjs/libc-extras.bc'
Target //:helloworld.js failed to build
Use --verbose_failures to see the command lines of failed build steps.

Floh

unread,
May 20, 2019, 9:04:24 AM5/20/19
to emscripten-discuss
Hmm, AFAIK those libraries you are building manually via embuilder.py should be built automatically when running emcc for the first time to build a program (basically emcc detects that some runtime libraries are missing, or are outdated, and builds them "on the fly").

Your last error (IOError: [Errno 30] Read-only file system: '/home/tsvi/.emscripten_cache/asmjs/libc-extras.bc') looks like emcc wants to build one of those required runtime libraries, but it can't because it doesn't have write-access permissions to the .emscripten_cache directory in your home directory.

Do you have some "unusual" Linux environment where write-access to the home directory is restricted? Or is bazel running as another user?

Maybe similar permission errors also caused other problems earlier, and that's why the bazel tutorial failed.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.

Tsvi Sabo

unread,
May 20, 2019, 9:22:23 AM5/20/19
to emscripte...@googlegroups.com
Thanks Floh,
seems like adding 
the above mentioned -isystem flag does seem to work after all, rebuilt after clean without any errors the `hello-world` example, also i got no special env but i'm worried about the write permission error,
However, now i happen to stumble upon something really weird,
When i try to separate the example to a header and source file, it does not build successfully,

I now get:

ERROR: /home/tsvi/IOTA_DEV/entangled/common/BUILD:8:1: Linking of rule '//common:errors' failed (Exit 1): false 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 \
  /bin/false rcsD bazel-out/asmjs-fastbuild/bin/common/liberrors.a bazel-out/asmjs-fastbuild/bin/common/_objs/errors/errors.o)
Execution platform: @bazel_tools//platforms:host_platform
Target //common:errors failed to build



To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.

IOTA Foundation
c/o Nextland
Strassburgerstraße 55
10405 Berlin, Germany

Board of Directors: Sergey Ivancheglo, Serguei Popov, Ralf Rottmann, Dominik Schiener, David Sønstebø

ID/Company No.: 3416/1234/2

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/1f8ccc46-13e3-44c7-950c-d67d6f708f14%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Floh

unread,
May 20, 2019, 1:06:29 PM5/20/19
to emscripten-discuss
...I don't know how to read such obfuscated bazel error messages sorry ;) It could be about a build target called "errors", which would produce a library file "liberrors.a" from an object file "errors.o" which fails somehow, but that looks like a problem with the build system, not emscripten.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.

IOTA Foundation
c/o Nextland
Strassburgerstraße 55
10405 Berlin, Germany

Board of Directors: Sergey Ivancheglo, Serguei Popov, Ralf Rottmann, Dominik Schiener, David Sønstebø

ID/Company No.: 3416/1234/2

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages