Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit most builtins if bridge explicitly includes "rust/cxx.h" #769

Merged
merged 3 commits into from
Mar 26, 2021

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented Mar 26, 2021

Closes #703. Builtins are not dumped into the generated output file if either the #[cxx::bridge] module contains include!("rust/cxx.h") or the cxxbridge CLI is invoked to pass it as an additional include via --include rust/cxx.h.

Before:

$ echo '#[cxx::bridge] mod ffi { struct Test { s: String } }' | cxxbridge /dev/stdin
#include <array>
#include <cstdint>
#include <string>
#include <type_traits>

namespace rust {
inline namespace cxxbridge1 {
// #include "rust/cxx.h"

#ifndef CXXBRIDGE1_RUST_STRING
#define CXXBRIDGE1_RUST_STRING
class String final {
  ...
  ...
  ...
};
#endif // CXXBRIDGE1_RUST_STRING
} // namespace cxxbridge1
} // namespace rust

struct Test;

#ifndef CXXBRIDGE1_STRUCT_Test
#define CXXBRIDGE1_STRUCT_Test
struct Test final {
  ::rust::String s;

  using IsRelocatable = ::std::true_type;
};
#endif // CXXBRIDGE1_STRUCT_Test

After (--include rust/cxx.h):

$ echo '#[cxx::bridge] mod ffi { struct Test { s: String } }' | cxxbridge /dev/stdin --include rust/cxx.h
#include "rust/cxx.h"

struct Test;

#ifndef CXXBRIDGE1_STRUCT_Test
#define CXXBRIDGE1_STRUCT_Test
struct Test final {
  ::rust::String s;

  using IsRelocatable = ::std::true_type;
};
#endif // CXXBRIDGE1_STRUCT_Test

After (include!("rust/cxx.h");):

$ echo '#[cxx::bridge] mod ffi { extern "C++" { include!("rust/cxx.h"); } struct Test { s: String } }' | cxxbridge /dev/stdin
#include "rust/cxx.h"

struct Test;

#ifndef CXXBRIDGE1_STRUCT_Test
#define CXXBRIDGE1_STRUCT_Test
struct Test final {
  ::rust::String s;

  using IsRelocatable = ::std::true_type;
};
#endif // CXXBRIDGE1_STRUCT_Test

@dtolnay dtolnay merged commit fbcd8fd into master Mar 26, 2021
@dtolnay dtolnay deleted the include branch March 26, 2021 04:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for #include "rust/cxx.h"
1 participant