esp-idf icon indicating copy to clipboard operation
esp-idf copied to clipboard

docs(c++): std::filesystem is generally supported (#5003) (IDFGH-12755)

Open nebkat opened this issue 1 year ago • 6 comments

Have been using most std::filesystem features successfully since IDF v5.1, and now std::filesystem::directory_iterator is also fixed since 994b4ed459269be1f6548137eac84ec3f9a8e37f.

nebkat avatar May 02 '24 22:05 nebkat

Messages
:book: 🎉 Good Job! All checks are passing!

👋 Hello nebkat, we appreciate your contribution to this project!


📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more.

🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project.

Click to see more instructions ...


This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with each push event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests via this public GitHub repository.

This GitHub project is public mirror of our internal git repository

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved, we synchronize it into our internal git repository.
4. In the internal git repository we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
5. If the change is approved and passes the tests it is merged into the default branch.
5. On next sync from the internal git repository merged change will appear in this public GitHub repository.

Generated by :no_entry_sign: dangerJS against cae6a35ac71eb827024c6e46c7ad4512567b1658

github-actions[bot] avatar May 02 '24 22:05 github-actions[bot]

sha=cae6a35ac71eb827024c6e46c7ad4512567b1658

igrr avatar May 06 '24 09:05 igrr

@nebkat Thanks for the PR!

In #5003 you wrote,

I have found most std::filesystem functions actually work quite well, except for some unusual cases in path concatenation, and std::filesystem::directory_iterator does not work at all.

Do you recall what were the "some unusual cases in path concatenation"? We probably need to add some tests if we want to claim that std::filesystem is supported, so I'm wondering if we should check something specific.

igrr avatar May 06 '24 09:05 igrr

Actually we found that some functions used by std::filesystem aren't implemented in IDF, resulting in linker errors. For example, fpathconf, dirfd and others. We'll probably need to implement these first, before merging this PR.

igrr avatar May 06 '24 10:05 igrr

I believe the issue I encountered was with copying std::filesystem::paths - I had to do std::filesystem::path copy { other.c_str() } as other directly resulted in an empty string. This was however over a year ago, I will test again later this week.

For dirfd at least there is _GLIBCXX_HAVE_DIRFD, not sure about others. If you can share the functions that are causing linker errors I can do some further investigating if that would be of assistance!

nebkat avatar May 07 '24 19:05 nebkat

@nebkat Here is my current changeset on top of your commit. You can see the few added stub functions there.

esp-idf-13cf3f6-333f1db.patch.txt

We will take a look at _GLIBCXX_HAVE_DIRFD and other config options. Not all of the current settings seem to make sense to me.

igrr avatar May 09 '24 11:05 igrr

Actually we found that some functions used by std::filesystem aren't implemented in IDF, resulting in linker errors. For example, fpathconf, dirfd and others. We'll probably need to implement these first, before merging this PR.

Ironically v5.3-beta1 has seemingly completely broken <filesystem> for me, not sure if related to your linker errors?

[5/7] Linking CXX executable mdf-firmware.elf
FAILED: mdf-firmware.elf
cmd.exe /C "cd . && C:\Users\Nebojsa\.espressif\tools\xtensa-esp-elf\esp-13.2.0_20240305\xtensa-esp-elf\bin\xtensa-esp32s3-elf-g++.exe -mlongcalls  -fno-builtin-memcpy -fno-builtin-memset -fno-builtin-bzero -fno-builtin-stpcpy -fno-builtin-strncpy -Wl,--cref -Wl,--defsym=IDF_TARGET_ESP32S3=0 -Wl,--Map=C:/Users/Nebojsa/Work/Troo/mdf-firmware/build/rtk_v1_7_dbg/mdf-firmware.map -Wl,--no-warn-rwx-segments -fno-rtti -fno-lto -Wl,--gc-sections -Wl,--warn-common -T esp32s3.peripherals.ld -T esp32s3.rom.ld -T esp32s3.rom.api.ld -T esp32s3.rom.libgcc.ld -T esp32s3.rom.wdt.ld -T esp32s3.rom.version.ld -T esp32s3.rom.newlib.ld -T memory.ld -T sections.ld @CMakeFiles\mdf-firmware.elf.rsp -o mdf-firmware.elf  && cd ."
C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/lib/esp32s3/no-rtti\libstdc++.a(fs_ops.o):(.literal._ZNSt10filesystem12current_pathB5cxx11ERSt10error_code+0x8): warning: pathconf is not implemented and will always fail
C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/lib/esp32s3/no-rtti\libstdc++.a(fs_ops.o):(.literal._ZNSt10filesystem11permissionsERKNS_7__cxx114pathENS_5permsENS_12perm_optionsERSt10error_code+0xc): warning: chmod is not implemented and will always fail
C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/lib/esp32s3/no-rtti\libstdc++.a(fs_dir.o):(.literal._ZNKSt10filesystem7__cxx114_Dir7currentEv[_ZNKSt10filesystem7__cxx114_Dir7currentEv]+0x4): warning: dirfd is not implemented and will always fail
C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: esp-idf/mbedtls/mbedtls/library/libmbedx509.a(x509_crt.c.obj):(.literal.mbedtls_x509_crt_parse_path+0x28): warning: readdir is not implemented and will always fail
C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/lib/esp32s3/no-rtti\libstdc++.a(fs_ops.o):(.literal._ZNSt10filesystem12current_pathERKNS_7__cxx114pathERSt10error_code+0x0): warning: chdir is not implemented and will always fail
C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/lib/esp32s3/no-rtti\libstdc++.a(fs_ops.o):(.literal._ZNSt10filesystem12current_pathB5cxx11ERSt10error_code+0x14): warning: getcwd is not implemented and will always fail
C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/lib/esp32s3/no-rtti\libstdc++.a(fs_ops.o):(.literal._ZN12_GLOBAL__N_110create_dirERKNSt10filesystem7__cxx114pathENS0_5permsERSt10error_code+0x0): warning: mkdir is not implemented and will always fail
C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: esp-idf/mbedtls/mbedtls/library/libmbedx509.a(x509_crt.c.obj):(.literal.mbedtls_x509_crt_parse_path+0x2c): warning: closedir is not implemented and will always fail
C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: esp-idf/mbedtls/mbedtls/library/libmbedx509.a(x509_crt.c.obj):(.literal.mbedtls_x509_crt_parse_path+0x10): warning: opendir is not implemented and will always fail
C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/lib/esp32s3/no-rtti\libnosys.a(dir.o): in function `opendir':
/builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp-elf/src/newlib/libgloss/libnosys/dir.c:16: multiple definition of `opendir'; esp-idf/vfs/libvfs.a(vfs.c.obj):/IDF/components/vfs/vfs.c:733: first defined here
C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/lib/esp32s3/no-rtti\libnosys.a(dir.o): in function `closedir':
/builds/idf/crosstool-NG/.build/src/newlib-git-070bbf2f/newlib/libc/include/dirent.h:76: multiple definition of `closedir'; esp-idf/vfs/libvfs.a(vfs.c.obj):/IDF/components/vfs/vfs.c:805: first defined here
C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/lib/esp32s3/no-rtti\libnosys.a(dir.o): in function `mkdir':
/builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp-elf/src/newlib/libgloss/libnosys/dir.c:30: multiple definition of `mkdir'; esp-idf/vfs/libvfs.a(vfs.c.obj):/IDF/components/vfs/vfs.c:818: first defined here
C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/lib/esp32s3/no-rtti\libnosys.a(dir.o): in function `getcwd':
/builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp-elf/src/newlib/libgloss/libnosys/dir.c:37: multiple definition of `getcwd'; esp-idf/newlib/libnewlib.a(realpath.c.obj):/IDF/components/newlib/realpath.c:111: first defined here
C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/lib/esp32s3/no-rtti\libnosys.a(dir.o): in function `chdir':
/builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp-elf/src/newlib/libgloss/libnosys/dir.c:42: multiple definition of `chdir'; esp-idf/newlib/libnewlib.a(realpath.c.obj):/IDF/components/newlib/realpath.c:120: first defined here
C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/lib/esp32s3/no-rtti\libnosys.a(dir.o): in function `readdir':
/builds/idf/crosstool-NG/.build/src/newlib-git-070bbf2f/newlib/libc/include/dirent.h:56: multiple definition of `readdir'; esp-idf/vfs/libvfs.a(vfs.c.obj):/IDF/components/vfs/vfs.c:750: first defined here
C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/lib/esp32s3/no-rtti\libnosys.a(dir.o): in function `telldir':
/builds/idf/crosstool-NG/.build/src/newlib-git-070bbf2f/newlib/libc/include/dirent.h:73: multiple definition of `telldir'; esp-idf/vfs/libvfs.a(vfs.c.obj):/IDF/components/vfs/vfs.c:776: first defined here
C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/lib/esp32s3/no-rtti\libnosys.a(dir.o): in function `seekdir':
/builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp-elf/src/newlib/libgloss/libnosys/dir.c:73: multiple definition of `seekdir'; esp-idf/vfs/libvfs.a(vfs.c.obj):/IDF/components/vfs/vfs.c:789: first defined here
C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld.exe: C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/lib/esp32s3/no-rtti\libnosys.a(dir.o): in function `rewinddir':
/builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp-elf/src/newlib/libgloss/libnosys/dir.c:101: multiple definition of `rewinddir'; esp-idf/vfs/libvfs.a(vfs.c.obj):/IDF/components/vfs/vfs.c:800: first defined here
C:/Users/Nebojsa/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240305/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp

nebkat avatar May 30 '24 00:05 nebkat

@nebkat Yep, my patch above should fix these linking issues.

igrr avatar Jun 13 '24 10:06 igrr