Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4b0e1f3..7455519 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -13,7 +13,11 @@
# limitations under the License.!

list(APPEND SPM_LIBS absl::status)
-list(APPEND SPM_LIBS absl::status_builder)
+# absl::status_builder only exists in abseil-cpp >= 20260526.0; with older
+# versions src/absl_status_compat.h provides the subset this project uses.
+if (TARGET absl::status_builder)
+ list(APPEND SPM_LIBS absl::status_builder)
+endif()
list(APPEND SPM_LIBS absl::strings)
list(APPEND SPM_LIBS absl::flags)
list(APPEND SPM_LIBS absl::flags_parse)
diff --git a/src/absl_status_compat.h b/src/absl_status_compat.h
new file mode 100644
index 0000000..16c41a9
--- /dev/null
+++ b/src/absl_status_compat.h
@@ -0,0 +1,66 @@
+// Copyright 2026 Google LLC.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.!
+
+#ifndef ABSL_STATUS_COMPAT_H_
+#define ABSL_STATUS_COMPAT_H_
+
+// absl::StatusBuilder and ABSL_RETURN_IF_ERROR only exist in abseil-cpp
+// >= 20260526.0, while emscripten-forge 4x ships 20260107.1. Provide the
+// minimal subset used by this project so it builds against either version.
+
+#include <sstream>
+#include <utility>
+
+#include "third_party/absl/status/status.h"
+
+// abseil-cpp >= 20260526.0 ships the real implementation; use it there.
+// third_party/absl is symlinked to the installed abseil by CMakeLists.txt.
+#if __has_include("third_party/absl/status/status_macros.h")
+#include "third_party/absl/status/status_macros.h"
+#else
+
+namespace absl {
+ABSL_NAMESPACE_BEGIN
+
+class StatusBuilder {
+ public:
+ explicit StatusBuilder(StatusCode code) : code_(code) {}
+
+ template <typename T>
+ StatusBuilder &operator<<(const T &value) {
+ os_ << value;
+ return *this;
+ }
+
+ operator Status() const { return Status(code_, os_.str()); }
+
+ private:
+ StatusCode code_;
+ std::ostringstream os_;
+};
+
+ABSL_NAMESPACE_END
+} // namespace absl
+
+#ifndef ABSL_RETURN_IF_ERROR
+#define ABSL_RETURN_IF_ERROR(expr) \
+ do { \
+ const ::absl::Status _status = (expr); \
+ if (!_status.ok()) return _status; \
+ } while (0)
+#endif
+
+#endif // __has_include("third_party/absl/status/status_macros.h")
+
+#endif // ABSL_STATUS_COMPAT_H_
diff --git a/src/common.h b/src/common.h
index ba82860..49a2fbf 100644
--- a/src/common.h
+++ b/src/common.h
@@ -22,7 +22,7 @@
#include "third_party/absl/log/globals.h"
#include "third_party/absl/log/log.h"
#include "third_party/absl/status/status.h"
-#include "third_party/absl/status/status_macros.h"
+#include "absl_status_compat.h"
#include "third_party/absl/strings/string_view.h"

#if defined(_WIN32) && !defined(__CYGWIN__)
diff --git a/src/spec_parser.h b/src/spec_parser.h
index 41fb573..a96a08c 100644
--- a/src/spec_parser.h
+++ b/src/spec_parser.h
@@ -20,7 +20,7 @@

#include "sentencepiece_processor.h"
#include "third_party/absl/status/status.h"
-#include "third_party/absl/status/status_builder.h"
+#include "absl_status_compat.h"
#include "third_party/absl/strings/ascii.h"
#include "third_party/absl/strings/numbers.h"
#include "third_party/absl/strings/str_split.h"
diff --git a/src/util.h b/src/util.h
index 07d9f37..a6830ba 100644
--- a/src/util.h
+++ b/src/util.h
@@ -38,7 +38,7 @@
#include "third_party/absl/numeric/bits.h"
#include "third_party/absl/random/random.h"
#include "third_party/absl/status/status.h"
-#include "third_party/absl/status/status_builder.h"
+#include "absl_status_compat.h"
#include "third_party/absl/strings/ascii.h"
#include "third_party/absl/strings/numbers.h"
#include "third_party/absl/strings/str_cat.h"
10 changes: 6 additions & 4 deletions recipes/recipes_emscripten/sentencepiece/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@ emcmake cmake -GNinja \
..

# Build only the static library (CLI tools fail to link due to duplicate
# abseil symbols between internal protobuf-lite and system libabseil)
ninja sentencepiece-static
# abseil symbols between internal protobuf-lite and system libabseil).
# generate_installed_headers rewrites the "third_party/absl/..." includes in
# the public headers to "<absl/...>" for installation.
ninja sentencepiece-static generate_installed_headers

# Install library and headers manually
mkdir -p "${PREFIX}/lib"
mkdir -p "${PREFIX}/include"
cp src/libsentencepiece.a "${PREFIX}/lib/"
cp ../src/sentencepiece_processor.h "${PREFIX}/include/"
cp ../src/sentencepiece_trainer.h "${PREFIX}/include/"
cp src/installed_headers/sentencepiece_processor.h "${PREFIX}/include/"
cp src/installed_headers/sentencepiece_trainer.h "${PREFIX}/include/"

# Remove .la files if any
find "${PREFIX}" -name '*.la' -delete 2>/dev/null || true
Expand Down
11 changes: 8 additions & 3 deletions recipes/recipes_emscripten/sentencepiece/recipe.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
context:
name: sentencepiece
version: 0.2.1
version: 0.2.2

package:
name: ${{ name }}
version: ${{ version }}

source:
url: https://github.com/google/sentencepiece/archive/refs/tags/v${{ version }}.tar.gz
sha256: c1a59e9259c9653ad0ade653dadff074cd31f0a6ff2a11316f67bee4189a8f1b
sha256: 92381f713e094a15a1ccff1ac4a5315a4c4b82a99ac1332d6ac53c9dc8e1bcf1
# 0.2.2 uses absl::StatusBuilder / status_macros.h, which only exist in
# abseil-cpp >= 20260526.0; 4x still ships 20260107.1.
patches:
- absl-status-builder-compat.patch

build:
number: 1
number: 0
script: build.sh

requirements:
Expand Down Expand Up @@ -66,5 +70,6 @@ about:
repository: https://github.com/google/sentencepiece

extra:
skip-auto-updates: true
recipe-maintainers:
- Alex-PLACET
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ if(NOT TARGET sentencepiece::sentencepiece)
set_target_properties(sentencepiece::sentencepiece PROPERTIES
IMPORTED_LOCATION "${CMAKE_CURRENT_LIST_DIR}/../../libsentencepiece.a"
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_LIST_DIR}/../../../include"
INTERFACE_LINK_LIBRARIES "absl::base;absl::flags;absl::flags_parse;absl::flat_hash_map;absl::flat_hash_set;absl::log;absl::random_random;absl::status;absl::statusor;absl::str_format;absl::strings;protobuf::libprotobuf"
INTERFACE_LINK_LIBRARIES "absl::base;absl::check;absl::flags;absl::flags_parse;absl::flat_hash_map;absl::flat_hash_set;absl::log;absl::log_initialize;absl::random_random;absl::status;absl::statusor;absl::str_format;absl::strings;absl::time;protobuf::libprotobuf"
)
endif()
Loading