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

[common] Switch to std::filesystem #17834

Merged
merged 1 commit into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -338,18 +338,12 @@ drake_cc_library(
)

# The drake::filesystem support is intended ONLY for use within Drake's *.cc
# files -- it is not a public dependency of Drake. As such, we compile it with
# hidden visibility and mark it internal.
# files -- it is not a public dependency of Drake, so we mark it internal.
drake_cc_library(
name = "filesystem",
srcs = ["filesystem.cc"],
hdrs = ["filesystem.h"],
copts = ["-fvisibility=hidden"],
internal = True,
visibility = ["//:__subpackages__"],
deps = [
"@ghc_filesystem",
],
)

drake_cc_library(
Expand Down
23 changes: 0 additions & 23 deletions common/filesystem.cc

This file was deleted.

23 changes: 6 additions & 17 deletions common/filesystem.h
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
#pragma once

// Alias drake::filesystem to either std::filesystem or ghc::filesystem.
// Alias drake::filesystem to std::filesystem.
//
// The drake::filesystem support is intended ONLY for use within Drake's *.cc
// files -- it is not a public dependency of Drake; do not include this file
// from Drake header files.
//
// Note that until Apple ships a working std::filesystem implementation, we
// need to force-disable it. Similarly, GCC prior to 9 requires arcane linker
// flags, so we need to exclude it as well.
//
// Keep this if-sequence in sync with drake/common/filesystem.cc.
#if __has_include(<filesystem>) && !( \
defined(__APPLE__) || \
(!defined(__clang__) && defined(__GNUC__) && (__GNUC__ < 9)))

#include <filesystem>
namespace drake { namespace filesystem = std::filesystem; }

#else
namespace drake {

#define GHC_FILESYSTEM_FWD
#include "ghc/filesystem.hpp"
#undef GHC_FILESYSTEM_FWD
namespace drake { namespace filesystem = ghc::filesystem; }
// For legacy reasons, we have a Drake alias for std::filesystem.
// In the future, we could port to `std` directly and remove this alias.
namespace filesystem = std::filesystem;

#endif
} // namespace drake
1 change: 0 additions & 1 deletion tools/workspace/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ _DRAKE_EXTERNAL_PACKAGE_INSTALLS = ["@%s//:install" % p for p in [
"commons_io",
"fcl",
"fmt",
"ghc_filesystem",
"gz_math_internal",
"gz_utils_internal",
"lcm",
Expand Down
1 change: 1 addition & 0 deletions tools/workspace/ghc_filesystem/package.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ cc_library(
name = "ghc_filesystem",
hdrs = ["include/ghc/filesystem.hpp"],
strip_include_prefix = "include",
deprecation = "DRAKE DEPRECATED: The @ghc_filesystem repository is no longer used by Drake. If you still use it, you may copy the the repository rule into your own project. This target will be removed from Drake on or after 2023-01-01.", # noqa
linkstatic = 1,
)

Expand Down