Skip to content

Commit 8aebcc0

Browse files
WiP: win debug
1 parent 2ffff63 commit 8aebcc0

File tree

7 files changed

+55
-15
lines changed

7 files changed

+55
-15
lines changed

.cargo/windbg-config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[env]
2+
CFLAGS = "/MDd"
3+
CXXFLAGS = "/MDd"

.github/workflows/rust.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,21 @@ jobs:
4949
steps:
5050
- uses: actions/checkout@v4
5151

52-
- name: Build
52+
- name: Release Build
5353
uses: houseabsolute/actions-rust-cross@v1
5454
with:
5555
command: ${{ matrix.platform.command }}
5656
target: ${{ matrix.platform.target }}
5757
args: "--locked --all --release"
5858

59+
- name: Debug Build
60+
uses: houseabsolute/actions-rust-cross@v1
61+
if: startsWith(matrix.platform.os-name, 'Windows')
62+
with:
63+
command: ${{ matrix.platform.command }}
64+
target: ${{ matrix.platform.target }}
65+
args: "--config .cargo/windbg-config.toml --locked --all"
66+
5967
- name: Store command line tool
6068
uses: actions/upload-artifact@v4
6169
with:

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,15 @@ This creates a distribution archive containing:
185185
- C++ header files
186186
- CMake configuration files
187187

188+
On Windows, if a debug build is necessary, the library can be built with:
189+
```bash
190+
# Build Rust library
191+
cargo build --all
192+
193+
# Generate distribution package
194+
./package.sh
195+
```
196+
188197
### Running Tests
189198

190199
```bash

build.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
1+
use std::env;
2+
13
fn main() {
24
cxx_build::bridge("src/lib.rs")
35
.cpp(true)
46
.std("c++14")
57
.compile("rs_dfu");
8+
9+
if env::var("TARGET").is_ok_and(|s| s.contains("windows-msvc")) {
10+
// MSVC compiler suite
11+
if env::var("CFLAGS").is_ok_and(|s| s.contains("/MDd")) {
12+
// debug runtime flag is set
13+
14+
// Don't link the default CRT
15+
println!("cargo::rustc-link-arg=/nodefaultlib:msvcrt");
16+
// Link the debug CRT instead
17+
println!("cargo::rustc-link-arg=/defaultlib:msvcrtd");
18+
}
19+
}
620
}

cmake/rs_dfu-config.cmake

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ if(WIN32)
77
set(_rs_dfu_lib_prefix "")
88
set(_rs_dfu_shared_ext "dll")
99
set(_rs_dfu_static_ext "lib")
10+
set(_rs_dfu_debug_suffix "d")
1011
set(_rs_dfu_system_libs ws2_32 userenv winusb ntdll cfgmgr32)
1112
elseif(APPLE)
1213
set(_rs_dfu_lib_prefix "lib")
@@ -26,7 +27,13 @@ set(RS_DFU_DIR "${CMAKE_CURRENT_LIST_DIR}/..")
2627
set(RS_DFU_INCLUDE_DIR "${RS_DFU_DIR}/include")
2728
set(RS_DFU_LIB_DIR "${RS_DFU_DIR}/lib")
2829

29-
set(_rs_dfu_static_lib "${RS_DFU_LIB_DIR}/${_rs_dfu_lib_prefix}rs_dfu.${_rs_dfu_static_ext}")
30+
if(CMAKE_BUILD_TYPE STREQUAL "Release")
31+
set(_rs_dfu_libname "${_rs_dfu_lib_prefix}rs_dfu")
32+
else()
33+
set(_rs_dfu_libname "${_rs_dfu_lib_prefix}rs_dfu${_rs_dfu_debug_suffix}")
34+
endif()
35+
36+
set(_rs_dfu_static_lib "${RS_DFU_LIB_DIR}/${_rs_dfu_libname}.${_rs_dfu_static_ext}")
3037

3138
# Create imported target
3239
if(EXISTS "${_rs_dfu_static_lib}" AND NOT TARGET rs_dfu::static)

examples/cpp/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ target_include_directories(cpp-example PRIVATE
4747
${CARGO_CXX_TARGET_DIR}/src
4848
)
4949

50-
target_link_libraries(cpp-example fmt::fmt)
51-
target_link_libraries(cpp-example ${RS_DFU_LIB})
50+
target_link_libraries(cpp-example PRIVATE fmt::fmt)
51+
target_link_libraries(cpp-example PRIVATE ${RS_DFU_LIB})
5252

5353
if(APPLE)
5454
target_link_libraries(cpp-example PRIVATE

package.sh

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,21 @@ esac
2424
LIB_NAME="rs_dfu"
2525
TARGET_DIR=${2:-"target"}
2626

27-
if [ -d "${TARGET_DIR}/release" ]; then
28-
PROFILE_DIR=${3:-"release"}
29-
elif [ -d "${TARGET_DIR}/debug" ]; then
30-
PROFILE_DIR=${3:-"debug"}
31-
TARGET="${TARGET}-debug"
32-
fi
33-
3427
# Create distribution structure
3528
rm -rf dist
3629
mkdir -p dist/cmake dist/include dist/lib
3730

3831
# Copy libraries
39-
STATIC_LIB="${TARGET_DIR}/${PROFILE_DIR}/${LIB_PREFIX}${LIB_NAME}.${STATIC_EXT}"
40-
if [ -f "$STATIC_LIB" ]; then
41-
cp "$STATIC_LIB" "dist/lib/"
42-
echo "Copied: $STATIC_LIB"
32+
RELEASE_LIB="${TARGET_DIR}/release/${LIB_PREFIX}${LIB_NAME}.${STATIC_EXT}"
33+
if [ -f "$RELEASE_LIB" ]; then
34+
cp "$RELEASE_LIB" "dist/lib/"
35+
echo "Copied: $RELEASE_LIB"
36+
fi
37+
38+
DEBUG_LIB="${TARGET_DIR}/debug/${LIB_PREFIX}${LIB_NAME}.${STATIC_EXT}"
39+
if [ -f "$DEBUG_LIB" ]; then
40+
cp "$DEBUG_LIB" "dist/lib/${LIB_PREFIX}${LIB_NAME}d.${STATIC_EXT}"
41+
echo "Copied: $DEBUG_LIB -> ${LIB_PREFIX}${LIB_NAME}d.${STATIC_EXT}"
4342
fi
4443

4544
# Copy headers

0 commit comments

Comments
 (0)