Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 068e2fb2e4 | |||
| 1e8c440825 | |||
| 6eb62cf693 | |||
| 7afb7b2f20 | |||
| 1d433dc13b |
|
|
@ -1,4 +1,4 @@
|
|||
cmake_minimum_required(VERSION 3.18...4.2)
|
||||
cmake_minimum_required(VERSION 4.2)
|
||||
|
||||
project(PROJECT-NAME VERSION 1.0.0 LANGUAGES CXX)
|
||||
|
||||
|
|
@ -7,7 +7,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Gui Widgets)
|
||||
find_program(CARGO cargo REQUIRED)
|
||||
set(CARGO_TARGET_DIR "${CMAKE_SOURCE_DIR}/target" CACHE PATH "Path to the Cargo target directory")
|
||||
set(CARGO_TARGET_DIR "${CMAKE_BINARY_DIR}/cargo")
|
||||
|
||||
include(cbindgen.cmake)
|
||||
|
||||
qt_standard_project_setup()
|
||||
|
||||
|
|
|
|||
13
cbindgen.cmake
Normal file
13
cbindgen.cmake
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
option(LOCAL_CBINDGEN "Download and build `cbindgen` even if one can be found on the system")
|
||||
|
||||
if(NOT LOCAL_CBINDGEN)
|
||||
find_program(CBINDGEN cbindgen)
|
||||
endif()
|
||||
|
||||
if(NOT CBINDGEN)
|
||||
message(CONFIGURE_LOG "cbindgen not found, downloading...")
|
||||
set(crates "${CMAKE_BINARY_DIR}/crates")
|
||||
file(MAKE_DIRECTORY ${crates})
|
||||
execute_process(COMMAND ${CARGO} install --root ${crates} cbindgen@0.29.4)
|
||||
set(CACHE{CBINDGEN} TYPE FILEPATH FORCE VALUE "${crates}/bin/cbindgen")
|
||||
endif()
|
||||
|
|
@ -50,10 +50,10 @@ mod tests {
|
|||
fn test_view() {
|
||||
let mut ok = true;
|
||||
for (yaw, pitch, x1, y1, z1) in [
|
||||
(0.0, 0.0, [0., 0., -4.], [-1., 0., -3.], [0., 1., -3.]),
|
||||
(0.5, 0.0, [-1., 0., -3.], [0., 0., -2.], [0., 1., -3.]),
|
||||
(0.0, 0.5, [0., 1., -3.], [-1., 0., -3.], [0., 0., -2.]),
|
||||
(0.5, 0.5, [-1., 0., -3.], [0., -1., -3.], [0., 0., -2.]),
|
||||
(0.0, 0.0, [0., 0., 2.], [-1., 0., 3.], [0., 1., 3.]),
|
||||
(0.5, 0.0, [1., 0., 3.], [0., 0., 2.], [0., 1., 3.]),
|
||||
(0.0, 0.5, [0., -1., 3.], [-1., 0., 3.], [0., 0., 2.]),
|
||||
(0.5, 0.5, [1., 0., 3.], [0., -1., 3.], [0., 0., 2.]),
|
||||
] {
|
||||
let m = view(yaw * PI, pitch * PI, 3.);
|
||||
for (label, world, expected) in
|
||||
|
|
|
|||
14
ui/cbindgen.toml
Normal file
14
ui/cbindgen.toml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
includes = ["types.hxx"]
|
||||
sys_includes = ["cstdint"]
|
||||
pragma_once = true
|
||||
no_includes = true
|
||||
namespace = "ffi"
|
||||
tab_width = 4
|
||||
language = "C++"
|
||||
|
||||
[parse]
|
||||
parse_deps = true
|
||||
include = ["PROJECT-NAME"]
|
||||
|
||||
[export]
|
||||
exclude = ["Box"]
|
||||
|
|
@ -1,33 +1,45 @@
|
|||
# build the Rust side as a static library
|
||||
set(impl_basename "${CARGO_TARGET_DIR}/release/libPROJECT_NAME_impl")
|
||||
|
||||
set(cargo_cmake_args)
|
||||
|
||||
if("${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.27")
|
||||
list(APPEND cargo_cmake_args DEPENDS_EXPLICIT_ONLY)
|
||||
endif()
|
||||
|
||||
if("${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.28")
|
||||
list(APPEND cargo_cmake_args JOB_SERVER_AWARE TRUE)
|
||||
endif()
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT "${impl_basename}.a"
|
||||
COMMAND env "CARGO_TARGET_DIR=${CARGO_TARGET_DIR}" ${CARGO} build --release --package PROJECT-NAME-impl
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
DEPFILE "${impl_basename}.d"
|
||||
OUTPUT ${impl_basename}.a
|
||||
COMMAND env CARGO_TARGET_DIR=${CARGO_TARGET_DIR} ${CARGO} build --release --package PROJECT-NAME-impl
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
DEPFILE ${impl_basename}.d
|
||||
USES_TERMINAL
|
||||
JOB_SERVER_AWARE TRUE
|
||||
VERBATIM
|
||||
${cargo_cmake_args}
|
||||
DEPENDS_EXPLICIT_ONLY
|
||||
)
|
||||
|
||||
# HACK ensure CMake *actually adds* the command above
|
||||
add_custom_target(build_impl
|
||||
DEPENDS "${impl_basename}.a"
|
||||
DEPENDS ${impl_basename}.a
|
||||
)
|
||||
|
||||
add_library(PROJECT_NAME_impl STATIC IMPORTED)
|
||||
|
||||
set_target_properties(PROJECT_NAME_impl PROPERTIES
|
||||
IMPORTED_LOCATION "${impl_basename}.a"
|
||||
IMPORTED_LOCATION ${impl_basename}.a
|
||||
)
|
||||
|
||||
# generate the bindings
|
||||
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include")
|
||||
set(bindings_basename "${CMAKE_CURRENT_BINARY_DIR}/include/bindings")
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${bindings_basename}.hxx
|
||||
COMMAND ${CBINDGEN} --only-target-dependencies --output "${bindings_basename}.hxx" --depfile "${bindings_basename}.d"
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
DEPFILE ${bindings_basename}.d
|
||||
VERBATIM
|
||||
CODEGEN
|
||||
DEPENDS_EXPLICIT_ONLY
|
||||
)
|
||||
|
||||
target_sources(PROJECT_NAME_impl INTERFACE
|
||||
${bindings_basename}.hxx
|
||||
)
|
||||
target_include_directories(PROJECT_NAME_impl INTERFACE
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/include"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -3,13 +3,6 @@
|
|||
#include <stdexcept>
|
||||
#include <utility>
|
||||
|
||||
namespace ffi {
|
||||
extern "C" Core* rt4_viewport_create(xcb_connection_t* connection, std::uint32_t window, std::uint32_t width, std::uint32_t height);
|
||||
extern "C" void rt4_viewport_destroy(Core* viewport);
|
||||
extern "C" void rt4_viewport_configure(Core* viewport, std::uint32_t width, std::uint32_t height);
|
||||
extern "C" void rt4_viewport_redraw(Core* viewport, const RedrawArgs* args);
|
||||
} // namespace ffi
|
||||
|
||||
BoxCore::BoxCore(BoxCore&& b)
|
||||
: ptr(std::exchange(b.ptr, {})) {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,23 +2,10 @@
|
|||
|
||||
#include <cstdint>
|
||||
|
||||
#include "bindings.hxx"
|
||||
|
||||
struct xcb_connection_t;
|
||||
|
||||
struct alignas(16) Vec4 {
|
||||
float x, y, z, w;
|
||||
};
|
||||
|
||||
namespace ffi {
|
||||
struct Core;
|
||||
|
||||
struct RedrawArgs {
|
||||
float cam_yaw;
|
||||
float cam_pitch;
|
||||
float cam_distance;
|
||||
float cam_fovy;
|
||||
};
|
||||
} // namespace ffi
|
||||
|
||||
using ffi::RedrawArgs;
|
||||
|
||||
class MutCore {
|
||||
|
|
|
|||
12
ui/src/types.hxx
Normal file
12
ui/src/types.hxx
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
struct alignas(16) Vec4 {
|
||||
float x, y, z, w;
|
||||
};
|
||||
|
||||
namespace ffi {
|
||||
|
||||
template <typename T>
|
||||
using Box = T*;
|
||||
|
||||
} // namespace ffi
|
||||
Loading…
Reference in New Issue
Block a user