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
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ jobs:
mkdir -p ${{github.workspace}}/install

- name: Configure CMake (Linux)
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DEXTERNAL_EIGEN:BOOL=OFF -DPYTHON_WRAPPER:BOOL=OFF -DFORTRAN_WRAPPER:BOOL=ON -DRUST_WRAPPER:BOOL=OFF -DUSE_VTK=ON -DBUILD_TESTING=ON
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DEXTERNAL_EIGEN:BOOL=OFF -DPYTHON_WRAPPER:BOOL=OFF -DFORTRAN_WRAPPER:BOOL=ON -DRUST_WRAPPER:BOOL=ON -DUSE_VTK=ON -DBUILD_TESTING=ON
if: runner.os == 'Linux'

- name: Configure CMake (MacOS)
Expand Down
27 changes: 27 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,30 @@ if(${MATLAB_WRAPPER})
UNITTEST_FILE ${CMAKE_CURRENT_BINARY_DIR}/matlab_bindings.m
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endif()

if(${RUST_WRAPPER})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Cargo.toml
${CMAKE_CURRENT_BINARY_DIR}/Cargo.toml
COPYONLY)
set(RUST_TESTS
rust_minimal
)
foreach(TEST ${RUST_TESTS})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${TEST}.rs
${CMAKE_CURRENT_BINARY_DIR}/${TEST}.rs
COPYONLY)
endforeach()

add_custom_target(
rust_make_tests ALL
${CMAKE_COMMAND} -E env RUSTFLAGS="-L${CMAKE_BINARY_DIR}/source/" cargo build --release
)
add_dependencies(rust_make_tests rust_wrapper)

foreach(TEST ${RUST_TESTS})
add_test(NAME ${TEST}
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/target/release/${TEST})
set_tests_properties(${TEST}
PROPERTIES ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/source/:$ENV{LD_LIBRARY_PATH}")
endforeach()
endif()
11 changes: 11 additions & 0 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "moordyn-tests"
version = "0.1.0"
edition = "2018"
[[bin]]
name = "rust_minimal"
test = true
bench = false
path = "rust_minimal.rs"
[dependencies]
moordyn-sys = { path = "../wrappers/rust/" }
40 changes: 40 additions & 0 deletions tests/rust_minimal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
extern crate moordyn;
use std::ffi::CString;
use std::os::raw::c_uint;

fn main() {
let mut err: i32;

let fpath = CString::new("Mooring/lines.txt").expect("CString::new failed");
unsafe {
let system = moordyn::MoorDyn_Create(fpath.as_ptr());

let mut n_dof: u32 = 0;
err = moordyn::MoorDyn_NCoupledDOF(system, &mut n_dof as *mut c_uint);
assert_eq!(err, moordyn::MOORDYN_SUCCESS as i32);
assert_eq!(n_dof, 9);

let mut x = vec![0.0; 9];
let mut dx = vec![0.0; 9];
for i in 1..=3 {
let point = moordyn::MoorDyn_GetPoint(system, i);
let mut pos = vec![0.0; 3];
err = moordyn::MoorDyn_GetPointPos(point, pos.as_mut_ptr());
assert_eq!(err, moordyn::MOORDYN_SUCCESS as i32);
let slc : usize = (i - 1) as usize;
x[slc..slc+3].clone_from_slice(&pos);
}

err = moordyn::MoorDyn_Init(system, x.as_ptr(), dx.as_ptr());
assert_eq!(err, moordyn::MOORDYN_SUCCESS as i32);

let mut f = Vec::<f64>::with_capacity(9);
let mut t: f64 = 0.0;
let mut dt: f64 = 0.5;
err = moordyn::MoorDyn_Step(system, x.as_ptr(), dx.as_ptr(), f.as_mut_ptr(), &mut t as *mut f64, &mut dt as *mut f64);
assert_eq!(err, moordyn::MOORDYN_SUCCESS as i32);

err = moordyn::MoorDyn_Close(system);
assert_eq!(err, moordyn::MOORDYN_SUCCESS as i32);
}
}
1 change: 1 addition & 0 deletions wrappers/rust/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ add_custom_target(
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/Cargo.toml" "${CMAKE_CURRENT_BINARY_DIR}/Cargo.toml"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/lib.rs" "${CMAKE_CURRENT_BINARY_DIR}/lib.rs"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/build.rs" "${CMAKE_CURRENT_BINARY_DIR}/build.rs"
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/target/release/deps
COMMAND ${CMAKE_COMMAND} -E create_symlink $<TARGET_LINKER_FILE:moordyn> ${CMAKE_CURRENT_BINARY_DIR}/target/release/deps/$<TARGET_LINKER_FILE_NAME:moordyn>
COMMAND bindgen ${CMAKE_SOURCE_DIR}/source/MoorDyn2.h -o ${CMAKE_CURRENT_BINARY_DIR}/bindings.rs
)
Expand Down
1 change: 1 addition & 0 deletions wrappers/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2018"
[lib]
plugin = true
path = "./lib.rs"
name = "moordyn"
[dependencies]
libc = "0.2"
[build-dependencies]
Expand Down
Loading