Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • redox-os/cbindgen
  • xTibor/cbindgen
  • dlrobertson/cbindgen
  • alebcay/cbindgen
  • mati865/cbindgen
5 results
Show changes
Commits on Source (8)
...@@ -133,11 +133,13 @@ impl Bindings { ...@@ -133,11 +133,13 @@ impl Bindings {
out.new_line(); out.new_line();
} }
if self.config.language == Language::Cxx { out.new_line_if_not_start();
out.new_line_if_not_start(); out.write("#ifdef __cplusplus");
out.write("extern \"C\" {"); out.new_line();
out.new_line(); out.write("extern \"C\" {");
} out.new_line();
out.write("#endif");
out.new_line();
for global in &self.globals { for global in &self.globals {
out.new_line_if_not_start(); out.new_line_if_not_start();
...@@ -157,11 +159,15 @@ impl Bindings { ...@@ -157,11 +159,15 @@ impl Bindings {
out.new_line(); out.new_line();
} }
if self.config.language == Language::Cxx { out.new_line_if_not_start();
out.new_line_if_not_start(); out.write("#ifdef __cplusplus");
out.write("} // extern \"C\""); out.new_line();
out.new_line(); out.write("} // extern \"C\"");
out.new_line();
out.write("#endif");
out.new_line();
if self.config.language == Language::Cxx {
self.close_namespaces(&mut out); self.close_namespaces(&mut out);
} }
......
...@@ -58,7 +58,7 @@ impl AnnotationSet { ...@@ -58,7 +58,7 @@ impl AnnotationSet {
{ {
let comment = comment.value(); let comment = comment.value();
if &*ident.to_string() == "doc" { if &*ident.to_string() == "doc" {
let line = comment.trim_left_matches("///").trim(); let line = comment.trim_start_matches("///").trim();
if line.starts_with("cbindgen:") { if line.starts_with("cbindgen:") {
lines.push(line.to_owned()); lines.push(line.to_owned());
} }
......
...@@ -38,11 +38,11 @@ impl Documentation { ...@@ -38,11 +38,11 @@ impl Documentation {
if &*name == "doc" { if &*name == "doc" {
let line = if attr.is_sugared_doc { let line = if attr.is_sugared_doc {
comment comment
.trim_left_matches("/// ") .trim_start_matches("/// ")
.trim_left_matches("///") .trim_start_matches("///")
.trim_right() .trim_end()
} else { } else {
comment.trim_left_matches(" ").trim_right() comment.trim_start_matches(" ").trim_end()
}; };
if !line.starts_with("cbindgen:") { if !line.starts_with("cbindgen:") {
doc.push(line.to_owned()); doc.push(line.to_owned());
......
...@@ -45,6 +45,7 @@ pub enum PrimitiveType { ...@@ -45,6 +45,7 @@ pub enum PrimitiveType {
Int64, Int64,
Float, Float,
Double, Double,
VaList,
//SizeT, //SizeT,
} }
...@@ -79,6 +80,7 @@ impl PrimitiveType { ...@@ -79,6 +80,7 @@ impl PrimitiveType {
"i64" | "int64_t" => Some(PrimitiveType::Int64), "i64" | "int64_t" => Some(PrimitiveType::Int64),
"f32" => Some(PrimitiveType::Float), "f32" => Some(PrimitiveType::Float),
"f64" => Some(PrimitiveType::Double), "f64" => Some(PrimitiveType::Double),
"VaList" => Some(PrimitiveType::VaList),
//"size_t" => Some(PrimitiveType::SizeT), //"size_t" => Some(PrimitiveType::SizeT),
_ => None, _ => None,
} }
...@@ -112,6 +114,7 @@ impl PrimitiveType { ...@@ -112,6 +114,7 @@ impl PrimitiveType {
&PrimitiveType::Int64 => "i64", &PrimitiveType::Int64 => "i64",
&PrimitiveType::Float => "f32", &PrimitiveType::Float => "f32",
&PrimitiveType::Double => "f64", &PrimitiveType::Double => "f64",
&PrimitiveType::VaList => "va_list",
//&PrimitiveType::SizeT => "size_t", //&PrimitiveType::SizeT => "size_t",
} }
} }
...@@ -144,6 +147,7 @@ impl PrimitiveType { ...@@ -144,6 +147,7 @@ impl PrimitiveType {
&PrimitiveType::Int64 => "int64_t", &PrimitiveType::Int64 => "int64_t",
&PrimitiveType::Float => "float", &PrimitiveType::Float => "float",
&PrimitiveType::Double => "double", &PrimitiveType::Double => "double",
&PrimitiveType::VaList => "va_list",
//&PrimitiveType::SizeT => "size_t", //&PrimitiveType::SizeT => "size_t",
} }
} }
......
...@@ -313,12 +313,35 @@ impl Parser { ...@@ -313,12 +313,35 @@ impl Parser {
} else if next_mod_path2.exists() { } else if next_mod_path2.exists() {
self.parse_mod(pkg, next_mod_path2.as_path())?; self.parse_mod(pkg, next_mod_path2.as_path())?;
} else { } else {
// Last chance to find a module path
let mut path_attr_found = false;
for attr in &item.attrs {
if attr.is_sugared_doc {
continue;
}
match attr.interpret_meta() {
Some(syn::Meta::NameValue(syn::MetaNameValue { ident, lit, ..})) => {
match (ident.as_ref(), lit) {
("path", syn::Lit::Str(ref path)) => {
path_attr_found = true;
self.parse_mod(pkg, &mod_dir.join(path.value()))?;
}
_ => (),
}
}
_ => (),
}
}
// This should be an error, but it's common enough to // This should be an error, but it's common enough to
// just elicit a warning // just elicit a warning
warn!( if !path_attr_found {
"Parsing crate `{}`: can't find mod {}`.", warn!(
pkg.name, next_mod_name "Parsing crate `{}`: can't find mod {}`.",
); pkg.name, next_mod_name
);
}
} }
} }
......
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#define EXPORT_ME_TOO 42
typedef struct {
uint64_t val;
} ExportMe;
void export_me(ExportMe *val);
#include <cstdint>
#include <cstdlib>
static const uint8_t EXPORT_ME_TOO = 42;
struct ExportMe {
uint64_t val;
};
extern "C" {
void export_me(ExportMe *val);
} // extern "C"
[[package]]
name = "mod_path"
version = "0.1.0"
[package]
name = "mod_path"
version = "0.1.0"
authors = ["cbindgen"]
[lib]
name = "mod_path"
crate-type = ["lib", "dylib"]
[parse]
parse_deps = false
#[path = "other.rs"]
mod inner;
pub use inner::*;
#[repr(C)]
pub struct ExportMe {
val: u64
}
#[repr(C)]
pub struct DoNotExportMe {
val: u64
}
pub const EXPORT_ME_TOO: u8 = 0x2a;
#[no_mangle]
pub unsafe extern "C" fn export_me(val: *mut ExportMe) { }