Skip to content

Commit

Permalink
Merge 2e59a54 into 58d43f5
Browse files Browse the repository at this point in the history
  • Loading branch information
mbasso committed Apr 26, 2018
2 parents 58d43f5 + 2e59a54 commit 19306c6
Show file tree
Hide file tree
Showing 79 changed files with 2,489 additions and 1,452 deletions.
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ node_js:
- "8"
- "9"
install: true
sudo: required
services:
- docker
before_install:
- docker run -dit --name emscripten -v $(pwd):/src trzeci/emscripten:sdk-incoming-64bit bash
script:
- npm install --ignore-scripts
- docker exec -it emscripten make
- npm run lint
- npm run test:js
- npm run build
branches:
only:
- master
Expand All @@ -32,4 +37,5 @@ jobs:
branches:
only:
- master
if: tag =~ ^\d+\.\d+\.\d+
after_success: echo "Website online"
40 changes: 7 additions & 33 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,51 +25,25 @@ git clone https://github.com/mbasso/asm-dom.git

#### Building asm-dom

Running the `build` task will create both a CommonJS module-per-module build and a UMD build.
Running `make` will create both the C++ and the JS version of asm-dom, a CommonJS module-per-module build and a UMD build.
```
npm run build
make
```

To create just a CommonJS module-per-module build:

```
npm run build:commonjs
```

The result will be in the `lib` folder.

To create just a UMD build:
```
npm run build:umd
npm run build:umd:min
```

The result will be in the `dist` folder.
The result will be in the `lib`, `es` and `dist` folder.

### Testing and Linting

To run both linting and testing at once, run the following:

```
npm run check:src
```

To only run linting:

```
npm run lint
```

To only run tests:
To run linting:

```
npm run test
make lint
```

To continuously watch and run tests, run the following:
To run tests:

```
npm run test:watch
make test
```

### Docs
Expand Down
152 changes: 152 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# if you are using windows, comment line 4 and uncomment line 5
# leave it as it was before committing as travis uses linux
SRCDIR := src
SRCS := $(shell find $(SRCDIR) -name "*.js")
#SRCS := $(shell FORFILES /P $(SRCDIR) /S /M *.cpp /C "CMD /C ECHO @relpath")

ESDIR := es
LIBDIR := lib
ES := $(SRCS:$(SRCDIR)/%=$(ESDIR)/%)
LIBS := $(SRCS:$(SRCDIR)/%=$(LIBDIR)/%)
DISTDIR := dist
DISTJS := $(DISTDIR)/js
DISTCPP := $(DISTDIR)/cpp
UMDJS := $(DISTJS)/asm-dom.js
UMDCPP := $(DISTCPP)/asm-dom.js
TESTCPP := test/cpp/app.asm.js
COMPILED := compiled
COMPILEDASMJS := $(COMPILED)/asmjs
COMPILEDWASM := $(COMPILED)/wasm
CPPDIR := cpp

TREE := \
$(COMPILED) \
$(COMPILEDASMJS) \
$(COMPILEDWASM) \
$(DISTDIR) \
$(DISTJS) \
$(DISTCPP) \
$(ESDIR) \
$(LIBDIR) \
$(sort $(patsubst %/,%,$(dir $(ES)))) \
$(sort $(patsubst %/,%,$(dir $(LIBS))))

FILES = \
src/cpp/asm-dom.cpp \
src/cpp/asm-dom-server.cpp

BC = compiled/asm-dom.bc

CFLAGS = \
-O3 \
--bind \
-Wall \
-Werror \
-Wall \
-Wno-deprecated \
-Wno-parentheses \
-Wno-format

WASM_OPTIONS = \
-O3 \
--bind \
--memory-init-file 0 \
--llvm-lto 3 \
--llvm-opts 3 \
--js-opts 1 \
--closure 1 \
-s MODULARIZE=1 \
-s ALLOW_MEMORY_GROWTH=1 \
-s AGGRESSIVE_VARIABLE_ELIMINATION=1 \
-s ABORTING_MALLOC=1 \
-s NO_EXIT_RUNTIME=1 \
-s NO_FILESYSTEM=1 \
-s DISABLE_EXCEPTION_CATCHING=2 \
-s BINARYEN=1 \
-s EXPORTED_RUNTIME_METHODS=[\'UTF8ToString\'] \
-s BINARYEN_TRAP_MODE=\'allow\'

ASMJS_OPTIONS = \
-O3 \
--bind \
--memory-init-file 0 \
--llvm-lto 3 \
--llvm-opts 3 \
--js-opts 1 \
--closure 1 \
-s MODULARIZE=1 \
-s AGGRESSIVE_VARIABLE_ELIMINATION=1 \
-s ELIMINATE_DUPLICATE_FUNCTIONS=1 \
-s ABORTING_MALLOC=1 \
-s NO_EXIT_RUNTIME=1 \
-s NO_FILESYSTEM=1 \
-s DISABLE_EXCEPTION_CATCHING=2 \
-s EXPORTED_RUNTIME_METHODS=[\'UTF8ToString\']

.PHONY: all install clean lint test test_js test_watch build

all: build

install:
npm install

clean:
npx rimraf $(DISTDIR) $(LIBDIR) $(ESDIR) $(CPPDIR) .nyc_output $(COMPILED) $(TESTCPP)

lint:
npx eslint src test build

test: $(COMPILEDASMJS)/asm-dom.asm.js $(COMPILEDWASM)/asm-dom.js $(TESTCPP) test_js

test_js:
npx cross-env BABEL_ENV=commonjs nyc --require babel-register --require ./test/setup.js mocha --recursive

build: compiled/asm-dom.a $(BC) compiled/asm-dom.o $(COMPILEDASMJS)/asm-dom.asm.js $(COMPILEDWASM)/asm-dom.js $(TESTCPP) $(LIBS) $(ES) $(UMDJS) $(UMDCPP)
npx ncp $(SRCDIR)/cpp $(CPPDIR)
npx ncp $(DISTCPP) $(CPPDIR)
npx ncp $(LIBDIR)/cpp $(CPPDIR)

$(TESTCPP):
emcc \
-DASMDOM_TEST \
$(CFLAGS) \
$(ASMJS_OPTIONS) \
$(FILES) \
test/cpp/tests.cpp \
-o $@

.SECONDEXPANSION:
$(COMPILED)/asm-dom.%: $$(@D)
emcc \
-DASMDOM_JS_SIDE \
$(CFLAGS) \
$(FILES) \
src/js/index.cpp \
-o $@

$(COMPILEDASMJS)/asm-dom.asm.js: $(BC) | $$(@D)
emcc \
$(ASMJS_OPTIONS) \
$(BC) \
-o $@

$(COMPILEDWASM)/asm-dom.js: $(BC) | $$(@D)
emcc \
$(WASM_OPTIONS) \
$(BC) \
-o $@

$(ESDIR)/%: $(SRCDIR)/% | $$(@D)
npx cross-env BABEL_ENV=es babel $< --out-file $@

$(LIBDIR)/%: $(SRCDIR)/% | $$(@D)
npx cross-env BABEL_ENV=commonjs babel $< --out-file $@

$(UMDJS): $(SRCS) | $$(@D)
npx cross-env BABEL_ENV=commonjs webpack --env.prod src/js/index.js $@

$(UMDCPP): $(SRCS) | $$(@D)
npx cross-env BABEL_ENV=commonjs webpack --env.prod --env.cpp src/cpp/index.js $@

$(TREE): %:
npx mkdirp $@
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ Also, here is the list of the online Demos:

## Roadmap

- [ ] create asm-dom boilerplate
- [ ] Thunks support
- [ ] asm-dom aims to be even more powerful with [GC/DOM Integration](http://webassembly.org/docs/future-features/). Unfortunately this is a future feature 🦄, so, we have to be patient and wait a bit.

Expand Down
6 changes: 3 additions & 3 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ There are 4 tests at the moment:

- `create nodes`: this test create 700 nodes (100 nodes with 3 children, the last of which has 3 more children). Please note that, as we said before, **in the case of asm-dom, this test creates but also destroys the nodes**. While, in the case of snabbdom, the deletion is managed by the garbage collector and it is not measured.

- `create and diff equal nodes`: this test runs the `patch` function 100 times with 2 equal nodes (2 nodes with 100 children, each of them has 1 child), so, the DOM will be not updated.
- `diff equal nodes`: this test runs the `patch` function 100 times with 2 equal nodes (2 nodes with 100 children, each of them has 1 child), so, the DOM will be not updated.

- `create and diff different nodes`: this test runs the `patch` function 100 times with 2 nodes with different attributes (2 nodes with 100 children, each of them has 1 child), so, the DOM will be updated.
- `diff different nodes`: this test runs the `patch` function 100 times with 2 nodes with different attributes (2 nodes with 100 children, each of them has 1 child), so, the DOM will be updated.

- `create and add/remove nodes`: this test runs the `patch` function 100 times with 2 nodes, one with 100 children and one without children.
- `add/remove nodes`: this test runs the `patch` function 100 times with 2 nodes, one with 100 children and one without children.

Here you can find screenshots of the tests (lower is better) runned on a MacBook Pro (Retina, 13-inch, Late 2013), Processor 2,4 GHz Intel Core i5, Memory 8 GB 1600 MHz DDR3:

Expand Down
Binary file modified benchmarks/compiled/app.bc
Binary file not shown.
Binary file modified benchmarks/compiled/app.o
Binary file not shown.
138 changes: 69 additions & 69 deletions benchmarks/compiled/asmjs/app.asm.js

Large diffs are not rendered by default.

Loading

0 comments on commit 19306c6

Please sign in to comment.