diff --git a/build.rs b/build.rs index ead5874..bb8f744 100644 --- a/build.rs +++ b/build.rs @@ -156,7 +156,7 @@ fn main() { // Prefix symbols in Cyclone DDS and Cyclocut libraries to ensure uniqueness #[cfg(all(target_os = "linux", not(feature = "iceoryx")))] { - // Prefix = cyclors__ + // Prefix = cyclors_ prefix = env::var("CARGO_PKG_VERSION").unwrap().replace('.', "_"); prefix.insert_str(0, "cyclors_"); prefix.push('_'); @@ -292,11 +292,14 @@ fn prefix_symbols( lib_name )); } - let arg = format!("--redefine-syms={}", symbol_file_path.to_str().unwrap()); - match Command::new("objcopy").arg(arg).arg(lib_file_path).output() { - Ok(_) => Ok(()), - Err(_) => Err(format!("Failed to run objcopy on library {}", lib_name)), - } + + let mut objcopy = cmake::Config::new("objcopy"); + objcopy + .build_target("all") + .define("LIB_PATH", lib_file_path.clone()) + .define("SYMBOL_FILE_PATH", symbol_file_path.clone()) + .build(); + Ok(()) } Err(_) => Err(format!( "Failed to create symbol file for library {}", diff --git a/cyclocut/CMakeLists.txt b/cyclocut/CMakeLists.txt index 9f9254d..162e9fc 100644 --- a/cyclocut/CMakeLists.txt +++ b/cyclocut/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.0.0) +cmake_minimum_required(VERSION 3.5) project(cdds-util VERSION 0.1.6) include(CTest) diff --git a/objcopy/CMakeLists.txt b/objcopy/CMakeLists.txt new file mode 100644 index 0000000..ddd3433 --- /dev/null +++ b/objcopy/CMakeLists.txt @@ -0,0 +1,50 @@ +cmake_minimum_required(VERSION 3.12) +project(Objcopy) + +# Include the CMakeFindBinUtils module to find objcopy +include(CMakeFindBinUtils) + +# Ensure objcopy is available +if(NOT CMAKE_OBJCOPY) + message(FATAL_ERROR "CMAKE_OBJCOPY is not defined. Ensure objcopy is installed on your system!") +else() + message(STATUS "CMAKE_OBJCOPY found: ${CMAKE_OBJCOPY}") +endif() + +# Ensure LIB_PATH is defined and exists +if(NOT DEFINED LIB_PATH) + message(FATAL_ERROR "LIB_PATH not specified!") +else() + if(NOT EXISTS ${LIB_PATH}) + message(FATAL_ERROR "Library not found: ${LIB_PATH}") + else() + message(STATUS "LIB_PATH: ${LIB_PATH}") + endif() +endif() + +# Ensure SYMBOL_FILE_PATH is defined and exists +if(NOT DEFINED SYMBOL_FILE_PATH) + message(FATAL_ERROR "SYMBOL_FILE_PATH not specified!") +else() + if(NOT EXISTS ${SYMBOL_FILE_PATH}) + message(FATAL_ERROR "Symbol file not found: ${SYMBOL_FILE_PATH}") + else() + message(STATUS "SYMBOL_FILE_PATH: ${SYMBOL_FILE_PATH}") + endif() +endif() + +# Custom target to mangle the library +add_custom_target(mangle_library ALL + COMMAND ${CMAKE_COMMAND} -E echo "Running objcopy --redefine-syms on ${LIB_PATH} with symbols from ${SYMBOL_FILE_PATH}..." + + # Run objcopy and redirect stderr to a file + COMMAND ${CMAKE_OBJCOPY} --redefine-syms=${SYMBOL_FILE_PATH} ${LIB_PATH} 2> stderr.txt + + # Check if stderr.txt is empty (i.e., no errors were produced) + COMMAND ${CMAKE_COMMAND} -E echo "Checking for objcopy errors..." + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/check_errors.sh + + # Clean up stderr.txt after checking for errors + COMMAND ${CMAKE_COMMAND} -E remove stderr.txt + COMMENT "Mangling library with objcopy..." +) diff --git a/objcopy/check_errors.sh b/objcopy/check_errors.sh new file mode 100755 index 0000000..afc9db1 --- /dev/null +++ b/objcopy/check_errors.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +if [ ! -s stderr.txt ]; then + echo 'Command succeeded with no stderr output.' + exit 0 +else + echo 'Command failed with errors:' + cat stderr.txt + exit 1 +fi