gobanos / cargo-aoc

452 stars 48 forks source link

--features support #32

Open DarthGandalf opened 5 years ago

DarthGandalf commented 5 years ago

I want to add visualisation, but I don't want it every time, because it slows things down, so I want something like cargo aoc --features video which would enable video:

#[aoc(day1, part1)]
fn part1(input: &[i32]) -> i32 {
  #[cfg(feature = "video")]
  let mut video = ...;
  for i in input {
    ...
    #[cfg(feature = "video")]
    video.add_frame(...);
  }
  42
}

Two workarounds which I see now, is to change default back and forth in Cargo.toml:

[features]
video = []
defaults = ["video"]

or to decide it in runtime based on some environment variable.

gobanos commented 4 years ago

It might be possible to read Cargo.toml features section and add them to the template crate run by cargo aoc.

DarthGandalf commented 4 years ago

Yeah, that's not what I meant though. I'm using that workaround already. When the generated crate uses my crate as a dependency, cargo reads the defaults section of my Cargo.toml just fine. But that requires me to change the defaults section every time, which is not the intended purpose of it.

What I want is to run cargo aoc --features foo without changing my Cargo.toml, then cargo-aoc doesn't need to parse Cargo.toml at all, but only parse its own command line arguments.