Skip to content

Commit b0c868a

Browse files
committed
Add C++ support and CMake fixes for newlib targets.
1 parent 3b4a7b1 commit b0c868a

8 files changed

+110
-36
lines changed

ci/test.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ main() {
7171
popd
7272

7373
rm -rf "${td}"
74-
75-
return
7674
fi
7775

7876
# `cross build` test for the other targets
@@ -166,7 +164,7 @@ main() {
166164
fi
167165

168166
# Test C++ support
169-
if (( ${CPP:-0} )); then
167+
if (( ${STD:-0} )) && (( ${CPP:-0} )); then
170168
td="$(mkcargotemp -d)"
171169

172170
git clone --depth 1 https://github.com/cross-rs/rust-cpp-hello-word "${td}"
@@ -205,10 +203,10 @@ main() {
205203

206204
pushd "${td}"
207205
retry cargo fetch
208-
if (( ${RUN:-0} )); then
206+
if (( ${STD:-0} )) && (( ${RUN:-0} )); then
209207
cross_run --target "${TARGET}"
210208
else
211-
"${CROSS[@]}" build --target "${TARGET}" ${CROSS_FLAGS}
209+
"${CROSS[@]}" build --lib --target "${TARGET}" ${CROSS_FLAGS}
212210
fi
213211
popd
214212

docker/Dockerfile.thumbv6m-none-eabi

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,22 @@ RUN /cmake.sh
1010
COPY xargo.sh /
1111
RUN /xargo.sh
1212

13-
COPY qemu.sh /
1413
RUN apt-get update && apt-get install --assume-yes --no-install-recommends \
1514
gcc-arm-none-eabi \
16-
libnewlib-arm-none-eabi && \
17-
/qemu.sh arm
15+
libnewlib-arm-none-eabi \
16+
libstdc++-arm-none-eabi-newlib
17+
18+
COPY qemu.sh /
19+
RUN /qemu.sh arm
20+
21+
COPY newlib.cmake /opt/newlib.cmake
22+
ENV CMAKE_TOOLCHAIN_FILE=/opt/newlib.cmake
23+
ENV CROSS_NEWLIB_OBJECT_FLAGS="-ffunction-sections -fdata-sections -mthumb -march=armv6s-m"
1824

19-
ENV QEMU_CPU=cortex-m3 \
25+
ENV QEMU_CPU=cortex-m1 \
2026
AR_thumbv6m_none_eabi=arm-none-eabi-ar \
2127
CC_thumbv6m_none_eabi=arm-none-eabi-gcc \
2228
CXX_thumbv6m_none_eabi=arm-none-eabi-g++ \
23-
CARGO_TARGET_THUMBV6M_NONE_EABI_RUNNER=qemu-arm
29+
CARGO_TARGET_THUMBV6M_NONE_EABI_RUNNER=qemu-arm \
30+
CROSS_NEWLIB_ARCH=armv6-m \
31+
CROSS_NEWLIB_TARGET=arm-none-eabi

docker/Dockerfile.thumbv7em-none-eabi

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,22 @@ RUN /cmake.sh
1010
COPY xargo.sh /
1111
RUN /xargo.sh
1212

13-
COPY qemu.sh /
1413
RUN apt-get update && apt-get install --assume-yes --no-install-recommends \
1514
gcc-arm-none-eabi \
16-
libnewlib-arm-none-eabi && \
17-
/qemu.sh arm
15+
libnewlib-arm-none-eabi \
16+
libstdc++-arm-none-eabi-newlib
17+
18+
COPY qemu.sh /
19+
RUN /qemu.sh arm
20+
21+
COPY newlib.cmake /opt/newlib.cmake
22+
ENV CMAKE_TOOLCHAIN_FILE=/opt/newlib.cmake
23+
ENV CROSS_NEWLIB_OBJECT_FLAGS="-ffunction-sections -fdata-sections -mthumb -march=armv7e-m"
1824

1925
ENV QEMU_CPU=cortex-m4 \
2026
AR_thumbv7em_none_eabi=arm-none-eabi-ar \
2127
CC_thumbv7em_none_eabi=arm-none-eabi-gcc \
2228
CXX_thumbv7em_none_eabi=arm-none-eabi-g++ \
23-
CARGO_TARGET_THUMBV7EM_NONE_EABI_RUNNER=qemu-arm
29+
CARGO_TARGET_THUMBV7EM_NONE_EABI_RUNNER=qemu-arm \
30+
CROSS_NEWLIB_ARCH=armv7e-m \
31+
CROSS_NEWLIB_TARGET=arm-none-eabi

docker/Dockerfile.thumbv7em-none-eabihf

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,22 @@ RUN /cmake.sh
1010
COPY xargo.sh /
1111
RUN /xargo.sh
1212

13-
COPY qemu.sh /
1413
RUN apt-get update && apt-get install --assume-yes --no-install-recommends \
1514
gcc-arm-none-eabi \
16-
libnewlib-arm-none-eabi && \
17-
/qemu.sh arm
15+
libnewlib-arm-none-eabi \
16+
libstdc++-arm-none-eabi-newlib
17+
18+
COPY qemu.sh /
19+
RUN /qemu.sh arm
20+
21+
COPY newlib.cmake /opt/newlib.cmake
22+
ENV CMAKE_TOOLCHAIN_FILE=/opt/newlib.cmake
23+
ENV CROSS_NEWLIB_OBJECT_FLAGS="-ffunction-sections -fdata-sections -mthumb -mfloat-abi=hard -march=armv7e-m -mfpu=fpv4-sp-d16"
1824

1925
ENV QEMU_CPU=cortex-m4 \
2026
AR_thumbv7em_none_eabihf=arm-none-eabi-ar \
2127
CC_thumbv7em_none_eabihf=arm-none-eabi-gcc \
2228
CXX_thumbv7em_none_eabihf=arm-none-eabi-g++ \
23-
CARGO_TARGET_THUMBV7EM_NONE_EABIHF_RUNNER=qemu-arm
29+
CARGO_TARGET_THUMBV7EM_NONE_EABIHF_RUNNER=qemu-arm \
30+
CROSS_NEWLIB_ARCH=armv7e-m \
31+
CROSS_NEWLIB_TARGET=arm-none-eabi

docker/Dockerfile.thumbv7m-none-eabi

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,22 @@ RUN /cmake.sh
1010
COPY xargo.sh /
1111
RUN /xargo.sh
1212

13-
COPY qemu.sh /
1413
RUN apt-get update && apt-get install --assume-yes --no-install-recommends \
1514
gcc-arm-none-eabi \
16-
libnewlib-arm-none-eabi && \
17-
/qemu.sh arm
15+
libnewlib-arm-none-eabi \
16+
libstdc++-arm-none-eabi-newlib
17+
18+
COPY qemu.sh /
19+
RUN /qemu.sh arm
20+
21+
COPY newlib.cmake /opt/newlib.cmake
22+
ENV CMAKE_TOOLCHAIN_FILE=/opt/newlib.cmake
23+
ENV CROSS_NEWLIB_OBJECT_FLAGS="-ffunction-sections -fdata-sections -mthumb -march=armv7-m"
1824

1925
ENV QEMU_CPU=cortex-m3 \
2026
AR_thumbv7m_none_eabi=arm-none-eabi-ar \
2127
CC_thumbv7m_none_eabi=arm-none-eabi-gcc \
2228
CXX_thumbv7m_none_eabi=arm-none-eabi-g++ \
23-
CARGO_TARGET_THUMBV7M_NONE_EABI_RUNNER=qemu-arm
29+
CARGO_TARGET_THUMBV7M_NONE_EABI_RUNNER=qemu-arm \
30+
CROSS_NEWLIB_ARCH=armv7-m \
31+
CROSS_NEWLIB_TARGET=arm-none-eabi

docker/android.cmake

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ set(CMAKE_ANDROID_API "$ENV{CROSS_ANDROID_SDK}")
88
# not all of these are standard, however, they're common enough
99
# that it's good practice to define them.
1010
set(prefix "$ENV{CROSS_ANDROID_TARGET}")
11-
set(CMAKE_C_COMPILER "/android-ndk/bin/${prefix}-gcc")
12-
set(CMAKE_ASM_COMPILER "/android-ndk/bin/${prefix}-gcc")
13-
set(CMAKE_CXX_COMPILER "/android-ndk/bin/${prefix}-g++")
14-
set(CMAKE_AR "/android-ndk/bin/${prefix}-ar")
15-
set(CMAKE_LINKER "/android-ndk/bin/${prefix}-ld")
16-
set(CMAKE_NM "/android-ndk/bin/${prefix}-nm")
17-
set(CMAKE_OBJCOPY "/android-ndk/bin/${prefix}-objcopy")
18-
set(CMAKE_OBJDUMP "/android-ndk/bin/${prefix}-objdump")
19-
set(CMAKE_RANLIB "/android-ndk/bin/${prefix}-ranlib")
20-
set(CMAKE_STRIP "/android-ndk/bin/${prefix}-strip")
11+
set(CMAKE_C_COMPILER "${prefix}-gcc")
12+
set(CMAKE_ASM_COMPILER "${prefix}-gcc")
13+
set(CMAKE_CXX_COMPILER "${prefix}-g++")
14+
set(CMAKE_AR "${prefix}-ar")
15+
set(CMAKE_LINKER "${prefix}-ld")
16+
set(CMAKE_NM "${prefix}-nm")
17+
set(CMAKE_OBJCOPY "${prefix}-objcopy")
18+
set(CMAKE_OBJDUMP "${prefix}-objdump")
19+
set(CMAKE_RANLIB "${prefix}-ranlib")
20+
set(CMAKE_STRIP "${prefix}-strip")
2121

2222
# required because otherwise it tries to detect compiler features
2323
# from `/android-ndk/bin/clang`, which fails. these macros are
@@ -26,3 +26,8 @@ include(CMakeForceCompiler)
2626
set(CMAKE_WARN_DEPRECATED FALSE)
2727
CMAKE_FORCE_C_COMPILER("${CMAKE_C_COMPILER}" GNU)
2828
CMAKE_FORCE_CXX_COMPILER("${CMAKE_CXX_COMPILER}" GNU)
29+
30+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
31+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
32+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
33+
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)

docker/newlib.cmake

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# toolchain file for newlib targets, see #1110
2+
3+
# if we don't set generic, it tries to test the compiler which fails
4+
set(CMAKE_SYSTEM_NAME Generic)
5+
set(CMAKE_SYSTEM_PROCESSOR "$ENV{CROSS_NEWLIB_ARCH}")
6+
7+
# not all of these are standard, however, they're common enough
8+
# that it's good practice to define them.
9+
set(prefix "$ENV{CROSS_NEWLIB_TARGET}")
10+
set(CMAKE_C_COMPILER "${prefix}-gcc")
11+
set(CMAKE_ASM_COMPILER "${prefix}-gcc")
12+
set(CMAKE_CXX_COMPILER "${prefix}-g++")
13+
set(CMAKE_AR "${prefix}-ar")
14+
set(CMAKE_LINKER "${prefix}-ld")
15+
set(CMAKE_NM "${prefix}-nm")
16+
set(CMAKE_OBJCOPY "${prefix}-objcopy")
17+
set(CMAKE_OBJDUMP "${prefix}-objdump")
18+
set(CMAKE_RANLIB "${prefix}-ranlib")
19+
set(CMAKE_STRIP "${prefix}-strip")
20+
21+
set(CMAKE_FIND_ROOT_PATH "/usr/lib/${CROSS_NEWLIB_TARGET}" "${CMAKE_PREFIX_PATH}")
22+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
23+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
24+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
25+
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
26+
27+
# these are cached so any build system that compiled outside of the rust
28+
# build system, such as a third-party cmake build and install of a shared
29+
# library, will still work. however, cmake-rs can override these values
30+
set(CMAKE_C_FLAGS "$ENV{CROSS_NEWLIB_OBJECT_FLAGS}" CACHE INTERNAL "C Compiler options")
31+
set(CMAKE_CXX_FLAGS "$ENV{CROSS_NEWLIB_OBJECT_FLAGS}" CACHE INTERNAL "C++ Compiler options")
32+
set(CMAKE_ASM_FLAGS "$ENV{CROSS_NEWLIB_OBJECT_FLAGS}" CACHE INTERNAL "ASM Compiler options")
33+
34+
# bare-metal and missing start files, make a static library
35+
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

targets.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,22 +440,26 @@ std = true
440440
[[target]]
441441
target = "thumbv6m-none-eabi"
442442
os = "ubuntu-latest"
443-
std = true
443+
cpp = true
444+
std = false
444445

445446
[[target]]
446447
target = "thumbv7em-none-eabi"
447448
os = "ubuntu-latest"
448-
std = true
449+
cpp = true
450+
std = false
449451

450452
[[target]]
451453
target = "thumbv7em-none-eabihf"
452454
os = "ubuntu-latest"
453-
std = true
455+
cpp = true
456+
std = false
454457

455458
[[target]]
456459
target = "thumbv7m-none-eabi"
457460
os = "ubuntu-latest"
458-
std = true
461+
cpp = true
462+
std = false
459463

460464
[[target]]
461465
target = "cross"

0 commit comments

Comments
 (0)