File: cfg.rs

package info (click to toggle)
rust-cbindgen 0.27.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,616 kB
  • sloc: ansic: 15; makefile: 11
file content (85 lines) | stat: -rw-r--r-- 1,298 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#[cfg(all(unix, x11))]
#[repr(u32)]
enum FooType {
  A,
  B,
  C,
}

#[cfg(all(unix, x11))]
#[repr(C)]
struct FooHandle {
    ty: FooType,
    x: i32,
    y: f32,
}

#[cfg(any(windows, target_pointer_width="32"))]
#[repr(u32)]
enum BarType {
  A,
  B,
  C,
}

#[repr(u8)]
pub enum C {
    C1,
    C2,
    #[cfg(windows)]
    C3,
    #[cfg(unix)]
    C5 { int: i32 },
}

#[cfg(any(windows, target_pointer_width="32"))]
#[repr(C)]
struct BarHandle {
    ty: BarType,
    x: i32,
    y: f32,
}

// FIXME(#634): Support deriving methods for structs with conditional fields.
/// cbindgen:derive-eq=false
/// cbindgen:derive-neq=false
#[repr(C)]
struct ConditionalField {
    #[cfg(x11)]
    field: i32,
}

#[cfg(all(unix, x11))]
#[no_mangle]
pub extern "C" fn root(a: FooHandle, c: C)
{ }

#[cfg(any(windows, target_pointer_width="32"))]
#[no_mangle]
pub extern "C" fn root(a: BarHandle, c: C)
{ }

#[no_mangle]
pub extern "C" fn cond(a: ConditionalField)
{ }

// src/lib.rs
#[repr(C)]
struct Normal {
    x: i32,
    y: f32,
}

#[cfg(windows)]
extern "C" {
    fn foo() -> i32;

    fn bar(a: Normal);
}

#[cfg(windows)]
#[no_mangle]
pub static mut global_array_with_different_sizes: [i32; 2] = [123, 456];
#[cfg(unix)]
#[no_mangle]
pub static mut global_array_with_different_sizes: [i32; 1] = [7890];