Skip to content

feature: support compilers that use std::experimental::filesystem #3840

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

Merged
merged 10 commits into from
Apr 1, 2022

Conversation

Llcoolsouder
Copy link
Contributor

@Llcoolsouder Llcoolsouder commented Mar 31, 2022

feature: support compilers that use std::experimental::filesystem such as gcc7

Description

Minor changes to support older C++ compilers where filesystem is not yet part of the standard library and is instead included in std::experimental::filesystem.

Suggested changelog entry:

Minor changes to support older C++ compilers where filesystem is not yet part of the standard library and is instead included in ``std::experimental::filesystem``. 

# elif __has_include(<experimental/filesystem>)
# include <experimental/filesystem>
# define PYBIND11_HAS_EXPERIMENTAL_FILESYSTEM 1
namespace pybind11_filesystem_alias = std::experimental::filesystem;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, any reason it needs to / should be in the global namespace? Do we want people downstream to reuse it? Even if we do wouldn't be better to just make it part of the pybind11 namespace?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts @rwgk ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, totally doesn't need to be global

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine either way, I tried to keep it simple for you.
As long as there is a pybind11 prefix, I don't think we'll ever clash with anyone outside.
Formally putting it in pybind11::detail would seem ideal, but at first sight it seems slightly tricky, especially because there is macro logic around the pybind11 namespace that I don't understand 100% TBH.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I would try sticking it in detail and see if anything blows up.

Copy link
Contributor Author

@Llcoolsouder Llcoolsouder Mar 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second glance, I can't actually think of any way to completely remove this from the public API here. I can put it under the pybind11 namespace if that makes us feel better. Between pybind11_filesystem_alias or pybind11::filesystem_alias, I think the intent is clear enough. They're both unlikely to conflict with any user namespaces, they both have clear intent, and even if you were to use it, the can't cause any real damage; it's just a namespace alias.

EDIT: I should have hit refresh before posting. This is all largely redundant now. I'll see what I can do about fitting this into detail

Copy link
Collaborator

@Skylion007 Skylion007 Mar 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Llcoolsouder the detail namespace is how we denote private APIs / functions in pybind11. Putting under the pybind11 namespace would still be better though than leaving it in the current namespace like how it currently is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Skylion007 so we would move the macro logic to detail and then use pybind11::detail::filesystem_alias instead of the current pybind11_filesystem_alias? Or am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if I move this to detail, I have to #include <filesystem> (or #include <experimental/filesystem>) in detail in order to use the namespace alias. So filesystem would be included in every file that includes detail/common.h.

Thoughts?

(Personally at this point, I would just opt for pybind11::filesystem_alias in stl/filesystem.h)

# error \
"#include <filesystem> is not available. (Use -DPYBIND11_HAS_FILESYSTEM_IS_OPTIONAL to ignore.)"
"Neither #include <filesystem> nor #include <experimental/filesystem is available. (Use -DPYBIND11_HAS_FILESYSTEM_IS_OPTIONAL to ignore.)"
#endif

PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_BEGIN(detail)
Copy link
Collaborator

@Skylion007 Skylion007 Mar 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

detail namespace begins here. Can you not just move the include logic after line 38?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not, it's fine as is.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we even need the namespace btw? It's only used on the type caster right? Just mimic what we do for experimental optional and spell it out twice with an IFDEF?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in the latest commit.

Since we're here though, what is the point of the PYBIND11_NAMESPACE_BEGIN and PYBIND11_NAMESPACE_END macros? It looks like we're just replacing the language syntax with a lesser known syntax.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From memory: in some environments the macros insert "visibility hidden" attributes.

Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very clean now.

@rwgk rwgk merged commit b3ebd11 into pybind:master Apr 1, 2022
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Apr 1, 2022
@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label Jul 9, 2022
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

Successfully merging this pull request may close these issues.

4 participants