Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .github/workflows/cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
# Ubuntu-20.04 is being used here on purpose instead of ubuntu-latest due to a bug with clang and libstdc++
# https://github.com/actions/runner-images/issues/8659
os: [ubuntu-20.04, windows-latest, macos-13]
os: [ubuntu-22.04, windows-latest, macos-13]
build_type: [Release]
cpp_compiler: [g++, clang++, cl]
exclude:
- os: windows-latest
cpp_compiler: clang++
- os: windows-latest
cpp_compiler: g++
- os: ubuntu-20.04
- os: ubuntu-22.04
cpp_compiler: cl
- os: macos-13
cpp_compiler: cl
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#### v0.7.1+v0.28.3

----
- Core: Generate used code only in the scaffolding header

#### v0.7.0+v0.28.3

----
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ as a separate project from `uniffi-rs`, as per

# How to install

Minimum Rust version required to install `uniffi-bindgen-cpp` is `1.72`.
Minimum Rust version required to install `uniffi-bindgen-cpp` is `1.74`.
Newer Rust versions should also work fine.

```bash
cargo install uniffi-bindgen-cpp --git https://github.com/NordSecurity/uniffi-bindgen-cpp --tag v0.7.0+v0.28.3
cargo install uniffi-bindgen-cpp --git https://github.com/NordSecurity/uniffi-bindgen-cpp --tag v0.7.1+v0.28.3
```

# How to generate bindings
Expand Down
2 changes: 1 addition & 1 deletion bindgen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "uniffi-bindgen-cpp"
version = "0.7.0+v.0.28.3"
version = "0.7.1+v.0.28.3"
edition = "2021"

[dependencies]
Expand Down
19 changes: 19 additions & 0 deletions bindgen/src/bindings/cpp/gen_cpp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,25 @@ impl<'a> ScaffoldingHeader<'a> {
fn new(ci: &'a ComponentInterface) -> Self {
Self { ci }
}

pub fn scaffolding_definitions(&self) -> impl Iterator<Item = FfiDefinition> + '_ {
self.ci
.callback_interface_definitions()
.into_iter()
.map(|cb| cb.vtable_definition())
.chain(
self.ci
.object_definitions()
.iter()
.flat_map(|o| o.vtable_definition()),
)
.map(Into::into)
.chain(
self.ci
.iter_ffi_function_definitions_non_async()
.map(Into::into),
)
}
}

#[derive(Template)]
Expand Down
4 changes: 2 additions & 2 deletions bindgen/src/bindings/cpp/templates/scaffolding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct RustCallStatus {

#endif

{%- for def in ci.ffi_definitions() %}
{%- for def in self.scaffolding_definitions() %}
{%- match def %}
{%- when FfiDefinition::CallbackFunction(callback) %}
{% call macros::ffi_return_type(callback) %} {{ callback.name()}}(
Expand All @@ -41,7 +41,7 @@ struct {{ ffi_struct.name()|ffi_struct_name }} {
{%- endfor %}
};
{%- when FfiDefinition::Function(func) %}
{%- match func.return_type() -%}
{% match func.return_type() -%}
{% when Some with (return_type) %}{{ return_type|ffi_type_name }} {% when None %}void {% endmatch %}{{ func.name() }}(
{%- for arg in func.arguments() %}
{{- arg.type_().borrow()|ffi_type_name }} {{ arg.name() }}{% if !loop.last || func.has_rust_call_status_arg() %}, {% endif -%}
Expand Down
59 changes: 12 additions & 47 deletions cpp-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.10)
project(binding-tests VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down Expand Up @@ -54,24 +54,6 @@ list(APPEND BINDING_FILES ${BINDINGS_SRC_DIR}/${TEST_NAME}.cpp)

endmacro(test_case)

# Add a scaffolding test case
macro(scaffolding_test_case TEST_NAME)

add_executable(${TEST_NAME}-scaffolding-test tests/${TEST_NAME}/main.cpp ${BINDINGS_SRC_DIR}/${TEST_NAME}.cpp)
target_include_directories(${TEST_NAME}-scaffolding-test PRIVATE ${BINDINGS_SRC_DIR} include)
target_link_libraries(${TEST_NAME}-scaffolding-test uniffi_fixtures Threads::Threads)

add_test(NAME ${TEST_NAME}-scaffolding-test COMMAND ${TEST_NAME}-scaffolding-test)
memcheck_test(${TEST_NAME}-scaffolding-test)

add_dependencies(${TEST_NAME}-scaffolding-test bindings scaffolding)

list(APPEND SCAFFOLDING_FILES ${BINDINGS_SRC_DIR}/${TEST_NAME}_cpp_scaffolding.cpp)
list(APPEND SCAFFOLDING_LIB_FILES scaffolding_tests/${TEST_NAME}/lib_${TEST_NAME}.cpp)
list(APPEND SCAFFOLDING_LIB_INCLUDE_DIRS scaffolding_tests/${TEST_NAME})

endmacro(scaffolding_test_case)

test_case(arithmetic)
test_case(callbacks)
test_case(fixture_callbacks)
Expand All @@ -90,26 +72,17 @@ test_case(enum_style_test)
test_case(empty_type)
test_case(error_types_builtin)

# scaffolding_test_case(arithmetic)
# scaffolding_test_case(callbacks)
# scaffolding_test_case(fixture_callbacks)
# scaffolding_test_case(chronological)
# scaffolding_test_case(custom_types)
# scaffolding_test_case(geometry)
# scaffolding_test_case(rondpoint)
# scaffolding_test_case(sprites)
# scaffolding_test_case(todolist)
# scaffolding_test_case(traits)
# scaffolding_test_case(coverall)
# scaffolding_test_case(custom_types_builtin)
# scaffolding_test_case(enum_style_test)
# scaffolding_test_case(empty_type)

# add_library(uniffi_fixtures SHARED
# ${SCAFFOLDING_LIB_FILES})
# target_include_directories(uniffi_fixtures PRIVATE
# ${SCAFFOLDING_LIB_INCLUDE_DIRS} ${BINDINGS_SRC_DIR})
# add_dependencies(uniffi_fixtures scaffolding)
# Special multilib test that only needs to compile to check for potential symbol clashes
add_executable(multilib-test
tests/multilib/main.cpp
${BINDINGS_SRC_DIR}/arithmetic.cpp
${BINDINGS_SRC_DIR}/coverall.cpp
${BINDINGS_SRC_DIR}/sprites.cpp
)
target_include_directories(multilib-test PRIVATE ${BINDINGS_SRC_DIR} include)
target_link_directories(multilib-test PRIVATE ${BINDINGS_BUILD_DIR})
target_link_libraries(multilib-test uniffi_bindgen_cpp_fixtures Threads::Threads ${ADDITIONAL_LIBS})
add_dependencies(multilib-test bindings)

add_custom_target(libs ALL
BYPRODUCTS ${BINDING_FILES}
Expand All @@ -124,11 +97,3 @@ add_custom_target(bindings ALL
WORKING_DIRECTORY ${BINDINGS_BUILD_DIR}
COMMENT "Generating bindings"
)

# add_custom_target(scaffolding ALL
# BYPRODUCTS ${SCAFFOLDING_FILES}
# DEPENDS libs
# COMMAND ./uniffi-bindgen-cpp --scaffolding --library ${UNIFFI_FIXTURES_LIB} --out-dir bindings
# WORKING_DIRECTORY ${BINDINGS_BUILD_DIR}
# COMMENT "Generating scaffolding"
# )
5 changes: 5 additions & 0 deletions cpp-tests/tests/multilib/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <arithmetic.hpp>
#include <coverall.hpp>
#include <sprites.hpp>

int main() { return 0; }