LoginSignup
45
16

More than 5 years have passed since last update.

【Dart応援キャンペーン】Fuchsiaをエミュレータで動かしてみよう!

Last updated at Posted at 2016-12-25

2018-04-05 最近ポチポチされるようになってきたので、現状に合わせて大幅に更新しました。Ubuntuは更新のみで動作は未確認です。キャプチャ画像など後半のGUI関連はQEMUで確認できなかったのでそのままです。Don't miss it!

macOS High Sierra Version 10.13.4
Xcode Version 9.3

「Fuchsiaとは何ですか?」
@Cat_sushi 「希望です。」
と、私には聴こえました!(個人の妄想です。)

Fuchsiaとは、

Fuchsia の ネットワーク周りについて調べた。

FuchsiaはGoogleが2016年8月に公開したOSです。
Brilloと違ってLinux kernelではなく、独自のkernelを使っているのが特徴です。

カーネルはMagentaでしたが、今はZirconに改名されています。

Dart型システムの動向

また、Googleからまだ正式発表のない謎のOS Fuchsiaでも一級市民としてFlutterが採用されているようです。FuchisaはPC(Chrome OSの代替?)やIoT(Android Things、Brilloの代替?)での活用も噂されています。Flutter、FuchsiaともGitHubのコミットは非常に高いペースを保っているので期待できます。

Fuchsiaプロジェクトはこのあたりから入るのがよろしいかと。
https://fuchsia.googlesource.com/docs/+/HEAD/getting_started.md
GitHubのミラーはこちらです。
https://github.com/fuchsia-mirror

早速、ビルドしてエミュレータで動かしてみようじゃないですか!

ソース取得

Fuchsiaはソースファイルのgitリポジトリ群の管理にjiriというツールを使用しています。Go 1.6以上が必要です。

Mac:

$ brew install golang

Ubuntu:

$ sudo apt-get install golang git-all build-essential curl

最初にビルドしたいレイヤを選びます。よくわからなかれば、カレンダーやメール、DartやFlutterランナーなど、主だったものが含まれているtopazです。-sでレイヤを指定してソースを取得します。

$ curl -s "https://fuchsia.googlesource.com/scripts/+/master/bootstrap?format=TEXT" | base64 --decode | bash -s topaz
Please add /Users/tatsu/fuchsia/.jiri_root/bin to your PATH
WARN: Please opt in or out of analytics collection. You will receive this warning until an option is selected.
To check what data we collect run 'jiri init -show-analytics-data'
To opt-in run 'jiri init -analytics-opt=true "/Users/tatsu/fuchsia"'
To opt-out run 'jiri init -analytics-opt=false "/Users/tatsu/fuchsia"'

WARN: Please opt in or out of analytics collection. You will receive this warning until an option is selected.
To check what data we collect run 'jiri init -show-analytics-data'
To opt-in run 'jiri init -analytics-opt=true "/Users/tatsu/fuchsia"'
To opt-out run 'jiri init -analytics-opt=false "/Users/tatsu/fuchsia"'

Updating all projects
Done creating topaz development environment at "/Users/tatsu/fuchsia".
Recommended: export PATH="/Users/tatsu/fuchsia/.jiri_root/bin:$PATH"

jiriを実行できるようにPATHを通しておきましょう。

export PATH="/Users/tatsu/fuchsia/.jiri_root/bin:$PATH"

ちなみに次回からは、jiriコマンドで更新できます。jiriはGo版のRepoといったところです。updateはrepoでいうsyncですね。

$ cd fuchsia
$ jiri update
WARN: Please opt in or out of analytics collection. You will receive this warning until an option is selected.
To check what data we collect run 'jiri init -show-analytics-data'
To opt-in run 'jiri init -analytics-opt=true "/Users/tatsu/fuchsia"'
To opt-out run 'jiri init -analytics-opt=false "/Users/tatsu/fuchsia"'

Updating all projects

ビルド環境準備

Xcodeのコマンドラインツールと必要なライブラリをインストールしておきます。

初期の手順による構成上、Go関連は上記で登場済みですがここにも含めておきます。

Mac:

$ xcode-select --install
$ brew install wget pkg-config glib autoconf automake libtool golang

Ubuntu:

$ sudo apt-get install texinfo libglib2.0-dev liblz4-tool autoconf libtool libsdl-dev build-essential golang git build-essential curl unzip

業務連絡

店長、ゴマがありません。

gomaとは、白いバスローブを着て片手にコニャックグラスを持ったGooglerだけが、揺り椅子に腰掛け、バハマ産の葉巻の煙を燻らせながら使うことのできるccacheの代替ツールのようです。(個人の妄想です。)

しかたがないのでccacheを使って次回からのビルド時間を短縮しましょう。

$ brew install ccache
To install symlinks for compilers that will automatically use
ccache, prepend this directory to your PATH:
  /usr/local/opt/ccache/libexec

If this is an upgrade and you have previously added the symlinks to
your PATH, you may need to modify it to the path specified above so
it points to the current version.

NOTE: ccache can prevent some software from compiling.
ALSO NOTE: The brew command, by design, will never use ccache.

PATHの前方に/usr/local/opt/ccache/libexecを追加し、CCACHE_DIR環境変数でキャッシュディレクトリを指定しておきます。

export PATH="/usr/local/opt/ccache/libexec":"$PATH"
export CCACHE_DIR="your-ccache-directory"

ビルド

fxコマンドでビルドします。.jiri_root/binをPATHに追加してあれば、すでにPATHが通っています。

$ fx set x64 --ccache
Done. Made 6407 targets from 1032 files in 28209ms
$ fx full-build

fxにはfull-buildに対するcleanコマンドが用意されてなさそうなので、クリーンビルドしたいときはoutディレクトリをごっそり消してます。

QEMUで動かす

いよいよFuchsiaをQEMUで起動します。

$ fx run -g

-gフラグを指定すればグラフィックが有効になりますが、QEMUがVulkanをサポートしていないため、有効にならないようです。以下は2017-05-02に確認したときのログイン画面のスクリーンショットです。

Screen Shot 2017-05-03 at 7.56.53.png

画面をクリックするとマウスポインタを持っていかれますが、ctrl+altでホスト側へ戻ります。

USキーボード設定になってますので、JISキーボードの方は、ググってUSキーボード配列画像を表示しておいたほうがよいです。

Screen Shot 2016-12-25 at 16.26.49.png

Linuxではないようですが、cdやpwdなどのUnixコマンドはありました。試しに

$ echo $PATH
/system/apps:/system/bin:/boot/bin

お。vim、あります。python、ありません。dart、あります、あります!
/dataの下あたりだったら書けるかな?

$ dart --version
Dart VM version: 2.0.0-edge ...snip... on "fuchsia_x64"
$ cd /data
$ vim hello_fuchsia.dart
hello_fuchsia.dart
main() {
  print('Hello, Fuchsia!');
}
$ dart hello_fuchsia.dart
Hello, Fuchsia!

アプリを動かしてみましょう!

fortuneで奥深い金言が表示されているようです。けっこう地味です...。

$ fortune
Things that are impossible just take longer.

2018-04-05 以下、動作未確認でスクリーンショットは当時のままです。そもそも/system/appsがごっそり見当たらないので、topazには入っていなさそう。

/system/appsの下にあるGUIをサポートしているMozartアプリのspinning_square_viewを起動してみます。

$ launch spinning_square_view

Screen Shot 2016-12-25 at 13.56.32.png

うーん。止め方がわかりません。だれか教えて。しかたがないので起動したターミナル側からctrl-cで強制終了しました。

Flutterのサンプルも同じディレクトリに落ちています。Flutter Module Developmentにサンプルの起動方法や、Flutterモジュールの開発手順が載っています。

example_flutter_hello_worldアプリを起動してみます。

$ device_runner --user_shell=dev_user_shell --user_shell_args=--root_module=example_flutter_hello_world

Screen Shot 2016-12-25 at 15.52.47.png

おわりに

Fuchsiaがスターダムにのし上がるかどうかは別として、またひとつ新しいおもちゃがでてきたことに間違いないようです。いろいろいじってまたご報告できたらと思います。

まことに僭越ながら、今年のトリを勝手に努めさせて頂きましたので、ここらで締めさせて頂きます。

Dartの夜明けは近いぜよ!
Don't miss it!

45
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
45
16