Skip to content

Use emsdk on travis for CI #5087

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

Closed
wants to merge 17 commits into from
Closed

Use emsdk on travis for CI #5087

wants to merge 17 commits into from

Conversation

kripken
Copy link
Member

@kripken kripken commented Mar 27, 2017

See #4794

@kripken
Copy link
Member Author

kripken commented Mar 27, 2017

Maybe this can't be done, we are hitting

/home/travis/build/kripken/emscripten/emsdk-portable/clang/e1.37.9_64bit/llc: relocation error: /home/travis/build/kripken/emscripten/emsdk-portable/clang/e1.37.9_64bit/llc: symbol _ZNKSt3_V214error_category10_M_messageB5cxx11Ei, version GLIBCXX_3.4.21 not defined in file libstdc++.so.6 with link time reference

Perhaps the 16.04-built SDK can't be run on the 12.04 or 14.04 that is on travis?

@dschuff
Copy link
Member

dschuff commented Mar 27, 2017

Yeah this looks like a symbol versioning issue of the sort that is likely to arise if you build on a newer system than the one you want to run on. There are a couple of ways you might try to get around that. You can link with -static-libstdc++ which will statically link libstdc++ into the binaries. You can do what we did in the NaCl compiler, which was to build our own libc++ and dynamically link against that (we did that because the libstdc++ on 12.04 was too old to build LLVM anyway, but it also avoids duplicating the libc++ bits in every binary). But you are still liable to have the same problem with glibc, and you can't statically link that. What we do for PNaCl today is build in a sysroot, the same one that's used for shipping Chrome on Linux. (it's based on Debian Jesse IIRC). That takes a bit of work to set up (maybe you could just steal ours?) but works quite well and means that you don't have to care so much about the system libs on the build system, but will get a binary that runs predictably everywhere (where "everywhere" can be controlled by selecting the libs in the sysroot).

Dockerfile Outdated
RUN ls
RUN ./emcc # first use
RUN ./emcc -v # check s tuff
RUN python tests/runner.py test_hello_world
Copy link
Contributor

Choose a reason for hiding this comment

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

Right now this Docker file will consume 11 layers, it will be better to make it look like:

RUN apt-get update \
&&    apt-get install -y python wget cmake \
&&    wget https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-portable.tar.gz \
&&    tar -xvf emsdk-portable.tar.gz \
&&    cd emsdk-portable \
&&    ./emsdk update \
&&    ./emsdk install latest \
&&    ./emsdk activate latest \
&&    ls \
&&    ./emcc \
&&    ./emcc -v \
&&    \
&&    python tests/runner.py test_hello_world

It's important, because each RUN creates a snapshot. Especially step where you install latest will expand size of the image

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! I am just starting to learn about Docker now ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

Please note that I wrote this comment, before you pushed some change with 27a227f

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I've pushed a bunch of commits like that just for debugging, but I saw which commit you meant with the comment. Should be fixed now.

@kripken
Copy link
Member Author

kripken commented Mar 27, 2017

@dschuff thanks, meanwhile I am trying to run 16.04 using docker. so far no luck there either.

@kripken
Copy link
Member Author

kripken commented Mar 27, 2017

Ok, I think I'm stuck at the point of docker starting to work, but the emsdk doesn't seem to just download a binary, it wants to run cmake and I guess install from source - which fails but shouldn't be necessary.

I filed emscripten-core/emsdk#69 , hopefully @juj can help.

@kripken
Copy link
Member Author

kripken commented Mar 29, 2017

Disabling travis for now, as @juj is on vacation and travis gives emails on each branch as failing.

@weitjong
Copy link
Contributor

I have setup Travis CI successfully to build Emscripten and Binaryen from source using emsdk. The build artifacts works correctly on Travis CI (Ubuntu 12.04). If you are interested, this is how we do it.

https://github.com/urho3d/emscripten-sdk/tree/sdk-update-trigger

It has the "extra" bit (like building the clang-tool-extra and storing of build artifacts for later use by other CI build jobs) that you may not need and can be safely removed for your case. Also I set it up to build on demand (manual trigger) instead of as continuous integration build, but there should be no problem to make it so. The build is relatively fast (after the initial build) with the help from ccache.

Let me know if you need more information.

@kripken
Copy link
Member Author

kripken commented Apr 17, 2017

Thanks @weitjong. I was hoping to use the emsdk to avoid building from source, as emsdk now has binary downloads. But sounds like with ccache it's fast? But does the ccache work across different travis instantiations? I thought they were isolated from each other, but I understand little here...

@weitjong
Copy link
Contributor

The cache objects are automatically uploaded to S3 at the end of the CI job before the VM ends and restored from S3 at the beginning of the next CI job after a new VM starts. When the cache hits is higher than the cache miss, the build from source just whizzes by regardless of how complex the source code is. And this is usually true for CI build job where the code changes incrementally.

For the initial build when there is still no cache objects available then it may take longer than 50 minutes (time limit for free Travis-CI account). We handle that situation by "continuation". That is, we time-out the build process gracefully instead of being killed by Travis. This way we have the chance to save whatever cache objects we have so far in the initial build, then the next CI build can restore them and "continue" from there. Eventually when cache is warmed up, all the subsequent CI jobs will be relatively fast (the build time is a function of the code delta).

@kripken
Copy link
Member Author

kripken commented Apr 18, 2017

Oh wow, nice use of travis + S3. Maybe we'll need to do something similar, but I'm hoping we can figure out the issues and be able to use the binaries, avoiding building entirely.

@weitjong
Copy link
Contributor

Just want to clearify. The restoring/saving from/to S3 is part of Travis cache service and it is absolutely free. We just need to learn how to take advantage of it.

As for reusing the the prebuilt binary from emsdk on Travis worker VM, I think it would be tough to pull off unless juj also prebuild one specifically for Ubuntu 12.04 (or 14.04 if you plan just use "trusty" VM image for your CI).

@satoshinm
Copy link
Contributor

Ubuntu 12.04 LTS is nearing EOL soon and 14.04 LTS in a few years (source: https://en.wikipedia.org/wiki/Ubuntu_version_history#Table_of_versions), is it possible to update your CI system to the latest LTS version, 16.04?

Don't know how to do it on Travis CI (if it is possible), but if it is helpful here's what I am doing on a different continuous integration service, CircleCI, to run the downloaded binary emsdk on Ubuntu 16.04 LTS (Xenial Xerus): satoshinm/NetCraft@1066b1b

@weitjong
Copy link
Contributor

I think this is rather off topic now. But still, this is my two cents. I suppose when that time comes, Travis-CI will phase out their "precise" VM image and set the "trusty" as the new default and probably the "xenial" will be made available. For those that could not wait, of course they can always use roll-your-own docker approach. The topic of the discussion here is about how to get a "working" binary for the Travis-CI now today, whether the binary is prebuilt or or build from source just before it being used in the following CI tests. To me, build from source has the advantage. The CI tests are always tested against the latest binary. The binary itself is always guaranteed to be compatible with the Travis-CI VM. It is future proof because as the LTS version is changed, so does the binary.

@juj
Copy link
Collaborator

juj commented Jun 15, 2017

Emsdk does have precompiled SDK builds for Linux, which are made using Ubuntu 16.04. I wonder if the -static-libstdc++ flag is the one that would still be needed though for the precompiled builds to work?

@kripken
Copy link
Member Author

kripken commented Jun 16, 2017

I believe -static-libstdc++ was what was recommended in another thread on this, yes.

@cosinusoidally
Copy link

You can get the precompiled binaries from emsdk to work on Trusty by grabbing a copy of libstdc++ from the ubuntu-toolchain-r ppa and then using LD_LIBRARY_PATH

First note that emcc fails to run on Trusty (this is Emscripten 1.37.16):

trusty)ljw@localhost:~/src/emsdk/emsdk-portable$ source emsdk_set_env.sh 
(trusty)ljw@localhost:~/src/emsdk/emsdk-portable$ emcc
WARNING:root:(Emscripten: unknown: cannot concatenate 'str' and 'NoneType' objects, clearing cache)
CRITICAL:root:Could not verify LLVM version: argument of type 'NoneType' is not iterable
/home/ljw/src/emsdk/emsdk-portable/clang/e1.37.16_64bit/llc: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /home/ljw/src/emsdk/emsdk-portable/clang/e1.37.16_64bit/llc)
/home/ljw/src/emsdk/emsdk-portable/clang/e1.37.16_64bit/llc: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by /home/ljw/src/emsdk/emsdk-portable/clang/e1.37.16_64bit/llc)
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: need more than 1 value to unpack)
===========================================================================
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:failing sanity checks due to previous fastcomp failure

I then grab libstdc++ from ubuntu-toolchain-r and put it in my LD_LIBRARY_PATH . Note you should verify the sha256 sum is correct (instructions on how to do this are on https://groups.google.com/d/msg/emscripten-discuss/g5K8ypWjhZk/OclLysu1DQAJ)

(trusty)ljw@localhost:~/src/emsdk/emsdk-portable$ mkdir libstdc++
(trusty)ljw@localhost:~/src/emsdk/emsdk-portable$ ls
binaryen-tags.txt  emscripten                emsdk          emsdk_env.sh         libstdc++                 llvm-tags-32bit.txt  README.md
clang              emscripten-nightlies.txt  emsdk.bat      emsdk_manifest.json  llvm-nightlies-32bit.txt  llvm-tags-64bit.txt  zips
emcmdprompt.bat    emscripten-tags.txt       emsdk_env.bat  emsdk_set_env.sh     llvm-nightlies-64bit.txt  node
(trusty)ljw@localhost:~/src/emsdk/emsdk-portable$ cd libstdc++/
(trusty)ljw@localhost:~/src/emsdk/emsdk-portable/libstdc++$ wget "http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu/pool/main/g/gcc-5/libstdc++6_
5.1.0-0ubuntu11~10.04.2_amd64.deb"
--2017-08-03 19:12:24--  http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu/pool/main/g/gcc-5/libstdc++6_5.1.0-0ubuntu11~10.04.2_amd64.deb
Resolving ppa.launchpad.net (ppa.launchpad.net)... 91.189.95.83
Connecting to ppa.launchpad.net (ppa.launchpad.net)|91.189.95.83|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 525688 (513K) [application/x-debian-package]
Saving to: ‘libstdc++6_5.1.0-0ubuntu11~10.04.2_amd64.deb’

100%[=============================================================================================================>] 525,688     1.03MB/s   in 0.5s   

2017-08-03 19:12:25 (1.03 MB/s) - ‘libstdc++6_5.1.0-0ubuntu11~10.04.2_amd64.deb’ saved [525688/525688]

(trusty)ljw@localhost:~/src/emsdk/emsdk-portable/libstdc++$ sha256sum libstdc++6_5.1.0-0ubuntu11~10.04.2_amd64.deb 
3742f82b49b214f03c3531dd63be860ee63409788497f1b368cd465cabb5ec1c  libstdc++6_5.1.0-0ubuntu11~10.04.2_amd64.deb
(trusty)ljw@localhost:~/src/emsdk/emsdk-portable/libstdc++$ # at this point you should actually verify that sha256 sum is correct
(trusty)ljw@localhost:~/src/emsdk/emsdk-portable/libstdc++$ ar xv libstdc++6_5.1.0-0ubuntu11~10.04.2_amd64.deb 
x - debian-binary
x - control.tar.gz
x - data.tar.gz
(trusty)ljw@localhost:~/src/emsdk/emsdk-portable/libstdc++$ tar xf data.tar.gz 
(trusty)ljw@localhost:~/src/emsdk/emsdk-portable/libstdc++$ cd usr/lib/
(trusty)ljw@localhost:~/src/emsdk/emsdk-portable/libstdc++/usr/lib$ export LD_LIBRARY_PATH=${PWD}
(trusty)ljw@localhost:~/src/emsdk/emsdk-portable/libstdc++/usr/lib$ emcc
WARNING:root:no input files

@rajsite
Copy link

rajsite commented Aug 3, 2017

@cosinusoidally since the deb is just being extracted does that mean your approach runs on container (sudo: false) builds?

@cosinusoidally
Copy link

@rajsite should do. I extract the deb and use LD_LIBRARY_PATH to avoid needing to install the deb (it would also be a very bad idea to install that deb since it would replace the system copy of libstdc++, which can break your system).

Having said that, I have not tested the above workaround on Travis. I've only tested on my Desktop installation. I assume you would just need to tweak your .travis.yml to download the deb, check the sha256sum, extract it somewhere, and then add it to your LD_LIBRARY_PATH .

@weitjong
Copy link
Contributor

weitjong commented Aug 4, 2017

As mentioned before, our approach is to prebuild the EMSDK on Travis CI itself and store the prebuilt artifact in a GitHub repo to be quickly restored and activated in our CI build. We have updated all our CI builds to use Trusty. No issue so far.

https://github.com/urho3d/emscripten-sdk

@saschanaz
Copy link
Collaborator

What's the main blocker on this PR? It seems the last error is Could not run CMake, perhaps it has not been installed?, probably installing CMake will fix this.

@kripken
Copy link
Member Author

kripken commented Sep 5, 2017

Probably the main thing here is that this needs someone with time to look at it. I started this PR but I don't have time myself currently, would be great if someone else wants to.

@kkimdev
Copy link
Contributor

kkimdev commented Jan 26, 2018

Should we close this PR?

@kripken
Copy link
Member Author

kripken commented Jan 26, 2018

Thanks, yes, this was an earlier attempt that failed.

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.

10 participants