Skip to content

Commit 8fe7b93

Browse files
authored
Add Bazel build support
Add Bzlmod metadata and Bazel targets for cppjieba, limonp headers, and dictionary files. Add a Bazel smoke test plus a GitHub Actions workflow to keep the Bazel build path covered. CI: Bazel run 25088951349 passed; CMake run 25088951297 passed; CMake Windows ARM64 run 25088951295 passed. Closes #233
1 parent 5caef15 commit 8fe7b93

4 files changed

Lines changed: 90 additions & 0 deletions

File tree

.github/workflows/bazel.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Bazel
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Check out repository code
13+
uses: actions/checkout@v6
14+
with:
15+
submodules: recursive
16+
17+
- name: Test
18+
run: npx --yes @bazel/bazelisk test //:bazel_smoke_test

BUILD.bazel

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
cc_library(
6+
name = "limonp",
7+
hdrs = glob(["deps/limonp/include/limonp/**/*.hpp"]),
8+
includes = ["deps/limonp/include"],
9+
)
10+
11+
filegroup(
12+
name = "dict",
13+
srcs = glob(["dict/**"]),
14+
)
15+
16+
cc_library(
17+
name = "cppjieba",
18+
hdrs = glob(["include/cppjieba/**/*.hpp"]),
19+
includes = ["include"],
20+
deps = [":limonp"],
21+
)
22+
23+
cc_test(
24+
name = "bazel_smoke_test",
25+
srcs = ["test/bazel_smoke_test.cpp"],
26+
data = [":dict"],
27+
deps = [":cppjieba"],
28+
)

MODULE.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module(
2+
name = "cppjieba",
3+
version = "5.6.7",
4+
)
5+
6+
bazel_dep(name = "rules_cc", version = "0.2.17")

test/bazel_smoke_test.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "cppjieba/Jieba.hpp"
2+
3+
#include <cstdlib>
4+
#include <iostream>
5+
#include <string>
6+
#include <vector>
7+
8+
namespace {
9+
10+
std::string RunfilePath(const std::string& relative_path) {
11+
const char* test_srcdir = std::getenv("TEST_SRCDIR");
12+
const char* test_workspace = std::getenv("TEST_WORKSPACE");
13+
if (test_srcdir == NULL || test_workspace == NULL) {
14+
return relative_path;
15+
}
16+
17+
return std::string(test_srcdir) + "/" + test_workspace + "/" + relative_path;
18+
}
19+
20+
} // namespace
21+
22+
int main() {
23+
cppjieba::Jieba jieba(
24+
RunfilePath("dict/jieba.dict.utf8"),
25+
RunfilePath("dict/hmm_model.utf8"),
26+
RunfilePath("dict/user.dict.utf8"),
27+
RunfilePath("dict/idf.utf8"),
28+
RunfilePath("dict/stop_words.utf8"));
29+
30+
std::vector<std::string> words;
31+
jieba.Cut("南京市长江大桥", words);
32+
if (words.empty()) {
33+
std::cerr << "Expected cppjieba to segment the smoke-test sentence.\n";
34+
return 1;
35+
}
36+
37+
return 0;
38+
}

0 commit comments

Comments
 (0)