3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

RUSTFLAGS の設定方法

Last updated at Posted at 2020-03-21

備忘録です。

##bash
シェル変数に設定。シェルを終了すると設定は失われる。

$ RUSTFLAGS="-Ctarget-cpu=native -Cpanic=abort"

exportすると環境変数に設定される。消すときはunset

$ RUSTFLAGS="-Ctarget-cpu=native -Cpanic=abort"
$ export RUSTFLAGS
$ unset RUSTFLAGS

##PowerShell
シェルを終了すると設定は失われる。

PS> $env:RUSTFLAGS="-Ctarget-cpu=native -Cpanic=abort"

##.cargo/config
~/.cargo/ディレクトリ内の configファイルに設定を記述する。デフォルトではconfigファイルは存在しないので作成し以下記述する。設定はすべてのビルドに適用される。

[build]
rustflags = ["-Ctarget-cpu=native", "-Cpanic=abort"]

プロジェクト毎に設定したいときは /some_project/.cargo/config に置けばよい。

また、下記のようにエイリアスを設定しておけば、cargo rだけでビルドできる。

[alias]
r = "rustc --release -- -Clto=fat -Ccodegen-units=1 -Ctarget-cpu=native -Cpanic=abort"

##VSCode
settings.json に以下を記述。すべてのワークスペースに適用される。

settings.json
"terminal.integrated.env.(linux|windows)": {
    "RUSTFLAGS": "-Ctarget-cpu=native -Cpanic=abort"
}

ワークスペース毎に設定するときは、hoge.code-workspace に以下を記述。

hoge.code-workspace
"settings": {
	"terminal.integrated.env.(linux|windows)": {
		"RUSTFLAGS": "-Ctarget-cpu=native -Cpanic=abort"
	}
}

##参考

3
2
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?