Skip to content

Commit 47b64fb

Browse files
authored
Merge pull request #312 from MediosZ/fix-rs
Fix rs_port and other rust tests.
2 parents 258d9e8 + 76543d0 commit 47b64fb

File tree

8 files changed

+52
-17
lines changed

8 files changed

+52
-17
lines changed

source/loaders/rs_loader/rust/compiler/src/api/class.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ extern "C" fn class_singleton_static_await(
119119

120120
#[no_mangle]
121121
extern "C" fn class_singleton_destroy(_klass: OpaqueType, class_impl: OpaqueType) {
122-
unsafe {
123-
let class_impl_ptr = class_impl as *mut class::Class;
124-
let class = Box::from_raw(class_impl_ptr);
125-
drop(class);
126-
}
122+
// unsafe {
123+
// let class_impl_ptr = class_impl as *mut class::Class;
124+
// let class = Box::from_raw(class_impl_ptr);
125+
// drop(class);
126+
// }
127127
println!("class destroy");
128128
}
129129

source/loaders/rs_loader/rust/compiler/src/api/function.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ extern "C" fn function_singleton_await(
6161

6262
#[no_mangle]
6363
extern "C" fn function_singleton_destroy(_func: OpaqueType, func_impl: OpaqueType) {
64-
unsafe {
65-
let func_ptr = Box::from_raw(func_impl as *mut class::NormalFunction);
66-
drop(func_ptr);
67-
}
64+
// comment out this due to the seg fault
65+
// unsafe {
66+
// let func_ptr = Box::from_raw(func_impl as *mut class::NormalFunction);
67+
// drop(func_ptr);
68+
// }
6869
}
6970

7071
#[no_mangle]

source/loaders/rs_loader/rust/compiler/src/api/object.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ extern "C" fn object_singleton_method_await(
123123
}
124124
#[no_mangle]
125125
extern "C" fn object_singleton_destructor(_object: OpaqueType, object_impl: OpaqueType) -> c_int {
126-
unsafe {
127-
let object_impl_ptr = object_impl as *mut Object;
128-
let object = Box::from_raw(object_impl_ptr);
129-
drop(object);
130-
}
126+
// unsafe {
127+
// let object_impl_ptr = object_impl as *mut Object;
128+
// let object = Box::from_raw(object_impl_ptr);
129+
// drop(object);
130+
// }
131131
println!("destruct object");
132132
0
133133
}

source/loaders/rs_loader/rust/compiler/src/wrapper/class.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::collections::HashMap;
66
use std::ffi::CStr;
77
use std::fmt;
88
use std::sync::Arc;
9+
use std::convert::TryInto;
910
type Result<T, E = i32> = core::result::Result<T, E>;
1011
use std::os::raw::{c_char, c_double, c_float, c_int, c_long, c_short, c_void};
1112
extern "C" {

source/ports/rs_port/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ add_dependencies(${target}
4747
#
4848

4949
add_test(NAME ${target}
50-
COMMAND ${CMAKE_COMMAND} -E env RUSTFLAGS=-Zmacro-backtrace ${Rust_CARGO_EXECUTABLE} test
50+
COMMAND ${CMAKE_COMMAND} -E env CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR} RUSTFLAGS=-Zmacro-backtrace ${Rust_CARGO_EXECUTABLE} test
5151
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
5252
)
5353

source/ports/rs_port/build.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::env;
2+
fn main() {
3+
// when running tests
4+
if let Ok(val) = env::var("CMAKE_BINARY_DIR") {
5+
println!("cargo:rustc-link-search={val}");
6+
7+
match env::var("CMAKE_BUILD_TYPE") {
8+
Ok(val) => {
9+
if val == "Debug" {
10+
// try to link the debug version when running tests
11+
println!("cargo:rustc-link-lib=metacalld");
12+
} else {
13+
println!("cargo:rustc-link-lib=metacall");
14+
}
15+
}
16+
Err(_) => {
17+
println!("cargo:rustc-link-lib=metacall");
18+
}
19+
}
20+
21+
println!("cargo:rustc-env=LD_LIBRARY_PATH={val}");
22+
println!("cargo:rustc-env=CONFIGURATION_PATH={val}/configurations/global.json")
23+
} else {
24+
println!("cargo:rustc-link-lib=metacall");
25+
}
26+
27+
// default install location
28+
29+
// user defined location
30+
}

source/ports/rs_port/src/abi.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ pub mod interface {
22
use std::os::raw::{c_char, c_double, c_float, c_int, c_long, c_short, c_void};
33

44
// requires libmetacall to be in $PATH
5-
#[link(name = "metacall")]
5+
// we will set it in build.rs
6+
// #[link(name = "metacall")]
67
extern "C" {
78
pub fn metacall_destroy() -> c_int;
89
pub fn metacall_initialize() -> c_int;

source/scripts/rust/cmake/RustProject.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function(rust_project target version)
4646
set(PACKAGE_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/build/timestamp")
4747

4848
# Create project file
49-
script_project(${target} rust ${RUST_PROJECT_CONFIG_PATH}/RustProject.cmake.in)
49+
script_project(${target} rust ${RUST_PROJECT_CONFIG_PATH}/RustProject.cmake.in)
5050

5151
endfunction()
5252

@@ -100,6 +100,8 @@ function(rust_package target version script)
100100

101101
# Compile scripts
102102
add_custom_command(TARGET ${custom_target} PRE_BUILD
103+
# fix the version of rustc
104+
COMMAND ${Rust_RUSTUP_EXECUTABLE} default nightly-2021-12-04
103105
COMMAND ${Rust_RUSTC_EXECUTABLE} --crate-type=lib
104106
${CMAKE_CURRENT_SOURCE_DIR}/source/${script}.rs
105107
--out-dir ${LOADER_SCRIPT_PATH}

0 commit comments

Comments
 (0)