Skip to content

Commit

Permalink
[common] Switch to std::filesystem
Browse files Browse the repository at this point in the history
Deprecate unused ghc_filesystem external.
  • Loading branch information
jwnimmer-tri committed Sep 4, 2022
1 parent 8dff9ef commit 3eab23d
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 48 deletions.
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 an Anzu 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

0 comments on commit 3eab23d

Please sign in to comment.