Denoのソースビルドを試してみる
ちょっとしたツールをつくる必要があった際に、
TypeScriptで書きたいなー、そういえばDeno
っていうのがあったなー、
と思い出しました。
公式サイトを見ているとソースビルドの手順が書かれていて、気になったので試してみました。
基本的に公式サイトの手順に沿うだけですが、数箇所エラーが発生したので、その際の対応を書いていきます。
Deno とは?
こちらの記事で概要を把握できると思います。
Deno について知っていることと、今後への期待 v1811
環境
手順
https://deno.land/manual.html#buildfromsource
ソースダウンロード
mkdir ~/github.com/denoland cd ~/github.com/denoland git clone --recurse-submodules https://github.com/denoland/deno.git cd deno
セットアップスクリプト
$ ./tools/setup.py (省略...) Done. Made 431 targets from 90 files in 1120ms (省略...) Done. Made 431 targets from 90 files in 1051ms
問題なく実行できました。
ビルド
エラーが発生しました。
Rustファイルで発生しており、dyn
というものが非推奨になっているため、発生しているみたいです。
$ ./tools/setup.py error: trait objects without an explicit `dyn` are deprecated --> ../../core/isolate.rs:55:19 | 55 | type DispatchFn = Fn(&[u8], Option<PinnedBuf>) -> Op; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `dyn`: `dyn Fn(&[u8], Option<PinnedBuf>) -> Op` | = note: `-D bare-trait-objects` implied by `-D warnings` error: trait objects without an explicit `dyn` are deprecated --> ../../core/isolate.rs:58:20 | 58 | type DynImportFn = Fn(&str, &str) -> DynImportFuture; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `dyn`: `dyn Fn(&str, &str) -> DynImportFuture` error: trait objects without an explicit `dyn` are deprecated --> ../../core/modules.rs:593:32 | 593 | fn cause(&self) -> Option<&Error> { | ^^^^^ help: use `dyn`: `dyn Error`
deprecated
というのは、バージョン互換性関連でよく見る単語なので、
Rustのバージョンを1.37.0-nightly
から下げてみます。
Denoのドキュメントには、
Rust >= 1.34.1
と書かれているので、1.34.1
まで下げたほうがよさそうですが、
なるべく新しいバージョンで進めたいので 1.35.0
で試してみます。
Rustでは、プロジェクトディレクトリに、rust-toolchain
というバージョン情報を記載したファイルを用意しておくと、そのバージョンを使用してくれます。
プロジェクトで使用するRustツールチェインのバージョンをチームで共有する
# rust-toolchain作成前 $ rustup show Default host: x86_64-apple-darwin installed toolchains -------------------- stable-x86_64-apple-darwin nightly-x86_64-apple-darwin (default) 1.35.0-x86_64-apple-darwin active toolchain ---------------- nightly-x86_64-apple-darwin (default) rustc 1.37.0-nightly (5f3656ce9 2019-06-11)
# rust-toolchain作成後 $ cat rust-toolchain 1.35.0 # 未インストールのバージョンの場合、rustup showのタイミングでダウンロードしてくれる $ rustup show Default host: x86_64-apple-darwin installed toolchains -------------------- stable-x86_64-apple-darwin nightly-x86_64-apple-darwin (default) 1.35.0-x86_64-apple-darwin active toolchain ---------------- 1.35.0-x86_64-apple-darwin (overridden by '/Users/shootacean/github.com/denoland/deno/rust-toolchain') rustc 1.35.0 (3c235d560 2019-05-20)
再度、ビルドスクリプトを実行する!
$ ./tools/build.py ninja: Entering directory `/Users/shootacean/github.com/denoland/deno/target/debug' [17/264] ACTION //build_extra/rust:log_rustc(//build/toolchain/mac:clang_x64) FAILED: rust_crates/liblog.rlib python ../../build_extra/rust/run.py /Users/shootacean/github.com/denoland/deno/prebuilt/mac/sccache rustc ../../third_party/rust_crates/registry/src/github.com-1ecc6299db9ec823/log-0.4.6/src/lib.rs --crate-name=log --crate-type=rlib --emit=link,dep-info --edition=2015 --out-dir=rust_crates -Cextra-filename= -Cmetadata=\"_rustc\ 1.37.0-nightly\ \(5f3656ce9\ 2019-06-11\)\" -L dependency=rust_crates --color=always -g -Dwarnings --cap-lints allow --extern cfg_if=rust_crates/libcfg_if.rlib error[E0514]: found crate `cfg_if` compiled by an incompatible version of rustc --> ../../third_party/rust_crates/registry/src/github.com-1ecc6299db9ec823/log-0.4.6/src/lib.rs:287:1 | 287 | extern crate cfg_if; | ^^^^^^^^^^^^^^^^^^^^ | = help: please recompile that crate using this compiler (rustc 1.35.0 (3c235d560 2019-05-20)) = note: the following crate versions were found: crate `cfg_if` compiled by rustc 1.37.0-nightly (5f3656ce9 2019-06-11): /Users/shootacean/github.com/denoland/deno/target/debug/rust_crates/libcfg_if.rlib error: aborting due to previous error For more information about this error, try `rustc --explain E0514`. (以降省略...)
また別のエラーが発生しました:frowning2:
= note: the following crate versions were found: crate
cfg_if
compiled by rustc 1.37.0-nightly (5f3656ce9 2019-06-11): /Users/shootacean/github.com/denoland/deno/target/debug/rust_crates/libcfg_if.rlib
エラーメッセージを見た感じ、ビルド失敗時の情報が残っていることが原因っぽいです。
なので、./target/debug/rust_crates
ディレクトリを削除して、再度ビルドスクリプトを実行します!!
(./target
ディレクトリ配下をまるごと消してしまった場合は、再度セットアップスクリプトを実行してください。)
$ ./tools/build.py ninja: Entering directory `/Users/shootacean/github.com/denoland/deno/target/debug' [698/698] STAMP obj/default.stamp $
問題なく、ビルドできました!:grinning:
$ ./target/debug/deno run tests/002_hello.ts [1/1] Compiling file:///Users/shootacean/github.com/denoland/deno/tests/002_hello.ts Hello World
Hello World も問題なく実行できました!:grinning:
テストスクリプト
./tools/test.py gn_string (setup_test.TestSetup) ... ok read_gn_args (setup_test.TestSetup) ... ok write_gn_args (setup_test.TestSetup) ... ok ...省略 ---------------------------------------------------------------------- Ran 163 tests in 367.339s OK (skipped=1)
問題なし!:grinning:
リリースビルド
リリースビルドも試してみます。
$ ./tools/build.py --release deno ninja: Entering directory `/Users/shootacean/github.com/denoland/deno/target/release' [656/656] LINK ./deno
ビルドしたバイナリで、Hello Worldを実行します!
$ ./target/release/deno tests/002_hello.ts Hello World
実行できました!:ok_hand:
感想
言語処理系周りを学ぶのは初めてハードルが高そうですが、 TypeScriptは好きな言語ですし、Rustも興味あるので、Denoをチェックしていこうと思います!