0

I'm using #![no_main] so I can use SDL2main on Windows and Android but I would like to have it conditionally used so I can run Rust's built-in test harness on Linux.

I've tried:

#[cfg(not(test))]
#![no_main]

and

include!(concat!("cfg_test_", cfg!(test), ".rs"));

where cfg_test_false.rs contains #![no_main] and cfg_test_true.rs doesn't.

Neither of them work.

I know I can fall back to generating main.rs using build.rs but I'm hoping there is a better way, as from what I know, it will have to generate the main.rs in the src directory instead of ${OUT_DIR}.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
programmerjake
  • 1,794
  • 11
  • 15
  • does `#![cfg_attr(not(test), no_main)]` work? For using android you need a cdylib, not a binary. – Tim Diekmann Aug 01 '18 at 10:34
  • 1
    Hi! I think your question is answered by [this Q&A](https://stackoverflow.com/questions/42551113/is-it-possible-to-conditionally-derive-with-features/42551386). tl;dr: `#[cfg_attr(not(test), no_main)]`. But I'm not sure if I would actually close this question as a dupe since the question I linked asks about *deriving* and only happens to have an answer that fits here, too. Maybe someone else has an opinion about this. – Lukas Kalbertodt Aug 01 '18 at 10:34
  • This should be more prominent in rust-lang's docs as I couldn't find that info after an hour of googling – programmerjake Aug 01 '18 at 10:39
  • @Tim I hadn't actually gotten around to building on android yet, i just know that sdl is a pain to use on android because you can't even use something like `WinMain`. I think Windows Mobile and iOS are equally painful, but don't remember for sure – programmerjake Aug 01 '18 at 10:43

0 Answers0