Rust Notes

Collections of notes about the Rust programming language.

Release Flags and Options

Release profile (in Cargo.toml).

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
[profile.release]
opt-level        = 3
strip            = "symbols"
debug            = false
debug-assertions = false
overflow-checks  = false
lto              = "fat"
panic            = "unwind"
incremental      = false
codegen-units    = 1
rpath            = false

See the documentation for information about each setting.

Compilation flags.

1
2
3
MACOSX_DEPLOYMENT_TARGET=$(sw_vers -productVersion) \
	RUSTFLAGS="-C target-cpu=native" \
	cargo build --release

Flags:

Rustdoc

Documenting private types.

1
cargo doc --document-private-items

Sanitizers

See https://github.com/japaric/rust-san and the documentation.

1
2
3
4
RUSTFLAGS="-Z sanitizer=leak"    cargo test --all-features --target x86_64-unknown-linux-gnu
RUSTFLAGS="-Z sanitizer=address" cargo test --all-features --target x86_64-unknown-linux-gnu
RUSTFLAGS="-Z sanitizer=memory"  cargo test --all-features --target x86_64-unknown-linux-gnu
RUSTFLAGS="-Z sanitizer=thread"  cargo test --all-features --target x86_64-unknown-linux-gnu

A Makefile for Rust

Also see the latest version used in Heph.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Targets available via Rustup that are supported.
TARGETS ?= x86_64-apple-darwin x86_64-unknown-linux-gnu x86_64-unknown-freebsd
# Command to run in `dev` target, e.g. `make RUN=check dev`.
RUN ?= test

test:
	cargo test

check:
	cargo check --all-features --all-targets

check_all_targets: $(TARGETS)
$(TARGETS):
	cargo check --all-features --workspace --all-targets --target $@

# NOTE: when using this command you might want to change the `test` target to
# only run a subset of the tests you're actively working on.
dev:
	find src/ tests/ examples/ Makefile Cargo.toml | entr -d -c $(MAKE) $(RUN)

clippy: lint
lint:
	cargo clippy --all-features

install_clippy:
	rustup component add clippy

doc:
	cargo doc --all-features

doc_private:
	cargo doc --all-features --document-private-items

clean:
	cargo clean

.PHONY: test check check_all check_all_targets dev clippy lint install_clippy doc doc_private clean