Skip to content

Commit 7053c8e

Browse files
committed
build(emscripten): use docker image via npm scripts
1 parent 3ac5357 commit 7053c8e

File tree

6 files changed

+27
-23
lines changed

6 files changed

+27
-23
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Sass.js is used in the following tools:
4343

4444
* the [sass group](https://github.com/sass), especially [team libsass](https://github.com/sass/libsass)
4545
* team [emscripten](https://github.com/kripken/emscripten), especially [Alon Zakai](https://github.com/kripken)
46+
* [Piotr Paczkowski](https://github.com/trzecieu/) for providing the [emscripten docker image](https://hub.docker.com/r/trzeci/emscripten/)
4647

4748

4849
## License

docs/build.md

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Building Sass.js
22

3-
To compile libsass to JS you need [emscripten](http://emscripten.org), to build Sass.js you also need [grunt](http://gruntjs.com/).
3+
To compile libsass to JS you need [docker](https://www.docker.com/).
44

55

66
## Preparations
@@ -13,17 +13,10 @@ cd sass.js
1313
npm install
1414
```
1515

16-
Install emscripten (using [Home Brew](http://brew.sh/))
17-
18-
```bash
19-
brew install emscripten
20-
```
21-
22-
2316
## Building everything
2417

2518
```bash
26-
grunt build
19+
npm run build
2720

2821
# destination:
2922
# dist/file-size.json
@@ -36,14 +29,14 @@ grunt build
3629

3730
### Assembling files
3831

39-
When working with the Sass.js APIs it is not neccessary to download the libsass repository every time. The `grunt rebuild` command will compile the Sass.js the same way `grunt build` will, except it will expect the repository to already exist.
32+
When working with the Sass.js APIs it is not neccessary to download the libsass repository every time. The `npm run rebuild` command will compile the Sass.js the same way `npm run build` will, except it will expect the repository to already exist.
4033

4134
### Building in emscripten debug mode
4235

4336
This is useful (and necessary) to identify the callstacks required to whitelist for the [Emterpreter](https://github.com/kripken/emscripten/wiki/Emterpreter#emterpreter-async-run-synchronous-code).
4437

4538
```bash
46-
grunt build:debug
39+
npm run build:debug
4740

4841
# destination:
4942
# dist/file-size.json
@@ -60,11 +53,11 @@ When working on the C wrapper it may be unnecessary to build the entire library,
6053

6154
```bash
6255
# import libsass repository
63-
grunt libsass:prepare
56+
npm run libsass:prepare
6457
# invoke emscripten
65-
grunt libsass:build
58+
npm run libsass:build
6659
# invoke emscripten in debug mode
67-
grunt libsass:debug
60+
npm run libsass:debug
6861

6962
# destination:
7063
# libsass/libsass/lib/libsass.js
@@ -73,7 +66,7 @@ grunt libsass:debug
7366

7467
## Loading the source files in the browser
7568

76-
After cloning this repository you can run `grunt libsass:prepare libsass:build` and then run Sass.js off its source files to gain access to all components (emscripten environment, Sass.js components) in the global scope (see [`sass.source.html`](../sass.source.html)):
69+
After cloning this repository you can run `npm run libsass:prepare libsass:build` and then run Sass.js off its source files to gain access to all components (emscripten environment, Sass.js components) in the global scope (see [`sass.source.html`](../sass.source.html)):
7770

7871
```html
7972
<!-- you need to compile libsass.js first using `grunt libsass:prepare libsass:build` -->

grunt-tasks/versions.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ module.exports = function GruntfileVersions(grunt) {
5454
}
5555

5656
var versions = grunt.config.data.versions;
57-
childProcess.exec('emcc --version', function(err, stdout, stderr) {
57+
var command = 'docker run --rm trzeci/emscripten:latest emcc --version'
58+
childProcess.exec(command, function(err, stdout, stderr) {
5859
if (err) {
59-
grunt.log.error('`emcc --version` failed with: ' + err.code + '\n' + stderr);
60+
grunt.log.error('`' + command + '` failed with: ' + err.code + '\n' + stderr);
6061
return;
6162
}
6263

libsass/Makefile.patch

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@
88
+ emcc lib/libsass.a -o lib/libsass.js \
99
+ -O3 \
1010
+ -s EXPORTED_FUNCTIONS="['_sass_compile_emscripten']" \
11-
+ -s EXTRA_EXPORTED_RUNTIME_METHODS=@../exported_runtime_methods.json \
11+
+ -s EXTRA_EXPORTED_RUNTIME_METHODS=@exported_runtime_methods.json \
1212
+ -s WASM=0 \
1313
+ -s DISABLE_EXCEPTION_CATCHING=0 \
1414
+ -s ALLOW_MEMORY_GROWTH=1 \
1515
+ -s LEGACY_VM_SUPPORT=1 \
1616
+ -s EMTERPRETIFY=1 \
1717
+ -s EMTERPRETIFY_ASYNC=1 \
18-
+ -s EMTERPRETIFY_WHITELIST=@../emterpreter_whitelist.json \
18+
+ -s EMTERPRETIFY_WHITELIST=@emterpreter_whitelist.json \
1919
+ --memory-init-file 0
2020
+
2121
+js-debug: static
2222
+ emcc lib/libsass.a -o lib/libsass.js \
2323
+ -O0 \
2424
+ -s EXPORTED_FUNCTIONS="['_sass_compile_emscripten']" \
25-
+ -s EXTRA_EXPORTED_RUNTIME_METHODS=@../exported_runtime_methods.json \
25+
+ -s EXTRA_EXPORTED_RUNTIME_METHODS=@exported_runtime_methods.json \
2626
+ -s WASM=0 \
2727
+ -s DISABLE_EXCEPTION_CATCHING=0 \
2828
+ -s ALLOW_MEMORY_GROWTH=1 \
2929
+ -s LEGACY_VM_SUPPORT=1 \
3030
+ -s EMTERPRETIFY=1 \
3131
+ -s EMTERPRETIFY_ASYNC=1 \
32-
+ -s EMTERPRETIFY_WHITELIST=@../emterpreter_whitelist.json \
32+
+ -s EMTERPRETIFY_WHITELIST=@emterpreter_whitelist.json \
3333
+ -s ASSERTIONS=1 \
3434
+ -s SAFE_HEAP=1 \
3535
+ -s DEMANGLE_SUPPORT=1 \

libsass/build.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ patch ./libsass/Makefile.conf < ./Makefile.conf.patch
2121
echo " copying emscripten_wrapper"
2222
cp ./emscripten_wrapper.cpp ./libsass/src/emscripten_wrapper.cpp
2323
cp ./emscripten_wrapper.hpp ./libsass/src/emscripten_wrapper.hpp
24+
cp ./exported_runtime_methods.json ./libsass/exported_runtime_methods.json
25+
cp ./emterpreter_whitelist.json ./libsass/emterpreter_whitelist.json
2426

2527
# build
2628
echo " initializing emscripten"
2729
if [ "${2:-}" = "debug" ]; then
28-
(cd libsass && emmake make js-debug)
30+
docker run --rm --volume "$(pwd)/libsass:/src" --user="emscripten" trzeci/emscripten:latest emmake make js-debug
2931
else
30-
(cd libsass && emmake make js)
32+
docker run --rm --volume "$(pwd)/libsass:/src" --user="emscripten" trzeci/emscripten:latest emmake make js
3133
fi

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030
"main": "./dist/sass.sync.js",
3131
"scripts": {
3232
"build": "grunt build",
33+
"build:debug": "grunt build:debug",
34+
"rebuild": "grunt rebuild",
35+
"rebuild:debug": "grunt rebuild:debug",
36+
"libsass:prepare": "grunt libsass:prepare",
37+
"libsass:build": "grunt libsass:build",
38+
"libsass:build": "grunt libsass:build",
39+
"libsass:debug": "grunt libsass:debug",
3340
"test": "grunt test",
3441
"lint": "grunt lint",
3542
"serve": "serve ."

0 commit comments

Comments
 (0)