From 34ce0d8b952a0923ad6e4f3653d9f7945a651ef7 Mon Sep 17 00:00:00 2001 From: Joshua Liebow-Feeser Date: Fri, 29 Aug 2025 02:30:40 +0000 Subject: [PATCH] Support disabling float parsing and formatting Some users build the standard library with floating point parsing and formatting disabled. By default, zerocopy fails to build under these conditions because it assumes that this support exists. This commit adds support for `--cfg no_fp_fmt_parse` (the same name used to disable floating point support in the standard library). Closes #2673 --- .github/workflows/ci.yml | 9 +++++++++ src/byteorder.rs | 1 + 2 files changed, 10 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 67e507a4a8..9c48978313 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -341,6 +341,15 @@ jobs: run: ./cargo.sh +${{ matrix.toolchain }} build --package ${{ matrix.crate }} --target ${{ matrix.target }} ${{ matrix.features }} --verbose if: matrix.target != 'thumbv6m-none-eabi' + # Ensure that, when the standard library is built with `--cfg + # no_fp_fmt_parse`, building zerocopy with the same `--cfg` succeeds (note + # that `RUSTFLAGS='--cfg no_fp_fmt_parse'` is doing double-duty here - it's + # setting the environment variable for both the standard library build and + # for the zerocopy build). + - name: Build without floating point support + run: RUSTFLAGS='--cfg no_fp_fmt_parse' ./cargo.sh +${{ matrix.toolchain }} build -Zbuild-std --package ${{ matrix.crate }} --target ${{ matrix.target }} ${{ matrix.features }} --verbose + if: matrix.target != 'thumbv6m-none-eabi' + # When building tests for the i686 target, we need certain libraries which # are not installed by default; `gcc-multilib` includes these libraries. - name: Install gcc-multilib diff --git a/src/byteorder.rs b/src/byteorder.rs index 0e6a7ea5da..96c615d268 100644 --- a/src/byteorder.rs +++ b/src/byteorder.rs @@ -174,6 +174,7 @@ macro_rules! impl_fmt_trait { macro_rules! impl_fmt_traits { ($name:ident, $native:ident, "floating point number") => { + #[cfg(not(no_fp_fmt_parse))] impl_fmt_trait!($name, $native, Display); }; ($name:ident, $native:ident, "unsigned integer") => {