0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Rust+WebAssemblyでHello Worldを行ったメモ

Last updated at Posted at 2024-07-04

概要

RustとWebAssemblyによるゲーム開発を進めるにあたって、環境構築で少し詰まったのでメモ

ソースコード

RustのつづきはZennに。

環境

  • Windows 11 Home 23H2 22631.3810

実行環境構築

Rustのインストール

choco install rustup.install -y 

インストール後、cargoが利用できるようにする。

rustup update

cmakeのインストール

rust入門
Rustのコンパイルに使うのでC++のビルド環境を設定する。

choco visualstudio2022buildtools visualstudio2022-workload-vctools -y

cmakeのパスが通ったか確認。

cmake --version

パスが通っていない場合、環境変数(スタートメニューからシステム環境変数を検索)のPATHに下記を追加する。

C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin

パスが通ったか確認する。

cmake --version

wasmのインストール

cargo install wasm-pack

スケルトンの準備

本の手順ではnpm init rust-webpackコマンドで行っていたが、動かなかった。

githubのスケルトンをcloneして使うことに。

その後、パッケージが古かったので更新を行った。

参考
WASM の Webpack を v4 から v5 に Update した

著者なら https://crates.io/search で最新にするそうだ。私もそうした。

読者は私よりも賢いだろうから、サンプルコードが確実に動くように、ここで示したバージョンを使うだろう

動作

webpack-dev-serverの更新にともない、startコマンドも-dオプションを外している。

  "start": "rimraf dist pkg && webpack-dev-server --open",

npm run startで、開発者ツールのコンソールにHello Worldが表示されることを確認した。

試行錯誤

本に書いてあることそのままで動かないことがいくつか。

cmakeが入っていない

下記のようなエラーが発生

error: linker `link.exe` not found
  |
  = note: program not found

note: the msvc targets depend on the msvc linker but `link.exe` was not found

note: please ensure that Visual Studio 2017 or later, or Build Tools for Visual Studio were installed with the Visual C++ option.

note: VS Code is a different product, and is not sufficient.

error: could not compile `windows_x86_64_msvc` (build script) due to 1 previous error

エラーが発生したが欲しかったcmakeは入った件

visualstudio2022-workload-vctoolsをインストールしているときに下記のようなエラーが発生した。

[2e3c:0028][2024-07-04T01:10:41] WebClient error 'RequestCanceled' with 'https://aka.ms/vs/17/release/channel' - ExecuteWithRetryAsync failed along with a cancellation request
Warning: [2e3c:0028][2024-07-04T01:10:41] Failed to get the HttpWebResponse while invoking a HEAD request against https://aka.ms/vs/17/release/channel:System.OperationCanceledException: 操作は取り消されました。
   場所 System.Threading.CancellationToken.ThrowOperationCanceledException()
   場所 System.Threading.CancellationToken.ThrowIfCancellationRequested()
   場所 Microsoft.VisualStudio.Setup.Download.WebRequestService.<>c__DisplayClass9_0.<ExecuteWithRetryAsync>b__0(Object _)
   場所 System.Threading.Tasks.Task`1.InnerInvoke()
   場所 System.Threading.Tasks.Task.Execute()
--- 直前に例外がスローされた場所からのスタック トレースの終わり ---


[2e3c:000f][2024-07-04T01:10:41] Package Microsoft.Windows.UniversalCRT.Msu.7 is not applicable: 現在の OS のバージョン '10.0.22631.0' は、サポートされるバージョンの範囲 '[6.1,6.2)' に含まれていません。

エラーは発生したがcmakeはパスを通したら動いたので放置。

参考

The Rust Programming Language 日本語版

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?