Skip to content

Commit

Permalink
Replace boost filesystem with std filesystem (#649)
Browse files Browse the repository at this point in the history
* chore: set default C++ standard as 17

* refactor: replace boost filesystem with std filesystem

* build: remove boost filesystem component

* feat: make boost dll use std filesystem

* build(Makefile): raise MACOSX_DEPLOYMENT_TARGET to 10.15

* ci(windows-build.yml): improve msys2 setup

use UCRT64 as msystem, which is recommended by msys2.

* ci(windows-build.yml): use pre-installed msys2

* ci(windows-build.yml): disable git line ending auto conversion on Windows ...

... before run actions/checkout to prevent potential problems from msys2.

Ref: https://github.com/marketplace/actions/setup-msys2#actionscheckout-and-line-endings

* build(src/CMakeLists.txt): explicitly link bcrypt to fix build error with mingw64

* ci(Dockerfile): temporarily apply unmerged patch to verify build
  • Loading branch information
WhiredPlanck authored Oct 5, 2023
1 parent 619a67b commit 8bf01e9
Show file tree
Hide file tree
Showing 36 changed files with 153 additions and 117 deletions.
37 changes: 22 additions & 15 deletions .github/workflows/windows-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,26 +138,33 @@ jobs:
shell: msys2 {0}

steps:
- name: Setup MSYS2
- name: Install dependencies with MSYS2
uses: msys2/setup-msys2@v2

with:
release: false
update: true
msystem: UCRT64
install: >-
git
base-devel
mingw-w64-ucrt-x86_64-boost
mingw-w64-ucrt-x86_64-glog
mingw-w64-ucrt-x86_64-gtest
mingw-w64-ucrt-x86_64-yaml-cpp
mingw-w64-ucrt-x86_64-leveldb
mingw-w64-ucrt-x86_64-marisa
mingw-w64-ucrt-x86_64-opencc
pacboy: >-
toolchain:p
cmake:p
ninja:p
- run: git config --global core.autocrlf input
- name: Checkout last commit
uses: actions/checkout@v4
with:
repository: ${{ inputs.repository }}

- name: Install dependencies
run: |
pacman -S --noconfirm git base-devel mingw-w64-x86_64-toolchain ninja \
mingw64/mingw-w64-x86_64-cmake \
mingw-w64-x86_64-boost \
mingw-w64-x86_64-glog \
mingw-w64-x86_64-gtest \
mingw-w64-x86_64-yaml-cpp \
mingw-w64-x86_64-leveldb \
mingw-w64-x86_64-marisa \
mingw-w64-x86_64-opencc

- name: Configure build environment
run: |
echo git_ref_name="$(git describe --always)" >> $GITHUB_ENV
Expand Down
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cxx_fla

cmake_minimum_required(VERSION 3.12)
project(rime)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)

set(rime_version 1.9.0)
set(rime_soversion 1)
Expand Down Expand Up @@ -59,7 +59,7 @@ if(MSVC)
set(Boost_USE_STATIC_RUNTIME ON)
endif()

set(BOOST_COMPONENTS filesystem regex)
set(BOOST_COMPONENTS regex)

if(BOOST_USE_SIGNALS2)
set(RIME_BOOST_SIGNALS2 1)
Expand All @@ -71,6 +71,7 @@ find_package(Boost 1.74.0 REQUIRED COMPONENTS ${BOOST_COMPONENTS})
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
add_definitions(-DBOOST_DLL_USE_STD_FS)
endif()

if(ENABLE_LOGGING)
Expand Down Expand Up @@ -161,7 +162,7 @@ if(MSVC)
endif()

if(UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
endif()

if (NOT CMAKE_BUILD_PARALLEL_LEVEL)
Expand Down
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ RUN apt update && apt install -y \
cmake \
ninja-build \
libboost-dev \
libboost-filesystem-dev \
libboost-regex-dev \
libboost-locale-dev \
libgoogle-glog-dev \
Expand All @@ -22,6 +21,11 @@ WORKDIR /librime/plugins
RUN git clone https://github.com/rime/librime-charcode charcode && \
git clone https://github.com/hchunhui/librime-lua lua && \
git clone https://github.com/lotem/librime-octagram octagram

WORKDIR /librime/plugins/lua
RUN apt install -y curl
RUN curl -LO https://github.com/hchunhui/librime-lua/pull/275.patch
RUN git apply 275.patch

WORKDIR /librime
RUN cmake -B build -G Ninja \
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ endif
export SDKROOT ?= $(shell xcrun --sdk macosx --show-sdk-path)

# https://cmake.org/cmake/help/latest/envvar/MACOSX_DEPLOYMENT_TARGET.html
export MACOSX_DEPLOYMENT_TARGET ?= 10.13
export MACOSX_DEPLOYMENT_TARGET ?= 10.15

ifdef BUILD_UNIVERSAL
# https://cmake.org/cmake/help/latest/envvar/CMAKE_OSX_ARCHITECTURES.html
Expand Down
1 change: 0 additions & 1 deletion action-install-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

dep_packages=(
doxygen
libboost-filesystem-dev
libboost-locale-dev
libboost-regex-dev
libgoogle-glog-dev
Expand Down
1 change: 0 additions & 1 deletion build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ rem set curl=%RIME_ROOT%\bin\curl.exe
rem set download="%curl%" --remote-name-all

set boost_compiled_libs=--with-date_time^
--with-filesystem^
--with-locale^
--with-regex^
--with-thread
Expand Down
2 changes: 1 addition & 1 deletion install-boost.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ download_boost_source() {
[[ -f "${BOOST_ROOT}/bootstrap.sh" ]]
}

boost_libs="${boost_libs=filesystem,regex}"
boost_libs="${boost_libs=regex}"
boost_cxxflags='-arch arm64 -arch x86_64'

build_boost_macos() {
Expand Down
4 changes: 2 additions & 2 deletions plugins/plugins_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

#include <boost/algorithm/string.hpp>
#include <boost/dll.hpp>
#include <boost/filesystem.hpp>
#include <filesystem>
#include <rime/build_config.h>
#include <rime/common.h>
#include <rime/component.h>
#include <rime/module.h>
#include <rime/registry.h>
#include <rime_api.h>

namespace fs = boost::filesystem;
namespace fs = std::filesystem;

namespace rime {

Expand Down
4 changes: 3 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ set(rime_gears_deps
set(rime_levers_deps "")

if(MINGW)
set(rime_core_deps ${rime_core_deps} wsock32 ws2_32)
# fix: bcrypt for boost uuid issue
# https://github.com/boostorg/uuid/issues/68
set(rime_core_deps ${rime_core_deps} wsock32 ws2_32 bcrypt)
endif()

if(BUILD_SEPARATE_LIBS)
Expand Down
20 changes: 20 additions & 0 deletions src/rime/algo/fs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef RIME_FS_H_
#define RIME_FS_H_

#include <chrono>

namespace rime {
namespace filesystem {

template <typename TP>
inline std::time_t to_time_t(TP tp) {
using namespace std::chrono;
auto sctp = time_point_cast<system_clock::duration>(tp - TP::clock::now() +
system_clock::now());
return system_clock::to_time_t(sctp);
}

} // namespace filesystem
} // namespace rime

#endif // RIME_FS_H_
5 changes: 3 additions & 2 deletions src/rime/config/build_info_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// Copyright RIME Developers
// Distributed under the BSD License
//
#include <boost/filesystem.hpp>
#include <filesystem>
#include <rime/service.h>
#include <rime/algo/fs.h>
#include <rime/config/config_compiler.h>
#include <rime/config/config_types.h>
#include <rime/config/plugins.h>
Expand Down Expand Up @@ -36,7 +37,7 @@ bool BuildInfoPlugin::ReviewLinkOutput(ConfigCompiler* compiler,
}
// TODO: store as 64-bit number to avoid the year 2038 problem
timestamps[resource->resource_id] =
(int)boost::filesystem::last_write_time(file_name);
(int)filesystem::to_time_t(std::filesystem::last_write_time(file_name));
});
#endif
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/rime/config/config_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <cstdlib>
#include <fstream>
#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>
#include <filesystem>
#include <boost/format.hpp>
#include <yaml-cpp/yaml.h>
#include <rime/config/config_compiler.h>
Expand Down Expand Up @@ -62,7 +62,7 @@ bool ConfigData::LoadFromFile(const string& file_name,
file_name_ = file_name;
modified_ = false;
root.reset();
if (!boost::filesystem::exists(file_name)) {
if (!std::filesystem::exists(file_name)) {
LOG(WARNING) << "nonexistent config file '" << file_name << "'.";
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/rime/config/save_output_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright RIME Developers
// Distributed under the BSD License
//
#include <boost/filesystem.hpp>
#include <filesystem>
#include <rime/resource.h>
#include <rime/service.h>
#include <rime/config/config_compiler.h>
Expand Down
4 changes: 2 additions & 2 deletions src/rime/deployer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <exception>
#include <utility>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/filesystem.hpp>
#include <filesystem>
#include <rime/deployer.h>

namespace rime {
Expand Down Expand Up @@ -148,7 +148,7 @@ void Deployer::JoinMaintenanceThread() {
}

string Deployer::user_data_sync_dir() const {
return (boost::filesystem::path(sync_dir) / user_id).string();
return (std::filesystem::path(sync_dir) / user_id).string();
}

} // namespace rime
6 changes: 3 additions & 3 deletions src/rime/dict/db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// 2011-11-02 GONG Chen <chen.sst@gmail.com>
//
#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>
#include <filesystem>
#include <rime/common.h>
#include <rime/resource.h>
#include <rime/service.h>
Expand Down Expand Up @@ -40,15 +40,15 @@ Db::Db(const string& file_name, const string& name)
: name_(name), file_name_(file_name) {}

bool Db::Exists() const {
return boost::filesystem::exists(file_name());
return std::filesystem::exists(file_name());
}

bool Db::Remove() {
if (loaded()) {
LOG(ERROR) << "attempt to remove opened db '" << name_ << "'.";
return false;
}
return boost::filesystem::remove(file_name());
return std::filesystem::remove(file_name());
}

bool Db::CreateMetadata() {
Expand Down
6 changes: 3 additions & 3 deletions src/rime/dict/dict_compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// 2011-11-27 GONG Chen <chen.sst@gmail.com>
//
#include <boost/filesystem.hpp>
#include <filesystem>
#include <cfloat>
#include <cmath>
#include <fstream>
Expand All @@ -22,7 +22,7 @@
#include <rime/resource.h>
#include <rime/service.h>

namespace fs = boost::filesystem;
namespace fs = std::filesystem;

namespace rime {

Expand Down Expand Up @@ -84,7 +84,7 @@ bool DictCompiler::Compile(const string& schema_file) {
bool build_table_from_source = true;
DictSettings settings;
auto dict_file = source_resolver_->ResolvePath(dict_name_ + ".dict.yaml");
if (!boost::filesystem::exists(dict_file)) {
if (!std::filesystem::exists(dict_file)) {
LOG(ERROR) << "source file '" << dict_file << "' does not exist.";
build_table_from_source = false;
} else if (!load_dict_settings_from_file(&settings, dict_file)) {
Expand Down
6 changes: 3 additions & 3 deletions src/rime/dict/dictionary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// 2011-07-05 GONG Chen <chen.sst@gmail.com>
//
#include <boost/filesystem.hpp>
#include <filesystem>
#include <rime/algo/syllabifier.h>
#include <rime/common.h>
#include <rime/dict/dictionary.h>
Expand Down Expand Up @@ -306,8 +306,8 @@ bool Dictionary::Decode(const Code& code, vector<string>* result) {
}

bool Dictionary::Exists() const {
return boost::filesystem::exists(prism_->file_name()) && !tables_.empty() &&
boost::filesystem::exists(tables_[0]->file_name());
return std::filesystem::exists(prism_->file_name()) && !tables_.empty() &&
std::filesystem::exists(tables_[0]->file_name());
}

bool Dictionary::Remove() {
Expand Down
2 changes: 1 addition & 1 deletion src/rime/dict/level_db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// 2014-12-04 Chen Gong <chen.sst@gmail.com>
//

#include <boost/filesystem.hpp>
#include <filesystem>
#include <leveldb/db.h>
#include <leveldb/write_batch.h>
#include <rime/common.h>
Expand Down
6 changes: 3 additions & 3 deletions src/rime/dict/mapped_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// 2011-06-30 GONG Chen <chen.sst@gmail.com>
//
#include <fstream>
#include <boost/filesystem.hpp>
#include <filesystem>
#include <boost/interprocess/file_mapping.hpp>
#include <boost/interprocess/mapped_region.hpp>
#include <rime/dict/mapped_file.h>
Expand Down Expand Up @@ -101,7 +101,7 @@ void MappedFile::Close() {
}

bool MappedFile::Exists() const {
return boost::filesystem::exists(file_name_);
return std::filesystem::exists(file_name_);
}

bool MappedFile::IsOpen() const {
Expand Down Expand Up @@ -130,7 +130,7 @@ bool MappedFile::Resize(size_t capacity) {
if (IsOpen())
Close();
try {
boost::filesystem::resize_file(file_name_.c_str(), capacity);
std::filesystem::resize_file(file_name_.c_str(), capacity);
} catch (...) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/rime/dict/preset_vocabulary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// 2011-11-27 GONG Chen <chen.sst@gmail.com>
//
#include <boost/filesystem.hpp>
#include <filesystem>
#include <boost/lexical_cast.hpp>
#include <utf8.h>
#include <rime/resource.h>
Expand Down
2 changes: 1 addition & 1 deletion src/rime/dict/reverse_lookup_dictionary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <cstdlib>
#include <sstream>
#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>
#include <filesystem>
#include <boost/lexical_cast.hpp>
#include <rime/resource.h>
#include <rime/schema.h>
Expand Down
Loading

0 comments on commit 8bf01e9

Please sign in to comment.