Create a new crate to expose the C++

This commit is contained in:
Olivier Goffart 2021-03-16 16:33:09 +01:00
parent 705b76d2bd
commit 0e351de1a6
10 changed files with 88 additions and 54 deletions

View file

@ -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 $<TARGET_FILE:sixtyfps-rendering-backend-default-shared> TYPE LIB)
install(FILES $<TARGET_FILE:sixtyfps-cpp-shared> TYPE LIB)
if(WIN32)
install(FILES $<TARGET_LINKER_FILE:sixtyfps-rendering-backend-default-shared> TYPE LIB)
install(FILES $<TARGET_LINKER_FILE:sixtyfps-cpp-shared> TYPE LIB)
endif()
install(PROGRAMS $<TARGET_FILE:sixtyfps_compiler> 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}")

View file

@ -0,0 +1,19 @@
[package]
name = "sixtyfps-cpp"
version = "0.0.5"
authors = ["SixtyFPS <info@sixtyfps.io>"]
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" }

View file

@ -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}")

View file

@ -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 {

50
api/sixtyfps-cpp/lib.rs Normal file
View file

@ -0,0 +1,50 @@
/* LICENSE BEGIN
This file is part of the SixtyFPS Project -- https://sixtyfps.io
Copyright (c) 2020 Olivier Goffart <olivier.goffart@sixtyfps.io>
Copyright (c) 2020 Simon Hausmann <simon.hausmann@sixtyfps.io>
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::<ComponentWindow>(),
core::mem::size_of::<ComponentWindowOpaque>()
);
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(),
},
)
}