僕はDartをビルドしなければいけない 弱みを握られている——
ネタ古いですね、はい。
どちらかと言えば、背景の方に弱みを握られている気がします。
流れ
- Dockerで環境を分ける
- depot_toolsを落としてくる
- ソースコードを落としてくる
- ビルドする
- dev_compilerをインストールする
環境
Xubuntu 15.04。Dockerはインストールされているようだ。
Dockerで環境を分ける
あんまし試験的なことを素の環境でやりたくないです。
$ docker pull ubuntu:14.04 $ docker run -i -t --name=dart-build ubuntu:14.04 /bin/bash
ここからはDocker上の話になります。
depot_toolsを落としてくる
# まず$HOME(/root)へ行く $ cd # 作業用ディレクトリを掘る $ mkdir dart && cd $_ # 必要そうなものをaptでインストールする(本当に必要か自信はない) $ apt update $ apt install -y build-essential flex git python subversion # depot_toolsを落としてくる $ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git $ export PATH="$PWD/depot_tools:$PATH"
ソースコードを落としてくる
とても時間がかかります。
# Google謹製のgclientというツールを使う $ gclient config https://github.com/dart-lang/sdk.git # これがとても時間がかかる(10分くらい?) $ gclient sync
夜の向日葵でも聴いて心を落ち着けましょう。
ビルドする
Dart Editorとかいらないから。
$ time ./tools/build.py -m release -a x64 create_sdk real 33m42.406s user 100m11.292s sys 5m20.396s
100分もかかったのか‥‥。
# パスを通す $ export DART_CONFIGURATION="ReleaseX64" $ export DART_SDK="$PWD/sdk" $ export PATH="$PWD/sdk/bin:$PATH"
dev_compilerをインストールする
$ pub global activate -sgit https://github.com/dart-lang/dev_compiler.git # パスを通せと言われるので通す $ export PATH="$PATH:$HOME/.pub-cache/bin"
で、実際に使ってみます。
# ビルドも終わったので$HOMEに戻る $ cd # 適当なディレクトリを掘る $ mkdir dart_sample && cd $_ # main.dartを作る $ cat <<'EOF' >main.dart void main() { List<String> list = ["hello", "world"]; for (var item in list) { print(item); } } EOF # コンパイル(なんか遅い) $ dartdevc -o devc main.dart # コンパイルされた結果を表示してみる $ cat devc/main.js dart.library('main', null, /* Imports */[ 'dart/core' ], /* Lazy imports */[ ], function(exports, core) { 'use strict'; function main() { let list = dart.list(["hello", "world"], core.String); for (let item of list) { core.print(item); } } dart.fn(main, dart.void, []); // Exports: exports.main = main; }); //# sourceMappingURL=main.js.map
確かにdart2js
の出力よりは分かりやすくなったような気がします。あと、若干ES6使ってますね。