Rust 1.34.2 contig.toml 選項梳理

# Sample TOML configuration file for building Rust.
#
# To configure rustbuild, copy this file to the directory from which you will be
# running the build, and name it config.toml.
#
# All options are commented out by default in this file, and they're commented
# out with their default values. The build system by default looks for
# `config.toml` in the current directory of a build for build configuration, but
# a custom configuration file can also be specified with `--config` to the build
# system.

本文摘取config.toml.example中的注釋信息并進行說明,該文件中的所有選項都被注釋掉了,#后就是它們在不被指定時的默認值。

[llvm]

# =============================================================================
# Tweaking how LLVM is compiled
# =============================================================================

LLVM配置。

enabled

# Indicates whether rustc will support compilation with LLVM
# note: rustc does not compile without LLVM at the moment
#enabled = true

指定rustc是否支持和LLVM一起編譯,目前Rust只能依賴于LLVM,因此該選項總是為true。

optimize

# Indicates whether the LLVM build is a Release or Debug build
#optimize = true

指定LLVM的Release/Debug版本。

thin-lto

# Indicates whether LLVM should be built with ThinLTO. Note that this will
# only succeed if you use clang, lld, llvm-ar, and llvm-ranlib in your C/C++
# toolchain (see the `cc`, `cxx`, `linker`, `ar`, and `ranlib` options below).
# More info at: https://clang.llvm.org/docs/ThinLTO.html#clang-bootstrap
#thin-lto = false

當編譯用的C/C++工具鏈為LLVM時,可以指定ThinLTO(用于節(jié)約鏈接時優(yōu)化的時空開支)。

release-debuginfo

# Indicates whether an LLVM Release build should include debug info
#release-debuginfo = false

指定構建的Release版LLVM是否帶有調試信息。

assertions

# Indicates whether the LLVM assertions are enabled or not
#assertions = false

指定是否在編譯時進行斷言檢查。

ccache

# Indicates whether ccache is used when building LLVM
#ccache = false
# or alternatively ...
#ccache = "/path/to/ccache"

指定是否使用ccache(compiler cache),該工具可以將編譯結果緩存起來,下次編譯盡量使用先前的緩存以節(jié)省編譯時間。

version-check

# If an external LLVM root is specified, we automatically check the version by
# default to make sure it's within the range that we're expecting, but setting
# this flag will indicate that this version check should not be done.
#version-check = true

如果指定使用外部的LLVM,會核對其版本以確定是在可接受的范圍,該選項可關閉這一步驟。

static-libstdcpp

# Link libstdc++ statically into the librustc_llvm instead of relying on a
# dynamic version to be available.
#static-libstdcpp = false

指定libstdc++庫動態(tài)鏈接還是靜態(tài)鏈接到librustc_llvm中。

ninja

# Tell the LLVM build system to use Ninja instead of the platform default for
# the generated build system. This can sometimes be faster than make, for
# example.
#ninja = false

指定是否使用ninja工具(而非make)進行構建。

targets

# LLVM targets to build support for.
# Note: this is NOT related to Rust compilation targets. However, as Rust is
# dependent on LLVM for code generation, turning targets off here WILL lead to
# the resulting rustc being unable to compile for the disabled architectures.
# Also worth pointing out is that, in case support for new targets are added to
# LLVM, enabling them here doesn't mean Rust is automatically gaining said
# support. You'll need to write a target specification at least, and most
# likely, teach rustc about the C ABI of the target. Get in touch with the
# Rust team and file an issue if you need assistance in porting!
#targets = "X86;ARM;AArch64;Mips;PowerPC;SystemZ;JSBackend;MSP430;Sparc;NVPTX;Hexagon"

指定LLVM支持的目標平臺,得是Rust的超集。

experimental-targets

# LLVM experimental targets to build support for. These targets are specified in
# the same format as above, but since these targets are experimental, they are
# not built by default and the experimental Rust compilation targets that depend
# on them will not work unless the user opts in to building them. By default the
# `WebAssembly` and `RISCV` targets are enabled when compiling LLVM from scratch.
#experimental-targets = "WebAssembly;RISCV"

指定尚處在實驗階段的目標平臺。

link-jobs

# Cap the number of parallel linker invocations when compiling LLVM.
# This can be useful when building LLVM with debug info, which significantly
# increases the size of binaries and consequently the memory required by
# each linker process.
# If absent or 0, linker invocations are treated like any other job and
# controlled by rustbuild's -j parameter.
#link-jobs = 0

指定鏈接線程數(shù),為0時跟隨Rust構建的-j參數(shù)。

link-shared

# When invoking `llvm-config` this configures whether the `--shared` argument is
# passed to prefer linking to shared libraries.
#link-shared = false

如果使用了llvm-config工具,該選項用于指定靜態(tài)鏈接還是動態(tài)鏈接。

version-suffix

# When building llvm, this configures what is being appended to the version.
# If absent, we let the version as-is.
#version-suffix = "-rust"

指定所生成的LLVM版本的后綴。由于我們的目的是在Rust,通常把LLVM視為中間產(chǎn)物,該選項所謂不大。

clang-cl

# On MSVC you can compile LLVM with clang-cl, but the test suite doesn't pass
# with clang-cl, so this is special in that it only compiles LLVM with clang-cl
#clang-cl = '/path/to/clang-cl.exe'

MSVC專用,指定使用clang-cl編譯LLVM。

cflags、cxxflags、ldflags

# Pass extra compiler and linker flags to the LLVM CMake build.
#cflags = "-fextra-flag"
#cxxflags = "-fextra-flag"
#ldflags = "-Wl,extra-flag"

構建LLVM時,傳給cmake的編譯和鏈接參數(shù)。

use-libcxx

# Use libc++ when building LLVM instead of libstdc++. This is the default on
# platforms already use libc++ as the default C++ library, but this option
# allows you to use libc++ even on platforms when it's not. You need to ensure
# that your host compiler ships with libc++.
#use-libcxx = true

指定使用libc++(LLVM的C++標準庫,支持C++11)代替libstdc++(gcc的C++標準庫)。

use-linker

# The value specified here will be passed as `-DLLVM_USE_LINKER` to CMake.
#use-linker = "lld"

指定LLVM的連接器,作為-DLLVM_USE_LINKER參數(shù)傳給cmake

[build]

# =============================================================================
# General build configuration options
# =============================================================================

構建配置。

build

# Build triple for the original snapshot compiler. This must be a compiler that
# nightlies are already produced for. The current platform must be able to run
# binaries of this build triple and the nightly will be used to bootstrap the
# first compiler.
#build = "x86_64-unknown-linux-gnu"    # defaults to your host platform

構建平臺。

host

# In addition to the build triple, other triples to produce full compiler
# toolchains for. Each of these triples will be bootstrapped from the build
# triple and then will continue to bootstrap themselves. This platform must
# currently be able to run all of the triples provided here.
#host = ["x86_64-unknown-linux-gnu"]   # defaults to just the build triple

運行平臺。

target

# In addition to all host triples, other triples to produce the standard library
# for. Each host triple will be used to produce a copy of the standard library
# for each target triple.
#target = ["x86_64-unknown-linux-gnu"] # defaults to just the build triple

目標平臺。

cargo

# Instead of downloading the src/stage0.txt version of Cargo specified, use
# this Cargo binary instead to build all Rust code
#cargo = "/path/to/bin/cargo"

指定構建所用的cargo,構建Rust 1.34.2所用的是cargo 0.34.0,可預先安裝到指定路徑,缺省時boostrap會默認從官網(wǎng)下載并自動解壓到臨時目錄build/cache/2019-02-28中使用。

rustc

# Instead of downloading the src/stage0.txt version of the compiler
# specified, use this rustc binary instead as the stage0 snapshot compiler.
#rustc = "/path/to/bin/rustc"

指定構建所用的rustc,構建Rust 1.34.2所用的是rustc 1.33.0,可預先安裝到指定路徑,缺省時boostrap會默認從官網(wǎng)下載并自動解壓到臨時目錄build/cache/2019-02-28中使用。

docs

# Flag to specify whether any documentation is built. If false, rustdoc and
# friends will still be compiled but they will not be used to generate any
# documentation.
#docs = true

指定是否生成文檔,如否,可自行使用rustdoc工具按需生成。

compiler-docs

# Indicate whether the compiler should be documented in addition to the standard
# library and facade crates.
#compiler-docs = false

指定(除了庫之外)是否生成編譯器本身的文檔。

submodules

# Indicate whether submodules are managed and updated automatically.
#submodules = true

指定是否使用Git子模塊管理工具Submodules。當ignore-git = false時,如果項目中沒有使用Submodules,該選項需關閉。

fast-submodules

# Update submodules only when the checked out commit in the submodules differs
# from what is committed in the main rustc repo.
#fast-submodules = true

使用Submodules時,指定僅當子模塊有提交時才進行更新,提高效率。

gdb

# The path to (or name of) the GDB executable to use. This is only used for
# executing the debuginfo test suite.
#gdb = "gdb"

指定gdb路徑。

nodejs

# The node.js executable to use. Note that this is only used for the emscripten
# target when running tests, otherwise this can be omitted.
#nodejs = "node"

用于在構建emscripten版本時指定nodejs。

python

# Python interpreter to use for various tasks throughout the build, notably
# rustdoc tests, the lldb python interpreter, and some dist bits and pieces.
# Note that Python 2 is currently required.
#python = "python2.7"

指定bootstrap所用的python。

locked-deps

# Force Cargo to check that Cargo.lock describes the precise dependency
# set that all the Cargo.toml files create, instead of updating it.
#locked-deps = false

指定cargo是否檢查Cargo.lock

vendor

# Indicate whether the vendored sources are used for Rust dependencies or not
#vendor = false

指定是否使用源碼中攜帶的三方crate(位于vendor目錄),若否,bootstrap將從crates.io所需crate,速度比較慢,可在.cargo/config中配置鏡像站。

full-bootstrap

# Typically the build system will build the rust compiler twice. The second
# compiler, however, will simply use its own libraries to link against. If you
# would rather to perform a full bootstrap, compiling the compiler three times,
# then you can set this option to true. You shouldn't ever need to set this
# option to true.
#full-bootstrap = false

默認的bootstrap只進行到stage2,該選項指定是否進行stage3。

extended

# Enable a build of the extended rust tool set which is not only the compiler
# but also tools such as Cargo. This will also produce "combined installers"
# which are used to install Rust and Cargo together. This is disabled by
# default.
#extended = false

指定是否生成除rustc外的其他工具,包括cargo、clippy、miri、rls、rustdoc、rustfmt、rust-gdb、rust-gdbgui、rust-lldb等。雖然說明中特別指出可以生成combined installers(總安裝包),但實踐表明并不能。

tools

# Installs chosen set of extended tools if enables. By default builds all.
# If chosen tool failed to build the installation fails.
#tools = ["cargo", "rls", "clippy", "rustfmt", "analysis", "src"]

配合extended食用,指定要生成哪些工具,默認生成全部。

verbose

# Verbosity level: 0 == not verbose, 1 == verbose, 2 == very verbose
#verbose = 0

指定是否輸出詳細的構建命令。

sanitizers

# Build the sanitizer runtimes
#sanitizers = false

指定是否構建內存檢測工具集sanitizers

profiler

# Build the profiler runtime
#profiler = false

指定是否構建優(yōu)化工具PGO

cargo-native-static

# Indicates whether the native libraries linked into Cargo will be statically
# linked or not.
#cargo-native-static = false

指定cargo的依賴庫是否靜態(tài)鏈接到cargo。

low-priority

# Run the build with low priority, by setting the process group's "nice" value
# to +10 on Unix platforms, and by using a "low priority" job object on Windows.
#low-priority = false

指定是否降低構建的優(yōu)先級,因為構建一次很占系統(tǒng)資源。

configure-args

# Arguments passed to the `./configure` script, used during distcheck. You
# probably won't fill this in but rather it's filled in by the `./configure`
# script.
#configure-args = []

使用./configure自動生成config.toml時,這里存著該腳本收到的參數(shù),手動配置config.toml時不用管該選項。

local-rebuild

# Indicates that a local rebuild is occurring instead of a full bootstrap,
# essentially skipping stage0 as the local compiler is recompiling itself again.
#local-rebuild = false

指定是否為一次重新編譯,可以跳過stage0。

print-step-timings

# Print out how long each rustbuild step took (mostly intended for CI and
# tracking over time)
#print-step-timings = false

指定是否輸出構建過程中每一步的耗時。

[install]

# =============================================================================
# General install configuration options
# =============================================================================

安裝配置。

prefix、sysconfdir、docdir、bindir、libdir、mandir、datadir、infodir、localstatedir

# Instead of installing to /usr/local, install to this path instead.
#prefix = "/usr/local"

# Where to install system configuration files
# If this is a relative path, it will get installed in `prefix` above
#sysconfdir = "/etc"

# Where to install documentation in `prefix` above
#docdir = "share/doc/rust"

# Where to install binaries in `prefix` above
#bindir = "bin"

# Where to install libraries in `prefix` above
#libdir = "lib"

# Where to install man pages in `prefix` above
#mandir = "share/man"

# Where to install data in `prefix` above (currently unused)
#datadir = "share"

# Where to install additional info in `prefix` above (currently unused)
#infodir = "share/info"

# Where to install local state (currently unused)
# If this is a relative path, it will get installed in `prefix` above
#localstatedir = "/var/lib"

指定安裝路徑。

[rust]

# =============================================================================
# Options for compiling Rust code itself
# =============================================================================

Rust編譯配置。

optimize

# Whether or not to optimize the compiler and standard library.
#
# Note: the slowness of the non optimized compiler compiling itself usually
#       outweighs the time gains in not doing optimizations, therefore a
#       full bootstrap takes much more time with `optimize` set to false.
#optimize = true

指定是否使用O2編譯。

debug

# Indicates that the build should be configured for debugging Rust. A
# `debug`-enabled compiler and standard library will be somewhat
# slower (due to e.g. checking of debug assertions) but should remain
# usable.
#
# Note: If this value is set to `true`, it will affect a number of
#       configuration options below as well, if they have been left
#       unconfigured in this file.
#
# Note: changes to the `debug` setting do *not* affect `optimize`
#       above. In theory, a "maximally debuggable" environment would
#       set `optimize` to `false` above to assist the introspection
#       facilities of debuggers like lldb and gdb. To recreate such an
#       environment, explicitly set `optimize` to `false` and `debug`
#       to `true`. In practice, everyone leaves `optimize` set to
#       `true`, because an unoptimized rustc with debugging
#       enabled becomes *unusably slow* (e.g. rust-lang/rust#24840
#       reported a 25x slowdown) and bootstrapping the supposed
#       "maximally debuggable" environment (notably libstd) takes
#       hours to build.
#
#debug = false

指定是否為debug版本。

codegen-units

# Number of codegen units to use for each compiler invocation. A value of 0
# means "the number of cores on this machine", and 1+ is passed through to the
# compiler.
#codegen-units = 1

指定二進制代碼生成階段的LLVM工作線程數(shù)。按理說該選項能很大程度加快構建速度,但實測效果并不明顯。

codegen-units-std

# Sets the number of codegen units to build the standard library with,
# regardless of what the codegen-unit setting for the rest of the compiler is.
#codegen-units-std = 1

std庫可獨立指定二進制代碼生成階段的LLVM工作線程數(shù),該選項不允許為0。

debug-assertions

# Whether or not debug assertions are enabled for the compiler and standard
# library.
#debug-assertions = false

指定是否啟用debug_assert!宏,在構建過程中進行一些斷言檢查。該宏在O0時默認啟用,詳見src/libcore/macros.rs中的注釋:

/// Unlike [`assert!`], `debug_assert!` statements are only enabled in non
/// optimized builds by default. An optimized build will omit all
/// `debug_assert!` statements unless `-C debug-assertions` is passed to the
/// compiler. This makes `debug_assert!` useful for checks that are too
/// expensive to be present in a release build but may be helpful during
/// development.

debuginfo、debuginfo-lines、debuginfo-only-std、debuginfo-tools

# Whether or not debuginfo is emitted
#debuginfo = false

# Whether or not line number debug information is emitted
#debuginfo-lines = false

# Whether or not to only build debuginfo for the standard library if enabled.
# If enabled, this will not compile the compiler with debuginfo, just the
# standard library.
#debuginfo-only-std = false

# Enable debuginfo for the extended tools: cargo, rls, rustfmt
# Adding debuginfo makes them several times larger.
#debuginfo-tools = false

指定是否添加調試信息。

backtrace

# Whether or not `panic!`s generate backtraces (RUST_BACKTRACE)
#backtrace = true

指定程序panic時是否打印回溯信息。配合debuginfo-lines=true食用更佳,以下摘自src/doc/rustc-guide/src/compiler-debugging.md

In the default configuration, you don't have line numbers enabled, so the
backtrace looks like this:

stack backtrace:
  0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
  1: std::sys_common::backtrace::_print
  2: std::panicking::default_hook::{{closure}}
  3: std::panicking::default_hook
  4: std::panicking::rust_panic_with_hook
  5: std::panicking::begin_panic
  (~~~~ LINES REMOVED BY ME FOR BREVITY ~~~~)
 32: rustc_typeck::check_crate
 33: <std::thread::local::LocalKey<T>>::with
 34: <std::thread::local::LocalKey<T>>::with
 35: rustc::ty::context::TyCtxt::create_and_enter
 36: rustc_driver::driver::compile_input
 37: rustc_driver::run_compiler

If you want line numbers for the stack trace, you can enable
debuginfo-lines=true or debuginfo=true in your config.toml and rebuild the
compiler. Then the backtrace will look like this:

stack backtrace:
  (~~~~ LINES REMOVED BY ME FOR BREVITY ~~~~)
            at /home/user/rust/src/librustc_typeck/check/cast.rs:110
  7: rustc_typeck::check::cast::CastCheck::check
            at /home/user/rust/src/librustc_typeck/check/cast.rs:572
            at /home/user/rust/src/librustc_typeck/check/cast.rs:460
            at /home/user/rust/src/librustc_typeck/check/cast.rs:370
  (~~~~ LINES REMOVED BY ME FOR BREVITY ~~~~)
 33: rustc_driver::driver::compile_input
            at /home/user/rust/src/librustc_driver/driver.rs:1010
            at /home/user/rust/src/librustc_driver/driver.rs:212
 34: rustc_driver::run_compiler
            at /home/user/rust/src/librustc_driver/lib.rs:253

incremental

# Whether to always use incremental compilation when building rustc
#incremental = false

指定是否采用增量編譯。

parallel-compiler

# Build a multi-threaded rustc
#parallel-compiler = false

指定是否生成多線程rustc。

default-linker

# The default linker that will be hard-coded into the generated compiler for
# targets that don't specify linker explicitly in their target specifications.
# Note that this is not the linker used to link said compiler.
#default-linker = "cc"

指定內嵌到編譯器中的默認鏈接器,在不指定-C linker時使用。注意不是構建編譯器本身時所用的鏈接器。

channel

# The "channel" for the Rust build to produce. The stable/beta channels only
# allow using stable features, whereas the nightly and dev channels allow using
# nightly features
#channel = "dev"

指定Rust的構建版本,devnightlystable。由于源碼中許多特性需要nightly支持,一般只在發(fā)布時指定為stable

rpath

# By default the `rustc` executable is built with `-Wl,-rpath` flags on Unix
# platforms to ensure that the compiler is usable by default from the build
# directory (as it links to a number of dynamic libraries). This may not be
# desired in distributions, for example.
#rpath = true

該選項通過-C link-args=-Wl,-rpath,$ORIGIN/../lib告知編譯器共享庫的搜索路徑(連接器ld通過-rpath設置運行時共享庫的搜索路徑),使其可以直接在build目錄下運行。

verbose-tests

# Emits extraneous output from tests to ensure that failures of the test
# harness are debuggable just from logfiles.
#verbose-tests = false

指定使用測試框架進行測試時是否輸出詳細信息。

optimize-tests、debuginfo-tests

# Flag indicating whether tests are compiled with optimizations (the -O flag) or
# with debuginfo (the -g flag)
#optimize-tests = true
#debuginfo-tests = true

設置使用測試框架進行測試時的-O-g選項。

codegen-tests

# Flag indicating whether codegen tests will be run or not. If you get an error
# saying that the FileCheck executable is missing, you may want to disable this.
# Also see the target's llvm-filecheck option.
#codegen-tests = true

指定測試框架是否測試用于驗證LLVM的子集src/test/codegen。使用二進制LLVM時,如果該選項打開(默認就是打開),需要指定llvm-filecheck

ignore-git

# Flag indicating whether git info will be retrieved from .git automatically.
# Having the git information can cause a lot of rebuilds during development.
# Note: If this attribute is not explicitly set (e.g. if left commented out) it
# will default to true if channel = "dev", but will default to false otherwise.
#ignore-git = true

指定是否忽略Git信息。使用Git管理源碼時,打開該選項可在rustc -Vrustc -vV添加Git提交本版的哈希碼和日期。

dist-src

# When creating source tarballs whether or not to create a source tarball.
#dist-src = false

指定是否生成源碼tar包,需要交付源碼時才打開。目前不清楚該選項在哪發(fā)揮作用,經(jīng)驗證./x.py dist受下面的src-tarball影響。

test-miri

# Whether to also run the Miri tests suite when running tests.
# As a side-effect also generates MIR for all libraries.
#test-miri = false

指定使用測試框架進行測試時是否測試miri(src/tools/miri/tests),也可以使用./x.py test src/tools/miri單獨進行測試。

save-toolstates

# After building or testing extended tools (e.g. clippy and rustfmt), append the
# result (broken, compiling, testing) into this JSON file.
#save-toolstates = "/path/to/toolstates.json"

指定工具集構建或測試結果的日志路徑。

codegen-backends

# This is an array of the codegen backends that will be compiled for the rustc
# that's being compiled. The default is to only build the LLVM codegen backend,
# but you can also optionally enable the "emscripten" backend for asm.js or
# make this an empty array (but that probably won't get too far in the
# bootstrap)
#codegen-backends = ["llvm"]

指定編譯器后端,目前只能是LLVM。

codegen-backends-dir

# This is the name of the directory in which codegen backends will get installed
#codegen-backends-dir = "codegen-backends"

自定義后端目標碼生成庫坐在的目錄名稱,默認為codegen-backendslib/rustlib/x86_64-unknown-linux-gnu/codegen-backends/librustc_codegen_llvm-llvm.so)。

wasm-syscall

# Flag indicating whether `libstd` calls an imported function to handle basic IO
# when targeting WebAssembly. Enable this to debug tests for the `wasm32-unknown-unknown`
# target, as without this option the test output will not be captured.
#wasm-syscall = false

WebAssembly專用。

lld

# Indicates whether LLD will be compiled and made available in the sysroot for
# rustc to execute.
#lld = false

指定是否構建LLD

llvm-tools

# Indicates whether some LLVM tools, like llvm-objdump, will be made available in the
# sysroot.
#llvm-tools = false

指定是否將生成的LLVM工具集添加至Rust的可執(zhí)行路徑。

lldb

# Indicates whether LLDB will be made available in the sysroot.
# This is only built if LLVM is also being built.
#lldb = false

指定是否構建LLDB

deny-warnings

# Whether to deny warnings in crates
#deny-warnings = true

指定是否禁用warning。

backtrace-on-ice

# Print backtrace on internal compiler errors during bootstrap
#backtrace-on-ice = false

指定bootstrap過程中遇到編譯器內部錯誤時是否打印回溯信息。

verify-llvm-ir

# Whether to verify generated LLVM IR
#verify-llvm-ir = false

指定生成LLVM IR后是否進行確認。

remap-debuginfo

# Map all debuginfo paths for libstd and crates to `/rust/$sha/$crate/...`,
# generally only set for releases
#remap-debuginfo = false

重定向調試信息?

jemalloc

# Link the compiler against `jemalloc`, where on Linux and OSX it should
# override the default allocator for rustc and LLVM.
#jemalloc = false

指定是否使用jemalloc代替默認的內存分配器。

test-compare-mode

# Run tests in various test suites with the "nll compare mode" in addition to
# running the tests in normal mode. Largely only used on CI and during local
# development of NLL
#test-compare-mode = false

指定測試框架測試模式(常規(guī)或NLL),針對src/test/ui子集,其部分用例有常規(guī)結果和NLL結果兩個stderr對比文件。

NLL是non-lexical lifetimes的意思,作為Rust編譯器的擴展特性(通過#![feature(nll)]開啟),意在優(yōu)化借用檢查。若無NLL,若某個變量被借用后又被更新會編譯不過,開啟NLL后,編譯器能識別借用與更新并不沖突的情況而允許通過。

? [譯] Rust - None Lexical Lifetimes (NLL) 使用指南

Rust防范「內存不安全」代碼的原則極其清晰明了。如果你對同一塊內存存在多個引用,就不要試圖對這塊內存做修改;如果你需要對一塊內存做修改,就不要同時保留多個引用。只要保證了這個原則,我們就可以保證內存安全。它在實踐中發(fā)揮了強大的作用,可以幫助我們盡早發(fā)現(xiàn)問題。這個原則是Rust的立身之本、生命之基、活力之源。

這個原則是沒問題的,但是,初始的實現(xiàn)版本有一個主要問題,那就是它讓借用指針的生命周期規(guī)則與普通對象的生命周期規(guī)則一樣,是按作用域來確定的。所有的變量、借用的生命周期就是從它的聲明開始,到當前整個語句塊結束。這個設計被稱為Lexical Lifetime,因為生命周期是嚴格和詞法中的作用域范圍綁定的。這個策略實現(xiàn)起來非常簡單,但它可能過于保守了,某些情況下借用的范圍被過度拉長了,以至于某些實質上是安全的代碼也被阻止了。在某些場景下,限制了程序員的發(fā)揮。

——《深入淺出Rust》

[target.x86_64-unknown-linux-gnu]

# =============================================================================
# Options for specific targets
#
# Each of the following options is scoped to the specific target triple in
# question and is used for determining how to compile each target.
# =============================================================================

目標平臺配置,可額外增加其他目標平臺的配置。

cc、cxx、ar、ranlib、linker

# C compiler to be used to compiler C code. Note that the
# default value is platform specific, and if not specified it may also depend on
# what platform is crossing to what platform.
#cc = "cc"

# C++ compiler to be used to compiler C++ code (e.g. LLVM and our LLVM shims).
# This is only used for host targets.
#cxx = "c++"

# Archiver to be used to assemble static libraries compiled from C/C++ code.
# Note: an absolute path should be used, otherwise LLVM build will break.
#ar = "ar"

# Ranlib to be used to assemble static libraries compiled from C/C++ code.
# Note: an absolute path should be used, otherwise LLVM build will break.
#ranlib = "ranlib"

# Linker to be used to link Rust code. Note that the
# default value is platform specific, and if not specified it may also depend on
# what platform is crossing to what platform.
#linker = "cc"

編譯、鏈接工具。

llvm-config

# Path to the `llvm-config` binary of the installation of a custom LLVM to link
# against. Note that if this is specified we don't compile LLVM at all for this
# target.
#llvm-config = "../path/to/llvm/root/bin/llvm-config"

指定llvm-config工具的安裝路徑,該選項旨在使用現(xiàn)成的二進制LLVM,可省去編譯LLVM的時間。debug-assertions打開時需配合llvm-filecheck選項食用。

使用現(xiàn)成LLVM時,dist包中將不包含在src/bootstrap/lib.rs中指定的LLVM工具:

const LLVM_TOOLS: &[&str] = &[
    "llvm-nm", // used to inspect binaries; it shows symbol names, their sizes and visibility
    "llvm-objcopy", // used to transform ELFs into binary format which flashing tools consume
    "llvm-objdump", // used to disassemble programs
    "llvm-profdata", // used to inspect and merge files generated by profiles
    "llvm-readobj", // used to get information from ELFs/objects that the other tools don't provide
    "llvm-size", // used to prints the size of the linker sections of a program
    "llvm-strip", // used to discard symbols from binary files to reduce their size
];

llvm-filecheck

# Normally the build system can find LLVM's FileCheck utility, but if
# not, you can specify an explicit file name for it.
#llvm-filecheck = "/path/to/FileCheck"

指定LLVM文件檢查工具FileCheck的路徑,與llvm-config位于同一目錄時無需指定。有趣的是,隨便給個叫FileCheck的文件就可以避免boostrap報找不到。

android-ndk

# If this target is for Android, this option will be required to specify where
# the NDK for the target lives. This is used to find the C compiler to link and
# build native code.
#android-ndk = "/path/to/ndk"

指定安卓開發(fā)套件NDK(Native Development Kit)的路徑。

crt-static

# Force static or dynamic linkage of the standard library for this target. If
# this target is a host for rustc, this will also affect the linkage of the
# compiler itself. This is useful for building rustc on targets that normally
# only use static libraries. If unset, the target's default linkage is used.
#crt-static = false

指定目標平臺的std庫是動態(tài)還是靜態(tài)鏈接。

musl-root

# The root location of the MUSL installation directory. The library directory
# will also need to contain libunwind.a for an unwinding implementation. Note
# that this option only makes sense for MUSL targets that produce statically
# linked binaries
#musl-root = "..."

MUSL專用。

qemu-rootfs

# Used in testing for configuring where the QEMU images are located, you
# probably don't want to use this.
#qemu-rootfs = "..."

QEMU專用。

[dist]

# =============================================================================
# Distribution options
#
# These options are related to distribution, mostly for the Rust project itself.
# You probably won't need to concern yourself with any of these options
# =============================================================================

發(fā)布配置。

sign-folder

# This is the folder of artifacts that the build system will sign. All files in
# this directory will be signed with the default gpg key using the system `gpg`
# binary. The `asc` and `sha256` files will all be output into the standard dist
# output folder (currently `build/dist`)
#
# This folder should be populated ahead of time before the build system is
# invoked.
#sign-folder = "path/to/folder/to/sign"

指定需要gpg加密的目錄。

gpg-password-file

# This is a file which contains the password of the default gpg key. This will
# be passed to `gpg` down the road when signing all files in `sign-folder`
# above. This should be stored in plaintext.
#gpg-password-file = "path/to/gpg/password"

指定gpg密鑰文件。

upload-addr

# The remote address that all artifacts will eventually be uploaded to. The
# build system generates manifests which will point to these urls, and for the
# manifests to be correct they'll have to have the right URLs encoded.
#
# Note that this address should not contain a trailing slash as file names will
# be appended to it.
#upload-addr = "https://example.com/folder"

指定線上發(fā)布的網(wǎng)址(上傳地址)。

src-tarball

# Whether to build a plain source tarball to upload
# We disable that on Windows not to override the one already uploaded on S3
# as the one built on Windows will contain backslashes in paths causing problems
# on linux
#src-tarball = true

指定是否生成源碼tar包,需要交付源碼時才打開。

missing-tools

# Whether to allow failures when building tools
#missing-tools = false

指定構建工具時是否允許出錯。


2020年8月7日、10~12日 無錫

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。