this post was submitted on 18 Mar 2024
11 points (92.3% liked)

Rust

5807 readers
54 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

[email protected]

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS
 

Hello,

I have a project for which some machines have only a subset of features set. Currently, I write

cargo run --no-default-features --features "toto,titi" --bin my_bin

This is a bit cumbersome and I sometimes forget the --no-default-features --features part. I was wondering if there is a local config file that I could put in the directory to instruct cargo to use this particular subset of features. I guess this should be in the documentation, but I didn't find it.

top 7 comments
sorted by: hot top controversial new old
[–] [email protected] 3 points 6 months ago* (last edited 6 months ago) (1 children)

The way I can think of to do this is to make a program called cargo-build-env which reads a file of your choosing with the features and executes cargo, then place that binary in your ~/.cargo/bin directory. Then you can run cargo build-env to build your program

The program can be in any language as long as it's executable, including shell script

[–] [email protected] 3 points 6 months ago* (last edited 6 months ago)

Yeah, a simple bash script should do. Such as:

#!/usr/bin/env bash

BUILD_FEATURES=${BUILD_FEATURES:=default}

cargo run --no-default-features --features "${BUILD_FEATURES}" --bin my_bin

Then just set a BUILD_FEATURES env var.

[–] [email protected] 1 points 6 months ago

Not cargo, but I use justfiles in all my projects: https://github.com/casey/just Its great for aliasing project-specific commands like what you have.

[–] [email protected] 1 points 6 months ago
[–] [email protected] 1 points 6 months ago (1 children)

You can setup a cargo configuration file, in it you put a manifest and define some profiles, and in them define what features you want compiled

[–] [email protected] 2 points 6 months ago (1 children)

This would look like it would be what I am looking for, but the documentation of the configuration file does not mention features.

[–] [email protected] 1 points 6 months ago

https://doc.rust-lang.org/cargo/reference/manifest.html

it's the sixth from the bottom in the table of contents