Skip to content

Commit

Permalink
Update to require ldc 1.13.0-beta2 for -fvisibility=hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
skoppe committed Dec 13, 2018
1 parent 7aa46be commit a6a51a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,24 @@ You can add any extra css/js you'll need to the `index.template.html`, or you ca

# How to compile your application

Make sure to have ldc 1.12 installed. Also, make sure that ``ldc2 --version`` returns the `wasm32` among its target types. If not, you may need to install ldc from official sources or run one in docker.
Make sure to have at least ldc 1.13.0-beta2 installed. Also, make sure that ``ldc2 --version`` returns the `wasm32` among its target types. If not, you may need to install ldc from official sources or run one in docker.

Run `dub build --compiler=ldc2 --build=release` to compile your application, then run `npx webpack` to generate the `index.html`.

You can also `npm run start` to start a webpack development server that serves your application on localhost:3000 (it builds anytime the `app.js` or `index.template.html` changes).

* Note: I could not get it to build on my aged mac (el capitan). Instead I use docker to run ldc in ubuntu.

# Optimizing for size

Since ldc 1.13.0-beta2 there is the `-fvisibility=hidden` flag that hides all functions that aren't explicitly prefixed with the `export` keyword. This flag reduces binary size considerably and has reduced the need for manual stripping almost completely.

By default symbol names aren't stripped, which means the full mangled name is in the binary, this is convenient for debugging but adds to the binary's size. Add `-strip-all` to the lflags in your `dub.(sdl|json)` to strip all internal function names.

For yet unknown reasons a pointer to each struct's init section gets exported as a global. These globals are completely unused and add some additional bloat. The binaryen project has several tools to (dis)assemble a wasm to text representation and back, which allows manual removing of those exported symbols.

Also, llvm doesn't skip consecutive zeros in the data segment. Running wasm-opt (from binaryen project) removes them and reduces code size further.

# Examples

There is todo-mvc example project in this repo. It implements the famous [todo mvc application](http://todomvc.com).
Expand Down Expand Up @@ -71,7 +81,7 @@ Properties can also be a result of a function.
```d
struct App {
mixin Node!"div";
@prop bool innerText() {
@prop string innerText() {
return "Hello World!"
};
}
Expand Down
4 changes: 2 additions & 2 deletions dub.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ description "A framework for writing single page applications"
authors "Sebastiaan Koppe"
copyright "Copyright © 2018, Sebastiaan Koppe"
license "MIT"
dflags "-mtriple=wasm32-unknown-unknown-wasm" "-Oz" "-betterC"
lflags "-allow-undefined" "-import-memory" "-strip-all"
dflags "-mtriple=wasm32-unknown-unknown-wasm" "-betterC" "-fvisibility=hidden"
lflags "-allow-undefined" "-import-memory"
dependency "stdx-allocator" version="2.77.3"
#target "library"
subPackage "bootstrap-webpack"

0 comments on commit a6a51a7

Please sign in to comment.