Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
redox-os
cbindgen
Commits
42454fed
Commit
42454fed
authored
Jun 21, 2017
by
Ryan Hunt
Browse files
Make build scripts more ergonomic
Fixes #19
parent
060a79f0
Changes
3
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
42454fed
...
...
@@ -32,17 +32,13 @@ Here's an example build.rs script:
extern
crate
cbindgen
;
use
std
::
env
;
use
cbindgen
::{
Config
,
Library
};
fn
main
()
{
let
root
=
env
::
var
(
"CARGO_MANIFEST_DIR"
)
.unwrap
();
let
config
=
Config
::
from_root_or_default
(
&
root
);
Library
::
load_crate
(
Path
::
new
(
root
),
"CRATE_NAME"
,
&
config
)
.generate
()
.unwrap
()
.write_to_file
(
"bindings.h"
);
let
crate_dir
=
env
::
var
(
"CARGO_MANIFEST_DIR"
)
.unwrap
();
cbindgen
::
generate
(
crate_dir
)
.unwrap
()
.write_to_file
(
"bindings.h"
);
}
```
...
...
src/bindgen/mod.rs
View file @
42454fed
...
...
@@ -51,5 +51,5 @@ mod writer;
pub
use
self
::
cargo
::
*
;
pub
use
self
::
config
::
*
;
pub
use
self
::
library
::
Library
;
pub
use
self
::
library
::
{
GeneratedBindings
,
Library
}
;
pub
use
self
::
cargo_toml
::
manifest
;
src/lib.rs
View file @
42454fed
...
...
@@ -14,3 +14,19 @@ extern crate toml;
mod
bindgen
;
pub
use
bindgen
::
*
;
use
std
::
path
::
Path
;
/// A utility function for build scripts to generate bindings for a crate, using
/// a `cbindgen.toml` if it exists.
pub
fn
generate
(
crate_dir
:
&
str
)
->
Result
<
GeneratedBindings
,
String
>
{
let
crate_dir
=
Path
::
new
(
crate_dir
);
Library
::
load_crate
(
Cargo
::
load
(
crate_dir
,
None
)
?
,
&
Config
::
from_root_or_default
(
crate_dir
))
?
.generate
()
}
/// A utility function for build scripts to generate bindings for a crate with a
/// custom config.
pub
fn
generate_config
(
crate_dir
:
&
str
,
config
:
&
Config
)
->
Result
<
GeneratedBindings
,
String
>
{
Library
::
load_crate
(
Cargo
::
load
(
Path
::
new
(
crate_dir
),
None
)
?
,
config
)
?
.generate
()
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment