Compare commits

..

7 Commits

Author SHA1 Message Date
1c28c636b7 quote arguments
when it comes to quotes, cmake is quite like bash...
2026-10-27 19:15:39 +03:00
6185fbb449 share the Cargo target directory 2026-10-26 18:16:01 +03:00
41e747d9c2 add sample rendering (#2) 2026-10-25 12:48:40 +03:00
906aecf30d remove the KDE dependency 2026-10-25 12:45:09 +03:00
344a604877 switch to right-handed CS 2026-10-25 12:45:09 +03:00
9f5e52277a fix cmake 2026-10-25 12:32:24 +03:00
d0998119c8 add clang-format 2026-10-25 12:32:21 +03:00
8 changed files with 45 additions and 78 deletions

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 4.2) cmake_minimum_required(VERSION 3.18...4.2)
project(PROJECT-NAME VERSION 1.0.0 LANGUAGES CXX) project(PROJECT-NAME VERSION 1.0.0 LANGUAGES CXX)
@ -7,9 +7,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt6 REQUIRED COMPONENTS Gui Widgets) find_package(Qt6 REQUIRED COMPONENTS Gui Widgets)
find_program(CARGO cargo REQUIRED) find_program(CARGO cargo REQUIRED)
set(CARGO_TARGET_DIR "${CMAKE_BINARY_DIR}/cargo") set(CARGO_TARGET_DIR "${CMAKE_SOURCE_DIR}/target" CACHE PATH "Path to the Cargo target directory")
include(cbindgen.cmake)
qt_standard_project_setup() qt_standard_project_setup()

View File

@ -1,13 +0,0 @@
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()

View File

@ -50,10 +50,10 @@ mod tests {
fn test_view() { fn test_view() {
let mut ok = true; let mut ok = true;
for (yaw, pitch, x1, y1, z1) in [ for (yaw, pitch, x1, y1, z1) in [
(0.0, 0.0, [0., 0., 2.], [-1., 0., 3.], [0., 1., 3.]), (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.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.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.5, 0.5, [-1., 0., -3.], [0., -1., -3.], [0., 0., -2.]),
] { ] {
let m = view(yaw * PI, pitch * PI, 3.); let m = view(yaw * PI, pitch * PI, 3.);
for (label, world, expected) in for (label, world, expected) in

View File

@ -1,14 +0,0 @@
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"]

View File

@ -1,45 +1,33 @@
# build the Rust side as a static library # build the Rust side as a static library
set(impl_basename "${CARGO_TARGET_DIR}/release/libPROJECT_NAME_impl") 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( add_custom_command(
OUTPUT ${impl_basename}.a OUTPUT "${impl_basename}.a"
COMMAND env CARGO_TARGET_DIR=${CARGO_TARGET_DIR} ${CARGO} build --release --package PROJECT-NAME-impl COMMAND env "CARGO_TARGET_DIR=${CARGO_TARGET_DIR}" ${CARGO} build --release --package PROJECT-NAME-impl
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
DEPFILE ${impl_basename}.d DEPFILE "${impl_basename}.d"
USES_TERMINAL USES_TERMINAL
JOB_SERVER_AWARE TRUE
VERBATIM VERBATIM
DEPENDS_EXPLICIT_ONLY ${cargo_cmake_args}
) )
# HACK ensure CMake *actually adds* the command above # HACK ensure CMake *actually adds* the command above
add_custom_target(build_impl add_custom_target(build_impl
DEPENDS ${impl_basename}.a DEPENDS "${impl_basename}.a"
) )
add_library(PROJECT_NAME_impl STATIC IMPORTED) add_library(PROJECT_NAME_impl STATIC IMPORTED)
set_target_properties(PROJECT_NAME_impl PROPERTIES 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"
) )

View File

@ -3,6 +3,13 @@
#include <stdexcept> #include <stdexcept>
#include <utility> #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) BoxCore::BoxCore(BoxCore&& b)
: ptr(std::exchange(b.ptr, {})) { : ptr(std::exchange(b.ptr, {})) {
} }

View File

@ -2,10 +2,23 @@
#include <cstdint> #include <cstdint>
#include "bindings.hxx"
struct xcb_connection_t; 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; using ffi::RedrawArgs;
class MutCore { class MutCore {

View File

@ -1,12 +0,0 @@
#pragma once
struct alignas(16) Vec4 {
float x, y, z, w;
};
namespace ffi {
template <typename T>
using Box = T*;
} // namespace ffi