Setup develop environment - faas-rs/faasd-in-rust GitHub Wiki
Thanks to the nix
, we can easily develop the project in a reproducible environment. The following steps will guide you through the process.
nix environment
-
nix installation
-
home-manager
Manage nix features (flakes) and direnv (Optional)
https://nix-community.github.io/home-manager/index.xhtml#sec-install-standalone
-
direnv
For development environment activation
https://github.com/nix-community/nix-direnv#via-home-manager
-
VSCode extensions
Automatically environment activation. We have recommand extensions:
- pinage404.nix-extension-pack: provide direnv and essentials for activating nix dev env
- rust-lang.rust-analyzer: Rust language support
shell interactions
There are several integrated nix commands that can help you develop the project.
nix develop
Enter the default development shell. Usually already activated when you open the repo dir if you configured nix env correctly.nix build
Build the project, the result will be atresult/bin/faas-rs
nix flake check
Do the CI checks, including formatting, linting...
Besides, you can also use the cargo
command to interact with the project in the shell. Nix will automatically manage the toolchain and library dependencies for you.
[!NOTE] The project uses
cargo-hakari
to optimize the build time. If you don't know what it is, after new dependencies are added, you should runcargo hakari generate
to update the dependencies. Details below.
Rust Environment with crane
Reference: https://crane.dev/examples/quick-start-workspace.html
If you add an extra crate into crates
dir, make sure add it in to Cargo.toml
under the my-workspace-hack
crate, and add the dir path to flake.nix
:
fileSetForCrate = crate: lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./Cargo.toml
./Cargo.lock
(craneLib.fileset.commonCargoSources ./crates/app)
(craneLib.fileset.commonCargoSources ./crates/service)
(craneLib.fileset.commonCargoSources ./crates/provider)
(craneLib.fileset.commonCargoSources ./crates/cni)
(craneLib.fileset.commonCargoSources ./crates/my-workspace-hack)
(craneLib.fileset.commonCargoSources crate)
];
};