diff --git a/Cargo.toml b/Cargo.toml index ea837cf51..8a88f4eba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ members = [ 'api/sixtyfps-rs', 'api/sixtyfps-rs/sixtyfps-macros', 'api/sixtyfps-rs/sixtyfps-build', + 'api/sixtyfps-cpp', 'api/sixtyfps-node/native', 'api/sixtyfps-wasm-interpreter', 'tools/compiler', @@ -45,6 +46,7 @@ default-members = [ 'sixtyfps_compiler', 'api/sixtyfps-rs', 'api/sixtyfps-rs/sixtyfps-build', + 'api/sixtyfps-cpp', 'api/sixtyfps-node/native', 'tools/compiler', 'tools/viewer', diff --git a/api/sixtyfps-cpp/CMakeLists.txt b/api/sixtyfps-cpp/CMakeLists.txt index d2b369dc0..0eac035c3 100644 --- a/api/sixtyfps-cpp/CMakeLists.txt +++ b/api/sixtyfps-cpp/CMakeLists.txt @@ -18,11 +18,11 @@ FetchContent_Declare( ) FetchContent_MakeAvailable(Corrosion) corrosion_import_crate(MANIFEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../Cargo.toml" - CRATES sixtyfps-compiler sixtyfps-rendering-backend-default xtask) + CRATES sixtyfps-compiler sixtyfps-cpp xtask) add_library(SixtyFPS INTERFACE) add_library(SixtyFPS::SixtyFPS ALIAS SixtyFPS) -target_link_libraries(SixtyFPS INTERFACE sixtyfps-rendering-backend-default) +target_link_libraries(SixtyFPS INTERFACE sixtyfps-cpp) target_compile_features(SixtyFPS INTERFACE cxx_std_17) file(GLOB api_headers RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/include/" @@ -69,18 +69,18 @@ target_include_directories(SixtyFPS INTERFACE add_executable(SixtyFPS::sixtyfps_compiler ALIAS sixtyfps_compiler) include(${CMAKE_CURRENT_LIST_DIR}/cmake/SixtyFPSMacro.cmake) -export(TARGETS SixtyFPS sixtyfps-rendering-backend-default +export(TARGETS SixtyFPS sixtyfps-cpp NAMESPACE SixtyFPS:: FILE "${CMAKE_BINARY_DIR}/lib/cmake/SixtyFPS/SixtyFPSTargets.cmake") install(EXPORT SixtyFPSTargets NAMESPACE SixtyFPS:: DESTINATION lib/cmake/SixtyFPS) -install(TARGETS SixtyFPS sixtyfps-rendering-backend-default +install(TARGETS SixtyFPS sixtyfps-cpp EXPORT SixtyFPSTargets LIBRARY DESTINATION lib PUBLIC_HEADER DESTINATION include/sixtyfps) include(CMakePackageConfigHelpers) include(GNUInstallDirs) -install(FILES $ TYPE LIB) +install(FILES $ TYPE LIB) if(WIN32) - install(FILES $ TYPE LIB) + install(FILES $ TYPE LIB) endif() install(PROGRAMS $ TYPE BIN) @@ -89,7 +89,7 @@ set(SIXTYFPS_LIB_PROPERTIES "") foreach(prop IMPORTED_LOCATION IMPORTED_LOCATION_DEBUG IMPORTED_LOCATION_RELEASE IMPORTED_IMPLIB IMPORTED_IMPLIB_DEBUG IMPORTED_IMPLIB_RELEASE) - get_target_property(value sixtyfps-rendering-backend-default-shared ${prop}) + get_target_property(value sixtyfps-cpp-shared ${prop}) if(value) get_filename_component(value ${value} NAME) list(APPEND SIXTYFPS_LIB_PROPERTIES ${prop} "\${_IMPORT_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${value}") diff --git a/api/sixtyfps-cpp/Cargo.toml b/api/sixtyfps-cpp/Cargo.toml new file mode 100644 index 000000000..df8ca8297 --- /dev/null +++ b/api/sixtyfps-cpp/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "sixtyfps-cpp" +version = "0.0.5" +authors = ["SixtyFPS "] +edition = "2018" +license = "GPL-3.0-only" +description = "SixtyFPS C++ integration" +repository = "https://github.com/sixtyfpsui/sixtyfps" +homepage = "https://sixtyfps.io" +publish = false + +[lib] +path = "lib.rs" +crate-type = ["cdylib"] + +[dependencies] +sixtyfps-rendering-backend-default = { version = "=0.0.5", path="../../sixtyfps_runtime/rendering_backends/default" } +sixtyfps-corelib = { version = "=0.0.5", path="../../sixtyfps_runtime/corelib" } + diff --git a/api/sixtyfps-cpp/cmake/SixtyFPSConfig.cmake.in b/api/sixtyfps-cpp/cmake/SixtyFPSConfig.cmake.in index 4c61045b4..ce5a5a878 100644 --- a/api/sixtyfps-cpp/cmake/SixtyFPSConfig.cmake.in +++ b/api/sixtyfps-cpp/cmake/SixtyFPSConfig.cmake.in @@ -17,8 +17,8 @@ if(_IMPORT_PREFIX STREQUAL "/") set(_IMPORT_PREFIX "") endif() -add_library(sixtyfps-rendering-backend-default-shared SHARED IMPORTED) -set_target_properties(sixtyfps-rendering-backend-default-shared PROPERTIES @SIXTYFPS_LIB_PROPERTIES@) +add_library(sixtyfps-cpp-shared SHARED IMPORTED) +set_target_properties(sixtyfps-cpp-shared PROPERTIES @SIXTYFPS_LIB_PROPERTIES@) add_executable(SixtyFPS::sixtyfps_compiler IMPORTED GLOBAL) set_target_properties(SixtyFPS::sixtyfps_compiler PROPERTIES IMPORTED_LOCATION "${_IMPORT_PREFIX}/@CMAKE_INSTALL_BINDIR@/sixtyfps_compiler${CMAKE_EXECUTABLE_SUFFIX}") diff --git a/api/sixtyfps-cpp/include/sixtyfps.h b/api/sixtyfps-cpp/include/sixtyfps.h index 7ef9e0f54..36e7e2dc0 100644 --- a/api/sixtyfps-cpp/include/sixtyfps.h +++ b/api/sixtyfps-cpp/include/sixtyfps.h @@ -27,7 +27,7 @@ struct ComponentVTable; struct ItemVTable; } #include "sixtyfps_internal.h" -#include "sixtyfps_default_backend_internal.h" +#include "sixtyfps_backend_internal.h" #include "sixtyfps_qt_internal.h" namespace sixtyfps { diff --git a/api/sixtyfps-cpp/lib.rs b/api/sixtyfps-cpp/lib.rs new file mode 100644 index 000000000..01425caf8 --- /dev/null +++ b/api/sixtyfps-cpp/lib.rs @@ -0,0 +1,50 @@ +/* LICENSE BEGIN + This file is part of the SixtyFPS Project -- https://sixtyfps.io + Copyright (c) 2020 Olivier Goffart + Copyright (c) 2020 Simon Hausmann + + SPDX-License-Identifier: GPL-3.0-only + This file is also available under commercial licensing terms. + Please contact info@sixtyfps.io for more information. +LICENSE END */ +/*! This scrates just expose the function used by the C++ integration */ + +#[doc(hidden)] +#[cold] +pub fn use_modules() { + sixtyfps_rendering_backend_default::use_modules(); +} + +use sixtyfps_rendering_backend_default::backend; + +#[cfg(not(target_arch = "wasm32"))] +use sixtyfps_corelib::window::ffi::ComponentWindowOpaque; +use sixtyfps_corelib::window::ComponentWindow; + +#[no_mangle] +pub unsafe extern "C" fn sixtyfps_component_window_init(out: *mut ComponentWindowOpaque) { + assert_eq!( + core::mem::size_of::(), + core::mem::size_of::() + ); + core::ptr::write(out as *mut ComponentWindow, crate::backend().create_window()); +} + +#[no_mangle] +pub unsafe extern "C" fn sixtyfps_run_event_loop() { + crate::backend().run_event_loop(); +} + +#[no_mangle] +pub unsafe extern "C" fn sixtyfps_register_font_from_path( + path: &sixtyfps_corelib::SharedString, + error_str: *mut sixtyfps_corelib::SharedString, +) { + core::ptr::write( + error_str, + match crate::backend().register_font_from_path(std::path::Path::new(path.as_str())) { + Ok(()) => Default::default(), + Err(err) => err.to_string().into(), + }, + ) +} diff --git a/sixtyfps_runtime/rendering_backends/default/Cargo.toml b/sixtyfps_runtime/rendering_backends/default/Cargo.toml index 6e226876d..c150afa67 100644 --- a/sixtyfps_runtime/rendering_backends/default/Cargo.toml +++ b/sixtyfps_runtime/rendering_backends/default/Cargo.toml @@ -10,7 +10,6 @@ homepage = "https://sixtyfps.io" [lib] path = "lib.rs" -crate-type = [ "lib", "cdylib" ] [features] x11 = ["sixtyfps-rendering-backend-gl/x11"] diff --git a/sixtyfps_runtime/rendering_backends/default/lib.rs b/sixtyfps_runtime/rendering_backends/default/lib.rs index 594d85698..49a488243 100644 --- a/sixtyfps_runtime/rendering_backends/default/lib.rs +++ b/sixtyfps_runtime/rendering_backends/default/lib.rs @@ -77,37 +77,3 @@ pub fn use_modules() { #[cfg(feature = "sixtyfps-rendering-backend-gl")] sixtyfps_rendering_backend_gl::use_modules(); } - -#[cfg(not(target_arch = "wasm32"))] -pub mod ffi { - use sixtyfps_corelib::window::ffi::ComponentWindowOpaque; - use sixtyfps_corelib::window::ComponentWindow; - - #[no_mangle] - pub unsafe extern "C" fn sixtyfps_component_window_init(out: *mut ComponentWindowOpaque) { - assert_eq!( - core::mem::size_of::(), - core::mem::size_of::() - ); - core::ptr::write(out as *mut ComponentWindow, crate::backend().create_window()); - } - - #[no_mangle] - pub unsafe extern "C" fn sixtyfps_run_event_loop() { - crate::backend().run_event_loop(); - } - - #[no_mangle] - pub unsafe extern "C" fn sixtyfps_register_font_from_path( - path: &sixtyfps_corelib::SharedString, - error_str: *mut sixtyfps_corelib::SharedString, - ) { - core::ptr::write( - error_str, - match crate::backend().register_font_from_path(std::path::Path::new(path.as_str())) { - Ok(()) => Default::default(), - Err(err) => err.to_string().into(), - }, - ) - } -} diff --git a/tests/driver/cpp/cppdriver.rs b/tests/driver/cpp/cppdriver.rs index 2455bd61b..ebd97789c 100644 --- a/tests/driver/cpp/cppdriver.rs +++ b/tests/driver/cpp/cppdriver.rs @@ -97,13 +97,11 @@ pub fn test(testcase: &test_driver_lib::TestCase) -> Result<(), Box> compiler_command.arg("-g"); compiler_command.arg("-Werror").arg("-Wall").arg("-Wextra"); compiler_command.arg(concat!("-L", env!("CPP_LIB_PATH"))); - compiler_command.arg("-lsixtyfps_rendering_backend_default"); + compiler_command.arg("-lsixtyfps_cpp"); compiler_command.arg("-o").arg(&*binary_path); } else if compiler.is_like_msvc() { compiler_command.arg("/std:c++17"); - compiler_command - .arg("/link") - .arg(concat!(env!("CPP_LIB_PATH"), "\\sixtyfps_rendering_backend_default.dll.lib")); + compiler_command.arg("/link").arg(concat!(env!("CPP_LIB_PATH"), "\\sixtyfps_cpp.dll.lib")); let mut out_arg = std::ffi::OsString::from("/OUT:"); out_arg.push(&*binary_path); compiler_command.arg(out_arg); diff --git a/xtask/src/cbindgen.rs b/xtask/src/cbindgen.rs index e3770c1e2..b85360b30 100644 --- a/xtask/src/cbindgen.rs +++ b/xtask/src/cbindgen.rs @@ -304,17 +304,17 @@ fn gen_backend_qt(root_dir: &Path, include_dir: &Path) -> anyhow::Result<()> { Ok(()) } -fn gen_backend_default(root_dir: &Path, include_dir: &Path) -> anyhow::Result<()> { +fn gen_backend(root_dir: &Path, include_dir: &Path) -> anyhow::Result<()> { let config = default_config(); let mut crate_dir = root_dir.to_owned(); - crate_dir.extend(["sixtyfps_runtime", "rendering_backends", "default"].iter()); + crate_dir.extend(["api", "sixtyfps-cpp"].iter()); cbindgen::Builder::new() .with_config(config) .with_crate(crate_dir) .with_header("#include ") .generate() - .context("Unable to generate bindings for sixtyfps_default_backend_internal.h")? - .write_to_file(include_dir.join("sixtyfps_default_backend_internal.h")); + .context("Unable to generate bindings for sixtyfps_backend_internal.h")? + .write_to_file(include_dir.join("sixtyfps_backend_internal.h")); Ok(()) } @@ -326,6 +326,6 @@ pub fn gen_all(root_dir: &Path, include_dir: &Path) -> anyhow::Result<()> { std::fs::create_dir_all(include_dir).context("Could not create the include directory")?; gen_corelib(root_dir, include_dir)?; gen_backend_qt(root_dir, include_dir)?; - gen_backend_default(root_dir, include_dir)?; + gen_backend(root_dir, include_dir)?; Ok(()) }