Discussion:
[rust-dev] FFI: how to deal with different platforms
Fox, Michael
2014-09-08 01:03:26 UTC
Permalink
How can FFI work across platforms unless you compile against the specific platform?s headers?

Sometimes a common header defines the same-named structure, type or macro differently depending on your platform.

For example, here?s a definition from termios.h on OSX:

#define CSIZE 0x00000300 /* character size mask */

And here?s the same one on some old Linux:

#define CSIZE 0000060

So, you can?t just take one of them and define it like:

pub static CSIZE: ulong_t = 0x300;

I don?t see how it can work unless you embed a C compiler which reads and uses the actual platform?s headers.
Jack Moffitt
2014-09-08 16:44:56 UTC
Permalink
Post by Fox, Michael
Sometimes a common header defines the same-named structure, type or macro differently depending on your platform.
#define CSIZE 0x00000300 /* character size mask */
#define CSIZE 0000060
You'll need to do something like this:

#[cfg(target_os="macos")]
pub static CSIZE: ulong_t = 0x300;
#[cfg(target_os="linux")]
pub static CSIZE: ulong_t = 0x60;

jack.
Sean McArthur
2014-09-08 16:49:48 UTC
Permalink
You can use define the CSIZE a couple times in your file, with conditional
compilation: http://doc.rust-lang.org/rust.html#conditional-compilation


On Sun, Sep 7, 2014 at 6:03 PM, Fox, Michael <Michael.Fox at caviumnetworks.com
Post by Fox, Michael
How can FFI work across platforms unless you compile against the specific
platform?s headers?
Sometimes a common header defines the same-named structure, type or macro
differently depending on your platform.
#define CSIZE 0x00000300 /* character size mask */
#define CSIZE 0000060
pub static CSIZE: ulong_t = 0x300;
I don?t see how it can work unless you embed a C compiler which reads and
uses the actual platform?s headers.
_______________________________________________
Rust-dev mailing list
Rust-dev at mozilla.org
https://mail.mozilla.org/listinfo/rust-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140908/13930c5f/attachment.html>
Loading...