Skip to content

Commit

Permalink
add support for experimental filesystem - fixes jasonroelofs/rice/197
Browse files Browse the repository at this point in the history
  • Loading branch information
Kendal Miller committed Jan 16, 2024
1 parent 59b0395 commit 39376e2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
13 changes: 11 additions & 2 deletions include/rice/rice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1205,9 +1205,18 @@ namespace Rice::detail
// ========= cpp_protect.hpp =========

#include <regex>
#include <filesystem>
#include <stdexcept>

#if __has_include(<filesystem>)
#include <filesystem>
namespace fs = std::filesystem;
#elif __has_include(<experimental/filesystem>)
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#else
#error "no filesystem include found :'("
#endif


namespace Rice::detail
{
Expand Down Expand Up @@ -1247,7 +1256,7 @@ namespace Rice::detail
{
rb_exc_raise(rb_exc_new2(rb_eArgError, ex.what()));
}
catch (std::filesystem::filesystem_error const& ex)
catch (fs::filesystem_error const& ex)
{
rb_exc_raise(rb_exc_new2(rb_eIOError, ex.what()));
}
Expand Down
4 changes: 3 additions & 1 deletion lib/mkmf-rice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,7 @@ def cpp_command(outfile, opt="")
if IS_DARWIN
have_library('c++')
elsif !IS_MSWIN
have_library('stdc++')
if !have_library('stdc++fs')
have_library('stdc++')
end
end
13 changes: 11 additions & 2 deletions rice/detail/cpp_protect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@
#define Rice__detail__cpp_protect__hpp_

#include <regex>
#include <filesystem>
#include <stdexcept>

#if __has_include(<filesystem>)
#include <filesystem>
namespace fs = std::filesystem;
#elif __has_include(<experimental/filesystem>)
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#else
#error "no filesystem include found :'("
#endif

#include "Jump_Tag.hpp"
#include "../Exception_defn.hpp"

Expand Down Expand Up @@ -46,7 +55,7 @@ namespace Rice::detail
{
rb_exc_raise(rb_exc_new2(rb_eArgError, ex.what()));
}
catch (std::filesystem::filesystem_error const& ex)
catch (fs::filesystem_error const& ex)
{
rb_exc_raise(rb_exc_new2(rb_eIOError, ex.what()));
}
Expand Down

0 comments on commit 39376e2

Please sign in to comment.