Skip to content

Commit a6d3427

Browse files
authored
Speedup test running by running rustc directly instead of cargo (#113)
1 parent 0d01b4f commit a6d3427

14 files changed

Lines changed: 123 additions & 79 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ add_custom_command(
7777
)
7878

7979
add_subdirectory(cpp2rust)
80+
add_subdirectory(libc-dep)
8081
add_subdirectory(libcc2rs)
8182
add_subdirectory(tests)
8283

libc-dep/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
set(LIBC_DEP_DIR ${CMAKE_SOURCE_DIR}/libc-dep)
2+
set(LIBC_DEP_OUTPUT ${LIBC_DEP_DIR}/target/release/libc_dep.rlib)
3+
4+
add_custom_command(
5+
OUTPUT ${LIBC_DEP_OUTPUT}
6+
COMMAND cargo +${RUST_STABLE_VERSION} build --release
7+
WORKING_DIRECTORY ${LIBC_DEP_DIR}
8+
DEPENDS "${RUST_STAMP_FILE}" ${LIBC_DEP_DIR}/Cargo.toml
9+
)
10+
11+
add_custom_target(
12+
libc_dep ALL
13+
DEPENDS "${LIBC_DEP_OUTPUT}"
14+
)

libc-dep/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "libc-dep"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
libc = "0.2"

libc-dep/src/lib.rs

Whitespace-only changes.

libcc2rs-macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "libcc2rs-macros"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55

66
[lib]
77
proc-macro = true

libcc2rs-macros/src/goto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use proc_macro::TokenStream;
55
use syn::parse::{Parse, ParseStream};
6-
use syn::{parse_macro_input, Expr, Lifetime, Token};
6+
use syn::{Expr, Lifetime, Token, parse_macro_input};
77

88
use crate::state_machine::{Arm, GotoStateMachine, StateMachine};
99

libcc2rs-macros/src/switch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use proc_macro::TokenStream;
55
use syn::parse::{Parse, ParseStream};
6-
use syn::{parse_macro_input, Expr, Pat};
6+
use syn::{Expr, Pat, parse_macro_input};
77

88
use crate::state_machine::{Arm, DispatchCase, GotoStateMachine, StateMachine, SwitchStateMachine};
99

libcc2rs/CMakeLists.txt

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
1-
set(RUST_LIB_DIR ${CMAKE_SOURCE_DIR}/libcc2rs)
2-
set(RUST_MACROS_DIR ${CMAKE_SOURCE_DIR}/libcc2rs-macros)
3-
set(RUST_BUILD_DIR ${CMAKE_BINARY_DIR}/rust)
4-
file(GLOB_RECURSE LIBCC2RS_SOURCE "${RUST_LIB_DIR}/*.rs")
5-
file(GLOB_RECURSE LIBCC2RS_MACROS_SOURCE "${RUST_MACROS_DIR}/*.rs")
1+
set(LIBCC2RC_LIB_DIR ${CMAKE_SOURCE_DIR}/libcc2rs)
2+
set(LIBCC2RC_MACROS_LIB_DIR ${CMAKE_SOURCE_DIR}/libcc2rs-macros)
3+
set(LIBCC2RS_RLIB ${LIBCC2RC_LIB_DIR}/target/release/liblibcc2rs.rlib)
4+
set(LIBCC2RS_MACROS_RLIB ${LIBCC2RC_LIB_DIR}/target/release/liblibcc2rs-macros.rlib)
5+
file(GLOB_RECURSE LIBCC2RS_SOURCES "${LIBCC2RC_LIB_DIR}/src/*.rs")
6+
file(GLOB_RECURSE LIBCC2RS_MACROS_SOURCES "${LIBCC2RC_MACROS_LIB_DIR}/src/*.rs")
67

78
add_custom_command(
8-
OUTPUT ${RUST_BUILD_DIR}/release/liblibcc2rs.rlib
9-
COMMAND ${CMAKE_COMMAND} -E env CARGO_TARGET_DIR=${RUST_BUILD_DIR} cargo build --release
10-
WORKING_DIRECTORY ${RUST_LIB_DIR}
9+
OUTPUT ${LIBCC2RS_RLIB}
10+
COMMAND cargo +${RUST_STABLE_VERSION} build --release
11+
WORKING_DIRECTORY ${LIBCC2RC_LIB_DIR}
1112
DEPENDS
12-
${LIBCC2RS_SOURCE}
13-
${LIBCC2RS_MACROS_SOURCE}
14-
${RUST_LIB_DIR}/Cargo.toml
15-
${RUST_MACROS_DIR}/Cargo.toml
16-
COMMENT "Building libcc2rs"
13+
"${RUST_STAMP_FILE}"
14+
${LIBCC2RS_SOURCES}
15+
${LIBCC2RS_MACROS_SOURCES}
16+
${LIBCC2RC_LIB_DIR}/Cargo.toml
17+
${LIBCC2RC_MACROS_LIB_DIR}/Cargo.toml
18+
)
19+
20+
add_custom_command(
21+
OUTPUT ${LIBCC2RS_MACROS_RLIB}
22+
COMMAND cargo +${RUST_STABLE_VERSION} build --release
23+
WORKING_DIRECTORY ${LIBCC2RC_MACROS_LIB_DIR}
24+
DEPENDS
25+
"${RUST_STAMP_FILE}"
26+
${LIBCC2RS_MACROS_SOURCES}
27+
${LIBCC2RC_MACROS_LIB_DIR}/Cargo.toml
1728
)
1829

1930
add_custom_target(libcc2rs ALL
20-
DEPENDS ${RUST_BUILD_DIR}/release/liblibcc2rs.rlib "${RUST_STAMP_FILE}"
31+
DEPENDS ${LIBCC2RS_RLIB} ${LIBCC2RS_MACROS_RLIB}
2132
)

libcc2rs/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
[package]
22
name = "libcc2rs"
33
version = "0.1.0"
4-
edition = "2021"
5-
6-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
4+
edition = "2024"
75

86
[dependencies]
97
libcc2rs-macros = { path = "../libcc2rs-macros", version = "0.1.0" }

libcc2rs/src/compat.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use std::ffi::c_void;
55

6-
extern "C" {
6+
unsafe extern "C" {
77
#[cfg(target_os = "linux")]
88
#[link_name = "malloc_usable_size"]
99
fn platform_malloc_size(ptr: *mut c_void) -> usize;
@@ -21,10 +21,10 @@ extern "C" {
2121
pub unsafe fn malloc_usable_size(ptr: *mut c_void) -> usize {
2222
#[cfg(target_os = "linux")]
2323
{
24-
platform_malloc_size(ptr)
24+
unsafe { platform_malloc_size(ptr) }
2525
}
2626
#[cfg(target_os = "macos")]
2727
{
28-
platform_malloc_size(ptr as *const c_void)
28+
unsafe { platform_malloc_size(ptr as *const c_void) }
2929
}
3030
}

0 commit comments

Comments
 (0)