Skip to content

ZhengjunHUO/rust-playground

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rust-playground

Installation / Upgrade

$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
$ rustup update

When unstable features engaged, use nightly build

$ rustup override set nightly
$ rustup show
$ rustup override unset
$ echo '[toolchain]\nchannel = "nightly"' > rust-toolchain.toml

Perform macro expansion to debug

$ rustc -Zunpretty=expanded src/main.rs

Log level

$ RUST_LOG=debug ...

Fmt & Lint

$ rustup component add rustfmt

$ cargo clippy

See the println in cargo test

$ cargo test -- --nocapture

Find out crate's dependencies

$ cargo tree --target=x86_64-unknown-linux-musl -i openssl-sys

Docs

# Check std doc
$ rustup component add rust-docs
$ rustup doc

# Current crate's doc
$ cargo doc [--no-deps] --open

Static C runtime linkage

$ rustup target add x86_64-unknown-linux-musl
# Fedora
$ sudo dnf install musl-gcc
# Ubuntu
$ sudo apt install build-essential libssl-dev g++ musl-tools pkg-config
$ sudo ln -s /bin/g++ /bin/musl-g++
$ RUSTFLAGS='-C target-feature=+crt-static' cargo build --release --target x86_64-unknown-linux-musl

Error caused by libssl during build (useful command $ pkg-config --libs --cflags openssl)

  run pkg_config fail: pkg-config has not been configured to support cross-compilation.

  Install a sysroot for the target platform and configure it via
  PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH, or install a
  cross-compiling wrapper for pkg-config and set it via
  PKG_CONFIG environment variable.

  --- stderr
  thread 'main' panicked at '

  Could not find directory of OpenSSL installation, and this `-sys` crate cannot
  proceed without this knowledge. If OpenSSL is installed and this crate had
  trouble finding it,  you can set the `OPENSSL_DIR` environment variable for the
  compilation process.

  Make sure you also have the development packages of openssl installed.
  For example, `libssl-dev` on Ubuntu or `openssl-devel` on Fedora.

  If you're in a situation where you think the directory *should* be found
  automatically, please open a bug at https://github.com/sfackler/rust-openssl
  and include information about your system as well as this message.

  $HOST = x86_64-unknown-linux-gnu
  $TARGET = x86_64-unknown-linux-musl
  openssl-sys = 0.9.90

Specify vendored feature in Cargo.toml

openssl-sys = {version = "0.9.90", features = ["vendored"]}

Test coverage

$ rustup component add llvm-tools
$ CARGO_INCREMENTAL=0 RUSTFLAGS='-Cinstrument-coverage' LLVM_PROFILE_FILE='cargo-test-%p-%m.profraw' cargo test
$ grcov . --binary-path ./target/debug/ -s . -t html --branch --ignore-not-existing -o ./target/debug/coverage/
# check target/debug/coverage/index.html

Using tokio

Aya BPF prerequis

$ rustup install stable
$ rustup toolchain install nightly --component rust-src
$ cargo install bpf-linker
$ cargo install cargo-generate
$ sudo apt install libssl-dev linux-tools-common
$ cargo generate https://github.com/aya-rs/aya-template

About

explore Rust in different aspects

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages