Skip to content

Commit

Permalink
0.9.6: reproducible and shrink size
Browse files Browse the repository at this point in the history
- use __FILE_NAME__ supported by clang/gcc
- disallow boost/json to embed header path in rime.wasm
- disable DartsDict for OpenCC
  • Loading branch information
eagleoflqj committed Aug 19, 2023
1 parent 45be9ea commit 0e9bc40
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
- uses: actions/checkout@v3
- name: Install Ubuntu dependencies
if: ${{ inputs.os == 'ubuntu-latest' }}
# no need to use clang if gcc 12 becomes default
run: |
sudo apt install -y ninja-build \
clang-format \
Expand All @@ -25,6 +26,8 @@ jobs:
libleveldb-dev \
libmarisa-dev \
libopencc-dev
echo "CC=/usr/bin/clang" >> $GITHUB_ENV
echo "CXX=/usr/bin/clang++" >> $GITHUB_ENV
- name: Install macOS dependencies
if: ${{ inputs.os == 'macos-latest' }}
run: |
Expand Down
4 changes: 2 additions & 2 deletions checksum
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
1af97e7578a6b23af1aff33269acf462 public/rime.data
f660ee6b263d37d82ed988b39dfb9c40 public/rime.js
d528ca745a0e8610defde57beb12718b public/rime.wasm
1cbf63bda92830c1aa9fcaf1adf50ca4 public/rime.js
72f6dc1b0987f071b7c97cc68c04f818 public/rime.wasm
61 changes: 61 additions & 0 deletions glog_patch
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,64 @@ index f5c1e55..c181509 100644
cmake_dependent_option (WITH_GMOCK "Use Google Mock" ON WITH_GTEST OFF)

set (WITH_FUZZING none CACHE STRING "Fuzzing engine")
diff --git a/src/glog/logging.h.in b/src/glog/logging.h.in
index 26fd371..504237a 100644
--- a/src/glog/logging.h.in
+++ b/src/glog/logging.h.in
@@ -479,9 +479,9 @@ DECLARE_bool(log_utc_time);

#if GOOGLE_STRIP_LOG == 0
#define COMPACT_GOOGLE_LOG_INFO @ac_google_namespace@::LogMessage( \
- __FILE__, __LINE__)
+ __FILE_NAME__, __LINE__)
#define LOG_TO_STRING_INFO(message) @ac_google_namespace@::LogMessage( \
- __FILE__, __LINE__, @ac_google_namespace@::GLOG_INFO, message)
+ __FILE_NAME__, __LINE__, @ac_google_namespace@::GLOG_INFO, message)
#else
#define COMPACT_GOOGLE_LOG_INFO @ac_google_namespace@::NullStream()
#define LOG_TO_STRING_INFO(message) @ac_google_namespace@::NullStream()
@@ -489,9 +489,9 @@ DECLARE_bool(log_utc_time);

#if GOOGLE_STRIP_LOG <= 1
#define COMPACT_GOOGLE_LOG_WARNING @ac_google_namespace@::LogMessage( \
- __FILE__, __LINE__, @ac_google_namespace@::GLOG_WARNING)
+ __FILE_NAME__, __LINE__, @ac_google_namespace@::GLOG_WARNING)
#define LOG_TO_STRING_WARNING(message) @ac_google_namespace@::LogMessage( \
- __FILE__, __LINE__, @ac_google_namespace@::GLOG_WARNING, message)
+ __FILE_NAME__, __LINE__, @ac_google_namespace@::GLOG_WARNING, message)
#else
#define COMPACT_GOOGLE_LOG_WARNING @ac_google_namespace@::NullStream()
#define LOG_TO_STRING_WARNING(message) @ac_google_namespace@::NullStream()
@@ -499,9 +499,9 @@ DECLARE_bool(log_utc_time);

#if GOOGLE_STRIP_LOG <= 2
#define COMPACT_GOOGLE_LOG_ERROR @ac_google_namespace@::LogMessage( \
- __FILE__, __LINE__, @ac_google_namespace@::GLOG_ERROR)
+ __FILE_NAME__, __LINE__, @ac_google_namespace@::GLOG_ERROR)
#define LOG_TO_STRING_ERROR(message) @ac_google_namespace@::LogMessage( \
- __FILE__, __LINE__, @ac_google_namespace@::GLOG_ERROR, message)
+ __FILE_NAME__, __LINE__, @ac_google_namespace@::GLOG_ERROR, message)
#else
#define COMPACT_GOOGLE_LOG_ERROR @ac_google_namespace@::NullStream()
#define LOG_TO_STRING_ERROR(message) @ac_google_namespace@::NullStream()
@@ -509,9 +509,9 @@ DECLARE_bool(log_utc_time);

#if GOOGLE_STRIP_LOG <= 3
#define COMPACT_GOOGLE_LOG_FATAL @ac_google_namespace@::LogMessageFatal( \
- __FILE__, __LINE__)
+ __FILE_NAME__, __LINE__)
#define LOG_TO_STRING_FATAL(message) @ac_google_namespace@::LogMessage( \
- __FILE__, __LINE__, @ac_google_namespace@::GLOG_FATAL, message)
+ __FILE_NAME__, __LINE__, @ac_google_namespace@::GLOG_FATAL, message)
#else
#define COMPACT_GOOGLE_LOG_FATAL @ac_google_namespace@::NullStreamFatal()
#define LOG_TO_STRING_FATAL(message) @ac_google_namespace@::NullStreamFatal()
@@ -529,7 +529,7 @@ DECLARE_bool(log_utc_time);
#define COMPACT_GOOGLE_LOG_DFATAL COMPACT_GOOGLE_LOG_ERROR
#elif GOOGLE_STRIP_LOG <= 3
#define COMPACT_GOOGLE_LOG_DFATAL @ac_google_namespace@::LogMessage( \
- __FILE__, __LINE__, @ac_google_namespace@::GLOG_FATAL)
+ __FILE_NAME__, __LINE__, @ac_google_namespace@::GLOG_FATAL)
#else
#define COMPACT_GOOGLE_LOG_DFATAL @ac_google_namespace@::NullStreamFatal()
#endif
2 changes: 1 addition & 1 deletion librime
39 changes: 19 additions & 20 deletions librime_patch
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5262f168..bd6c9bbe 100644
index 5262f16..9c5bb5b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,6 +46,9 @@ if (ENABLE_ASAN)
set(CMAKE_SHARED_LINKER_FLAGS "${asan_lflags} ${CMAKE_SHARED_LINKER_FLAGS}")
endif()

+# Reproducible build
+set(CMAKE_CXX_FLAGS "-ffile-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=. -DBOOST_DISABLE_CURRENT_LOCATION ${CMAKE_CXX_FLAGS}")
+set(CMAKE_CXX_FLAGS "-DBOOST_DISABLE_CURRENT_LOCATION ${CMAKE_CXX_FLAGS}")
+
set(Boost_USE_STATIC_LIBS ${BUILD_STATIC})
set(Gflags_STATIC ${BUILD_STATIC})
set(Glog_STATIC ${BUILD_STATIC})
diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt
index a20440b3..515965f4 100644
--- a/deps/CMakeLists.txt
+++ b/deps/CMakeLists.txt
@@ -8,6 +8,9 @@ cmake_minimum_required(VERSION 3.10)
# libmarisa don't have cmake based build, but it is relatively small,
# so we define library target here
diff --git a/include/darts.h b/include/darts.h
index 18bf988..4b9bb5d 100644
--- a/include/darts.h
+++ b/include/darts.h
@@ -16,7 +16,7 @@
#define DARTS_LINE_TO_STR(line) DARTS_INT_TO_STR(line)
#define DARTS_LINE_STR DARTS_LINE_TO_STR(__LINE__)
#define DARTS_THROW(msg) throw Darts::Details::Exception( \
- __FILE__ ":" DARTS_LINE_STR ": exception: " msg)
+ __FILE_NAME__ ":" DARTS_LINE_STR ": exception: " msg)

namespace Darts {

+# Reproducible build
+add_definitions(-ffile-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=.)
+
if(UNIX)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Weffc++ -Wextra -Wconversion")
endif()
diff --git a/src/rime/config/build_info_plugin.cc b/src/rime/config/build_info_plugin.cc
index a60b6b56..eb521bb4 100644
index a60b6b5..eb521bb 100644
--- a/src/rime/config/build_info_plugin.cc
+++ b/src/rime/config/build_info_plugin.cc
@@ -19,6 +19,7 @@ bool BuildInfoPlugin::ReviewLinkOutput(ConfigCompiler* compiler,
Expand All @@ -39,7 +38,7 @@ index a60b6b56..eb521bb4 100644
compiler->EnumerateResources([&](an<ConfigResource> resource) {
if (!resource->loaded) {
diff --git a/src/rime/deployer.cc b/src/rime/deployer.cc
index 2b2169ca..19ac1097 100644
index 2b2169c..19ac109 100644
--- a/src/rime/deployer.cc
+++ b/src/rime/deployer.cc
@@ -5,6 +5,7 @@
Expand Down Expand Up @@ -67,7 +66,7 @@ index 2b2169ca..19ac1097 100644
}
LOG(INFO) << success + failure << " tasks ran: " << success << " success, "
diff --git a/src/rime/schema.cc b/src/rime/schema.cc
index 3026dda9..f29629f8 100644
index 3026dda..f29629f 100644
--- a/src/rime/schema.cc
+++ b/src/rime/schema.cc
@@ -4,9 +4,17 @@
Expand Down Expand Up @@ -103,7 +102,7 @@ index 3026dda9..f29629f8 100644
}
config_->GetInt("menu/page_size", &page_size_);
diff --git a/src/rime/schema.h b/src/rime/schema.h
index bb68bcdb..4ef84beb 100644
index bb68bcd..4ef84be 100644
--- a/src/rime/schema.h
+++ b/src/rime/schema.h
@@ -10,6 +10,12 @@
Expand Down Expand Up @@ -135,7 +134,7 @@ index bb68bcdb..4ef84beb 100644
const string& select_keys() const { return select_keys_; }
void set_select_keys(const string& keys) { select_keys_ = keys; }
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
index 18e3407f..b79a0c16 100644
index 18e3407..b79a0c1 100644
--- a/tools/CMakeLists.txt
+++ b/tools/CMakeLists.txt
@@ -44,18 +44,3 @@ install(TARGETS rime_dict_manager DESTINATION ${BIN_INSTALL_DIR})
Expand Down
15 changes: 15 additions & 0 deletions marisa_patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/include/marisa/exception.h b/include/marisa/exception.h
index 508c6b8..7f17c0a 100644
--- a/include/marisa/exception.h
+++ b/include/marisa/exception.h
@@ -62,8 +62,8 @@ class Exception : public std::exception {
// code and an error message. The message format is as follows:
// "__FILE__:__LINE__: error_code: error_message"
#define MARISA_THROW(error_code, error_message) \
- (throw marisa::Exception(__FILE__, __LINE__, error_code, \
- __FILE__ ":" MARISA_LINE_STR ": " #error_code ": " error_message))
+ (throw marisa::Exception(__FILE_NAME__, __LINE__, error_code, \
+ __FILE_NAME__ ":" MARISA_LINE_STR ": " #error_code ": " error_message))

// MARISA_THROW_IF throws an exception if `condition' is true.
#define MARISA_THROW_IF(condition, error_code) \
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@libreservice/my-rime",
"version": "0.9.5",
"version": "0.9.6",
"files": [
"dist"
],
Expand Down
2 changes: 2 additions & 0 deletions scripts/build_lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ function buildMarisaTrie () {
console.log('Building marisa-trie')
const src = 'librime/deps'
const dst = 'build/marisa-trie'
patch(`${src}/marisa-trie`, 'marisa_patch')
rmSync(dst, rf)
ensure(spawnSync('emcmake', [
'cmake', src,
Expand All @@ -126,6 +127,7 @@ function buildOpenCC () {
'-G', 'Ninja',
...CMAKE_DEF,
`-DCMAKE_FIND_ROOT_PATH:PATH=${CMAKE_FIND_ROOT_PATH}`,
'-DENABLE_DARTS:BOOL=OFF',
'-DUSE_SYSTEM_MARISA:BOOL=ON'
], spawnArg))
ensure(spawnSync('cmake', ['--build', dst], spawnArg))
Expand Down
2 changes: 2 additions & 0 deletions scripts/build_native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ function buildLevelDB () {

function buildMarisaTrie () {
console.log('Building marisa-trie')
patch('librime/deps/marisa-trie', 'marisa_patch')
chdir('librime/deps')
rmSync(dst, rf)
ensure(spawnSync('cmake', [
Expand All @@ -108,6 +109,7 @@ function buildOpenCC () {
'-G', 'Ninja',
...CMAKE_DEF,
`-DCMAKE_FIND_ROOT_PATH:PATH=${CMAKE_INSTALL_PREFIX}`,
'-DENABLE_DARTS:BOOL=OFF',
'-DUSE_SYSTEM_MARISA:BOOL=ON'
], spawnArg))
ensure(spawnSync('cmake', ['--build', dst], spawnArg))
Expand Down
8 changes: 7 additions & 1 deletion scripts/build_wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ const exportedFunctions = [

const compileArgs = [
'-std=c++14',
process.env.BUILD_TYPE === 'Debug' ? '-g' : '-O2',
...(process.env.BUILD_TYPE === 'Debug'
? ['-g']
: [
'-O2',
'-DBOOST_DISABLE_ASSERTS',
'-DBOOST_DISABLE_CURRENT_LOCATION'
]),
'-s', 'ALLOW_MEMORY_GROWTH=1',
'-s', 'MAXIMUM_MEMORY=4GB',
'-s', `EXPORTED_FUNCTIONS=${exportedFunctions.map(name => '_' + name).join(',')}`,
Expand Down

0 comments on commit 0e9bc40

Please sign in to comment.