understanding conditional compiling

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

understanding conditional compiling

google
Hi folks,


I'm currently trying to how conditional compiling in rust
actually works. I was under the impression that

     #[cfg(feature = "foo")]

behaves pretty much like an #ifdef, but for the subsequent
syntactical block, so instead of

     #ifdef ENABLE_FOO
     fn ... {
     }
     #endif

you istead write

     #[cfg(feature = "foo")]
     fn ... {
     }

BUT: there're lots of cases, where this doesn't seem to work, eg.
with if statements. An 'if cfg!(feature = "foo")' doesn't work for
me, as lots of types in the disabled code pathes won't exist at all.
Similar w/ 'use' statements, parameter lists, match statements, ...

background: I'm currently trying to trim down Servo, as it doesn't
compile on 32bit system (don't have an 64bit environment right now)
and I'd like to get rid of lots of things (eg. bluetooth, gamepad, etc)
anyways.


--mtx
_______________________________________________
Rust-dev mailing list
[hidden email]
https://mail.mozilla.org/listinfo/rust-dev
Reply | Threaded
Open this post in threaded view
|

Re: understanding conditional compiling

Diggory Hardy
I'd suggest you ask on https://users.rust-lang.org/ since this mailing list is
"closed".

On Wednesday, 20 December 2017 16:18:08 GMT google wrote:

> Hi folks,
>
>
> I'm currently trying to how conditional compiling in rust
> actually works. I was under the impression that
>
>      #[cfg(feature = "foo")]
>
> behaves pretty much like an #ifdef, but for the subsequent
> syntactical block, so instead of
>
>      #ifdef ENABLE_FOO
>      fn ... {
>      }
>      #endif
>
> you istead write
>
>      #[cfg(feature = "foo")]
>      fn ... {
>      }
>
> BUT: there're lots of cases, where this doesn't seem to work, eg.
> with if statements. An 'if cfg!(feature = "foo")' doesn't work for
> me, as lots of types in the disabled code pathes won't exist at all.
> Similar w/ 'use' statements, parameter lists, match statements, ...
>
> background: I'm currently trying to trim down Servo, as it doesn't
> compile on 32bit system (don't have an 64bit environment right now)
> and I'd like to get rid of lots of things (eg. bluetooth, gamepad, etc)
> anyways.
>
>
> --mtx
> _______________________________________________
> Rust-dev mailing list
> [hidden email]
> https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________
Rust-dev mailing list
[hidden email]
https://mail.mozilla.org/listinfo/rust-dev