Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: C++17 is not enabled on all platforms #2650

Closed
rkuester opened this issue Jul 31, 2024 · 3 comments
Closed

build: C++17 is not enabled on all platforms #2650

rkuester opened this issue Jul 31, 2024 · 3 comments

Comments

@rkuester
Copy link
Contributor

Bazel builds have been C++17 since 52c9568; however, Makefile builds remain C++11. Consistent with our webpage documentation and to match TF Lite's language support, it's our desire to support and compile as C++17 on all platforms.

@rkuester
Copy link
Contributor Author

After trying to set -std=c++17 and c17 in PR #2648, the only problem appears to be the age of the Xtensa toolchain. The flatbuffers library includes <optional> when it's being compiled under the C++17 standard. The Xtensa toolchain is happy enough to compile with -std=c++17, but the standard library appears to be incomplete—it doesn't have <optional>. E.g., from the PR's CI run:

https://github.com/tensorflow/tflite-micro/actions/runs/10152485116/job/28074001989?pr=2648#step:3:367

xt-clang++ -std=c++17 [...]
[....]
.../micro/tools/make/downloads/flatbuffers/include/flatbuffers/stl_emulation.h:41:12: fatal error:
'optional' file not found
  #include <optional>
           ^~~~~~~~~~

Perhaps upgrading the Xtensa toolchain, which is quite old, will fix this.

For reference, the current toolchain is identified and invoked here:

docker run --env XTENSA_TOOLS_VERSION=RI-2020.4-linux --rm -v `pwd`:/opt/tflite-micro ghcr.io/tflm-bot/xtensa_xplorer_13:0.3 \

@rascani
Copy link
Contributor

rascani commented Jul 31, 2024

I tested this out for at least the hifi3 builds and got it to compile with -stdlib=libc++. I think the default stdlib for Xtensa only supports C++14. The downside is that I think that pre-compiled library includes rtti & exception support, so it likely has some bloat. In newer versions of Xtensa toolchain, we can use libc++-re to disable those.

mergify bot pushed a commit that referenced this issue Aug 1, 2024
Begin using -std=c++17 and -std=c17 in Makefile builds on
all platforms. Bazel builds have been using C++17 since 52c9568.

Set `-stdlib=libc++ on xt-clang` on Xtensa to add C++17 library
support in addition to compiler support. From the xt-clang docs:

    Starting with the RI-2019.1 release, XT-CLANG has included support
    for C++14 and C++17 language features. The compiler support for
    C++14 and C++17 is accompanied by the C++ library from the LLVM
    project. This library can be selected with the -stdlib=libc++
    option, and this is strongly recommended when compiling with
    -std=c++14 or - std=c++17. Starting with the RI-2021.6 release, two
    additional versions of this C++ library are provided— one that
    excludes support for exception handling, and one that excludes both
    exception handling and run-time type identification. These libraries
    can be selected with -stdlib=libc ++-e and -stdlib=libc++-re options
    respectively.

Based on the `docker run` command in
tflite-micro/.github/workflows/xtensa_presubmit.yml, our CI is
currently using RI-2020.4.

Refactor the make/ext_libs/xtensa_download.sh script to make it eaiser
to patch downloads for all Xtensa platforms. The old script made overly
strict assumptions about the name of the patch.

Patch the Xtensa vision_p6 platform download xi_tflmlib_vision_p6 for
compatibility with the C++ library standard. Use the header <climits> to
access constants such as INT_MAX.

BUG=#2650
@rkuester
Copy link
Contributor Author

rkuester commented Aug 1, 2024

Fixed in #2648.

@rkuester rkuester closed this as completed Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants