Skip to content

Commit

Permalink
Release 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jan 8, 2020
1 parent 7db7369 commit e43b737
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 99 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "cxx"
version = "0.0.0"
version = "0.1.0"
authors = ["David Tolnay <[email protected]>"]
edition = "2018"
links = "cxxbridge00"
links = "cxxbridge01"
license = "MIT OR Apache-2.0"
description = "Safe interop between Rust and C++"
repository = "https://github.com/dtolnay/cxx"
Expand All @@ -18,7 +18,7 @@ anyhow = "1.0"
cc = "1.0.49"
codespan = "0.7"
codespan-reporting = "0.7"
cxxbridge-macro = { version = "0.0", path = "macro" }
cxxbridge-macro = { version = "0.1", path = "macro" }
proc-macro2 = { version = "1.0", features = ["span-locations"] }
quote = "1.0"
syn = { version = "1.0", features = ["full"] }
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using bindgen or cbindgen to generate unsafe C-style bindings.

```toml
[dependencies]
cxx = "0.0"
cxx = "0.1"
```

*Compiler support: requires rustc 1.42+ (beta on January 30, stable on March
Expand Down Expand Up @@ -294,9 +294,9 @@ of functions.
<tr><th>name in Rust</th><th>name in C++</th><th>restrictions</th></tr>
<tr><td>String</td><td>cxxbridge::RustString</td><td></td></tr>
<tr><td>&amp;str</td><td>cxxbridge::RustStr</td><td></td></tr>
<tr><td><a href="https://docs.rs/cxx/0.0/cxx/struct.CxxString.html">CxxString</a></td><td>std::string</td><td><sup><i>cannot be passed by value</i></sup></td></tr>
<tr><td><a href="https://docs.rs/cxx/0.1/cxx/struct.CxxString.html">CxxString</a></td><td>std::string</td><td><sup><i>cannot be passed by value</i></sup></td></tr>
<tr><td>Box&lt;T&gt;</td><td>cxxbridge::RustBox&lt;T&gt;</td><td><sup><i>cannot hold opaque C++ type</i></sup></td></tr>
<tr><td><a href="https://docs.rs/cxx/0.0/cxx/struct.UniquePtr.html">UniquePtr&lt;T&gt;</a></td><td>std::unique_ptr&lt;T&gt;</td><td><sup><i>cannot hold opaque Rust type</i></sup></td></tr>
<tr><td><a href="https://docs.rs/cxx/0.1/cxx/struct.UniquePtr.html">UniquePtr&lt;T&gt;</a></td><td>std::unique_ptr&lt;T&gt;</td><td><sup><i>cannot hold opaque Rust type</i></sup></td></tr>
<tr><td></td><td></td><td></td></tr>
</table>

Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ fn main() {
cc::Build::new()
.file("src/cxxbridge.cc")
.flag("-std=c++11")
.compile("cxxbridge00");
.compile("cxxbridge01");
println!("cargo:rustc-flags=-l dylib=stdc++");
println!("cargo:rerun-if-changed=src/cxxbridge.cc");
println!("cargo:rerun-if-changed=include/cxxbridge.h");
Expand Down
2 changes: 1 addition & 1 deletion cmd/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cxxbridge-cmd"
version = "0.0.0"
version = "0.1.0"
authors = ["David Tolnay <[email protected]>"]
edition = "2018"
license = "MIT OR Apache-2.0"
Expand Down
58 changes: 29 additions & 29 deletions gen/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ fn write_include_cxxbridge(out: &mut OutFile, types: &Types) {
}
}

out.begin_block("namespace cxxbridge00");
out.begin_block("namespace cxxbridge01");
if needs_rust_box {
writeln!(out, "// #include \"cxxbridge.h\"");
for line in include::get("CXXBRIDGE00_RUST_BOX").lines() {
for line in include::get("CXXBRIDGE01_RUST_BOX").lines() {
if !line.trim_start().starts_with("//") {
writeln!(out, "{}", line);
}
Expand All @@ -146,7 +146,7 @@ fn write_namespace_alias(out: &mut OutFile, types: &Types) {
}

if needs_namespace_alias {
writeln!(out, "namespace cxxbridge = cxxbridge00;");
writeln!(out, "namespace cxxbridge = cxxbridge01;");
}
}

Expand Down Expand Up @@ -176,7 +176,7 @@ fn write_cxx_function_shim(out: &mut OutFile, efn: &ExternFn, types: &Types) {
for name in out.namespace.clone() {
write!(out, "{}$", name);
}
write!(out, "cxxbridge00${}(", efn.ident);
write!(out, "cxxbridge01${}(", efn.ident);
for (i, arg) in efn.args.iter().enumerate() {
if i > 0 {
write!(out, ", ");
Expand Down Expand Up @@ -244,7 +244,7 @@ fn write_rust_function_decl(out: &mut OutFile, efn: &ExternFn, types: &Types) {
for name in out.namespace.clone() {
write!(out, "{}$", name);
}
write!(out, "cxxbridge00${}(", efn.ident);
write!(out, "cxxbridge01${}(", efn.ident);
for (i, arg) in efn.args.iter().enumerate() {
if i > 0 {
write!(out, ", ");
Expand Down Expand Up @@ -299,7 +299,7 @@ fn write_rust_function_shim(out: &mut OutFile, efn: &ExternFn, types: &Types) {
for name in out.namespace.clone() {
write!(out, "{}$", name);
}
write!(out, "cxxbridge00${}(", efn.ident);
write!(out, "cxxbridge01${}(", efn.ident);
for (i, arg) in efn.args.iter().enumerate() {
if i > 0 {
write!(out, ", ");
Expand Down Expand Up @@ -435,7 +435,7 @@ fn write_generic_instantiations(out: &mut OutFile, types: &Types) {
}
out.end_block();

out.begin_block("namespace cxxbridge00");
out.begin_block("namespace cxxbridge01");
for ty in types {
if let Type::RustBox(ty) = ty {
if let Type::Ident(inner) = &ty.inner {
Expand All @@ -455,34 +455,34 @@ fn write_rust_box_extern(out: &mut OutFile, ident: &Ident) {
inner += &ident.to_string();
let instance = inner.replace("::", "$");

writeln!(out, "#ifndef CXXBRIDGE00_RUST_BOX_{}", instance);
writeln!(out, "#define CXXBRIDGE00_RUST_BOX_{}", instance);
writeln!(out, "#ifndef CXXBRIDGE01_RUST_BOX_{}", instance);
writeln!(out, "#define CXXBRIDGE01_RUST_BOX_{}", instance);
writeln!(
out,
"void cxxbridge00$rust_box${}$uninit(cxxbridge::RustBox<{}> *ptr) noexcept;",
"void cxxbridge01$rust_box${}$uninit(cxxbridge::RustBox<{}> *ptr) noexcept;",
instance, inner,
);
writeln!(
out,
"void cxxbridge00$rust_box${}$set_raw(cxxbridge::RustBox<{}> *ptr, {} *raw) noexcept;",
"void cxxbridge01$rust_box${}$set_raw(cxxbridge::RustBox<{}> *ptr, {} *raw) noexcept;",
instance, inner, inner
);
writeln!(
out,
"void cxxbridge00$rust_box${}$drop(cxxbridge::RustBox<{}> *ptr) noexcept;",
"void cxxbridge01$rust_box${}$drop(cxxbridge::RustBox<{}> *ptr) noexcept;",
instance, inner,
);
writeln!(
out,
"const {} *cxxbridge00$rust_box${}$deref(const cxxbridge::RustBox<{}> *ptr) noexcept;",
"const {} *cxxbridge01$rust_box${}$deref(const cxxbridge::RustBox<{}> *ptr) noexcept;",
inner, instance, inner,
);
writeln!(
out,
"{} *cxxbridge00$rust_box${}$deref_mut(cxxbridge::RustBox<{}> *ptr) noexcept;",
"{} *cxxbridge01$rust_box${}$deref_mut(cxxbridge::RustBox<{}> *ptr) noexcept;",
inner, instance, inner,
);
writeln!(out, "#endif // CXXBRIDGE00_RUST_BOX_{}", instance);
writeln!(out, "#endif // CXXBRIDGE01_RUST_BOX_{}", instance);
}

fn write_rust_box_impl(out: &mut OutFile, ident: &Ident) {
Expand All @@ -498,7 +498,7 @@ fn write_rust_box_impl(out: &mut OutFile, ident: &Ident) {
writeln!(out, "void RustBox<{}>::uninit() noexcept {{", inner);
writeln!(
out,
" return cxxbridge00$rust_box${}$uninit(this);",
" return cxxbridge01$rust_box${}$uninit(this);",
instance
);
writeln!(out, "}}");
Expand All @@ -511,7 +511,7 @@ fn write_rust_box_impl(out: &mut OutFile, ident: &Ident) {
);
writeln!(
out,
" return cxxbridge00$rust_box${}$set_raw(this, raw);",
" return cxxbridge01$rust_box${}$set_raw(this, raw);",
instance
);
writeln!(out, "}}");
Expand All @@ -520,7 +520,7 @@ fn write_rust_box_impl(out: &mut OutFile, ident: &Ident) {
writeln!(out, "void RustBox<{}>::drop() noexcept {{", inner);
writeln!(
out,
" return cxxbridge00$rust_box${}$drop(this);",
" return cxxbridge01$rust_box${}$drop(this);",
instance
);
writeln!(out, "}}");
Expand All @@ -533,7 +533,7 @@ fn write_rust_box_impl(out: &mut OutFile, ident: &Ident) {
);
writeln!(
out,
" return cxxbridge00$rust_box${}$deref(this);",
" return cxxbridge01$rust_box${}$deref(this);",
instance
);
writeln!(out, "}}");
Expand All @@ -546,7 +546,7 @@ fn write_rust_box_impl(out: &mut OutFile, ident: &Ident) {
);
writeln!(
out,
" return cxxbridge00$rust_box${}$deref_mut(this);",
" return cxxbridge01$rust_box${}$deref_mut(this);",
instance
);
writeln!(out, "}}");
Expand All @@ -561,8 +561,8 @@ fn write_unique_ptr(out: &mut OutFile, ident: &Ident) {
inner += &ident.to_string();
let instance = inner.replace("::", "$");

writeln!(out, "#ifndef CXXBRIDGE00_UNIQUE_PTR_{}", instance);
writeln!(out, "#define CXXBRIDGE00_UNIQUE_PTR_{}", instance);
writeln!(out, "#ifndef CXXBRIDGE01_UNIQUE_PTR_{}", instance);
writeln!(out, "#define CXXBRIDGE01_UNIQUE_PTR_{}", instance);
writeln!(
out,
"static_assert(sizeof(std::unique_ptr<{}>) == sizeof(void *), \"\");",
Expand All @@ -575,14 +575,14 @@ fn write_unique_ptr(out: &mut OutFile, ident: &Ident) {
);
writeln!(
out,
"void cxxbridge00$unique_ptr${}$null(std::unique_ptr<{}> *ptr) noexcept {{",
"void cxxbridge01$unique_ptr${}$null(std::unique_ptr<{}> *ptr) noexcept {{",
instance, inner,
);
writeln!(out, " new (ptr) std::unique_ptr<{}>();", inner);
writeln!(out, "}}");
writeln!(
out,
"void cxxbridge00$unique_ptr${}$new(std::unique_ptr<{}> *ptr, {} *value) noexcept {{",
"void cxxbridge01$unique_ptr${}$new(std::unique_ptr<{}> *ptr, {} *value) noexcept {{",
instance, inner, inner,
);
writeln!(
Expand All @@ -593,31 +593,31 @@ fn write_unique_ptr(out: &mut OutFile, ident: &Ident) {
writeln!(out, "}}");
writeln!(
out,
"void cxxbridge00$unique_ptr${}$raw(std::unique_ptr<{}> *ptr, {} *raw) noexcept {{",
"void cxxbridge01$unique_ptr${}$raw(std::unique_ptr<{}> *ptr, {} *raw) noexcept {{",
instance, inner, inner,
);
writeln!(out, " new (ptr) std::unique_ptr<{}>(raw);", inner);
writeln!(out, "}}");
writeln!(
out,
"const {} *cxxbridge00$unique_ptr${}$get(const std::unique_ptr<{}>& ptr) noexcept {{",
"const {} *cxxbridge01$unique_ptr${}$get(const std::unique_ptr<{}>& ptr) noexcept {{",
inner, instance, inner,
);
writeln!(out, " return ptr.get();");
writeln!(out, "}}");
writeln!(
out,
"{} *cxxbridge00$unique_ptr${}$release(std::unique_ptr<{}>& ptr) noexcept {{",
"{} *cxxbridge01$unique_ptr${}$release(std::unique_ptr<{}>& ptr) noexcept {{",
inner, instance, inner,
);
writeln!(out, " return ptr.release();");
writeln!(out, "}}");
writeln!(
out,
"void cxxbridge00$unique_ptr${}$drop(std::unique_ptr<{}> *ptr) noexcept {{",
"void cxxbridge01$unique_ptr${}$drop(std::unique_ptr<{}> *ptr) noexcept {{",
instance, inner,
);
writeln!(out, " ptr->~unique_ptr();");
writeln!(out, "}}");
writeln!(out, "#endif // CXXBRIDGE00_UNIQUE_PTR_{}", instance);
writeln!(out, "#endif // CXXBRIDGE01_UNIQUE_PTR_{}", instance);
}
12 changes: 6 additions & 6 deletions include/cxxbridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <iostream>
#include <string>

namespace cxxbridge00 {
namespace cxxbridge01 {

class RustString final {
public:
Expand Down Expand Up @@ -58,8 +58,8 @@ class RustStr final {
Repr repr;
};

#ifndef CXXBRIDGE00_RUST_BOX
#define CXXBRIDGE00_RUST_BOX
#ifndef CXXBRIDGE01_RUST_BOX
#define CXXBRIDGE01_RUST_BOX
template <typename T> class RustBox final {
public:
RustBox(const RustBox &other) : RustBox(*other) {}
Expand Down Expand Up @@ -122,11 +122,11 @@ template <typename T> class RustBox final {
T *deref_mut() noexcept;
uintptr_t repr;
};
#endif // CXXBRIDGE00_RUST_BOX
#endif // CXXBRIDGE01_RUST_BOX

std::ostream &operator<<(std::ostream &os, const RustString &s);
std::ostream &operator<<(std::ostream &os, const RustStr &s);

} // namespace cxxbridge00
} // namespace cxxbridge01

namespace cxxbridge = cxxbridge00;
namespace cxxbridge = cxxbridge01;
4 changes: 2 additions & 2 deletions macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cxxbridge-macro"
version = "0.0.0"
version = "0.1.0"
authors = ["David Tolnay <[email protected]>"]
edition = "2018"
license = "MIT OR Apache-2.0"
Expand All @@ -19,4 +19,4 @@ quote = "1.0"
syn = { version = "1.0", features = ["full"] }

[dev-dependencies]
cxx = { version = "0.0", path = ".." }
cxx = { version = "0.1", path = ".." }
8 changes: 4 additions & 4 deletions macro/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ fn expand_cxx_function_decl(namespace: &Namespace, efn: &ExternFn, types: &Types
let ret = expand_extern_type(efn.ret.as_ref().unwrap());
outparam = Some(quote!(__return: *mut #ret));
}
let link_name = format!("{}cxxbridge00${}", namespace, ident);
let link_name = format!("{}cxxbridge01${}", namespace, ident);
let local_name = format_ident!("__{}", ident);
quote! {
#[link_name = #link_name]
Expand Down Expand Up @@ -266,7 +266,7 @@ fn expand_rust_function_shim(namespace: &Namespace, efn: &ExternFn, types: &Type
expr = quote!(::std::ptr::write(__return, #expr));
}
let ret = expand_extern_return_type(&efn.ret, types);
let link_name = format!("{}cxxbridge00${}", namespace, ident);
let link_name = format!("{}cxxbridge01${}", namespace, ident);
let local_name = format_ident!("__{}", ident);
let catch_unwind_label = format!("::{}", ident);
quote! {
Expand All @@ -280,7 +280,7 @@ fn expand_rust_function_shim(namespace: &Namespace, efn: &ExternFn, types: &Type
}

fn expand_rust_box(namespace: &Namespace, ident: &Ident) -> TokenStream {
let link_prefix = format!("cxxbridge00$rust_box${}{}$", namespace, ident);
let link_prefix = format!("cxxbridge01$rust_box${}{}$", namespace, ident);
let link_uninit = format!("{}uninit", link_prefix);
let link_set_raw = format!("{}set_raw", link_prefix);
let link_drop = format!("{}drop", link_prefix);
Expand Down Expand Up @@ -337,7 +337,7 @@ fn expand_rust_box(namespace: &Namespace, ident: &Ident) -> TokenStream {
}

fn expand_unique_ptr(namespace: &Namespace, ident: &Ident) -> TokenStream {
let prefix = format!("cxxbridge00$unique_ptr${}{}$", namespace, ident);
let prefix = format!("cxxbridge01$unique_ptr${}{}$", namespace, ident);
let link_null = format!("{}null", prefix);
let link_new = format!("{}new", prefix);
let link_raw = format!("{}raw", prefix);
Expand Down
4 changes: 2 additions & 2 deletions src/cxx_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use std::slice;
use std::str::{self, Utf8Error};

extern "C" {
#[link_name = "cxxbridge00$cxx_string$data"]
#[link_name = "cxxbridge01$cxx_string$data"]
fn string_data(_: &CxxString) -> *const u8;
#[link_name = "cxxbridge00$cxx_string$length"]
#[link_name = "cxxbridge01$cxx_string$length"]
fn string_length(_: &CxxString) -> usize;
}

Expand Down
Loading

0 comments on commit e43b737

Please sign in to comment.