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
2 changes: 1 addition & 1 deletion .github/workflows/release-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: "1.21.x"
go-version: "1.24.x"

- name: Download dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-csharp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: "1.21.x"
go-version: "1.24.x"

- name: Download dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: "1.21.x"
go-version: "1.24.x"

- name: Download dependencies
run: |
Expand Down
22 changes: 19 additions & 3 deletions .github/workflows/testing-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
run_loader: .\bin\loader.exe

runs-on: ${{ matrix.os }}
timeout-minutes: 10
timeout-minutes: 20

steps:
- name: Checkout Code
Expand All @@ -36,7 +36,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v6
with:
go-version: 1.21.x
go-version: 1.24.x
cache: true

- name: Install dependencies (Ubuntu)
Expand All @@ -51,7 +51,23 @@ jobs:
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1

- name: Init submodules and build protobuf
- name: Init submodules
shell: bash
run: |
git submodule update --init --recursive
cd third_party/_submodules/protobuf
git checkout v32.0
git submodule update --init --recursive

- name: Cache protobuf build
id: cache-protobuf
uses: actions/cache@v4
with:
path: third_party/_submodules/protobuf/.build
key: protobuf-${{ runner.os }}-${{ hashFiles('.gitmodules', 'init.sh') }}

- name: Build protobuf
if: steps.cache-protobuf.outputs.cache-hit != 'true'
shell: bash
run: bash init.sh

Expand Down
26 changes: 10 additions & 16 deletions .github/workflows/testing-csharp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,31 @@ jobs:
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
submodules: recursive

- name: Install Go
uses: actions/setup-go@v6
with:
go-version: 1.21.x
go-version: 1.24.x
cache: true

- name: Install .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"

- name: Install dependencies (Ubuntu)
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y cmake ninja-build

- name: Install dependencies (Windows)
if: runner.os == 'Windows'
run: choco install cmake ninja -y

- name: Setup MSVC (Windows)
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1

- name: Init submodules and build protobuf
shell: bash
run: bash init.sh
- name: Install Protoc
uses: arduino/setup-protoc@v3
with:
version: "32.x"
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Generate protoconf
working-directory: test/csharp-tableau-loader
run: ${{ matrix.gen_script }}
env:
PROTOC: protoc

- name: Build
working-directory: test/csharp-tableau-loader
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/testing-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.21.x]
go-version: [1.24.x]
os: [ubuntu-latest, windows-latest]

runs-on: ${{ matrix.os }}
Expand All @@ -36,11 +36,11 @@ jobs:
- name: Install Protoc
uses: arduino/setup-protoc@v3
with:
version: "23.x"
version: "32.x"
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Install protoc-gen-go
run: go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.34.2
run: go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.36.9

- name: Generate protoconf
shell: bash
Expand Down
10 changes: 5 additions & 5 deletions cmd/protoc-gen-cpp-tableau-loader/embed/load.pc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ bool LoadMessager(google::protobuf::Message& msg, const std::filesystem::path& p
bool LoadMessagerInDir(google::protobuf::Message& msg, const std::filesystem::path& dir, Format fmt,
std::shared_ptr<const MessagerOptions> options /* = nullptr*/) {
options = options ? options : std::make_shared<MessagerOptions>();
const std::string& name = msg.GetDescriptor()->name();
const std::string name(msg.GetDescriptor()->name());
std::filesystem::path path;
if (!options->path.empty()) {
// path specified in Paths, then use it instead of dir.
Expand Down Expand Up @@ -79,7 +79,7 @@ bool LoadMessagerWithPatch(google::protobuf::Message& msg, const std::filesystem
// ignore patch files when LoadMode::kModeOnlyMain specified
return load_func(msg, path, fmt, nullptr);
}
const std::string& name = msg.GetDescriptor()->name();
const std::string name(msg.GetDescriptor()->name());
std::vector<std::filesystem::path> patch_paths;
if (!options->patch_paths.empty()) {
// patch path specified in PatchPaths, then use it instead of PatchDirs.
Expand Down Expand Up @@ -155,21 +155,21 @@ bool Unmarshal(const std::string& content, google::protobuf::Message& msg, Forma
parse_options.ignore_unknown_fields = options->GetIgnoreUnknownFields();
auto status = google::protobuf::util::JsonStringToMessage(content, &msg, parse_options);
if (!status.ok()) {
SetErrMsg("failed to parse " + msg.GetDescriptor()->name() + kJSONExt + ": " + status.ToString());
SetErrMsg("failed to parse " + std::string(msg.GetDescriptor()->name()) + kJSONExt + ": " + status.ToString());
return false;
}
return true;
}
case Format::kText: {
if (!google::protobuf::TextFormat::ParseFromString(content, &msg)) {
SetErrMsg("failed to parse " + msg.GetDescriptor()->name() + kTextExt);
SetErrMsg("failed to parse " + std::string(msg.GetDescriptor()->name()) + kTextExt);
return false;
}
return true;
}
case Format::kBin: {
if (!msg.ParseFromString(content)) {
SetErrMsg("failed to parse " + msg.GetDescriptor()->name() + kBinExt);
SetErrMsg("failed to parse " + std::string(msg.GetDescriptor()->name()) + kBinExt);
return false;
}
return true;
Expand Down
13 changes: 13 additions & 0 deletions cmd/protoc-gen-cpp-tableau-loader/embed/templates/hub.pc.cc.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ void Hub::InitScheduler() {
std::shared_ptr<MessagerMap> Hub::InternalLoad(const std::filesystem::path& dir, Format fmt /* = Format::kJSON */,
std::shared_ptr<const load::Options> options /* = nullptr */) const {
// intercept protobuf error logs
#if TABLEAU_PB_LOG_LEGACY
auto old_handler = google::protobuf::SetLogHandler(util::ProtobufLogHandler);
#else
util::ProtobufAbslLogSink log_sink;
absl::AddLogSink(&log_sink);
#endif
auto msger_map = NewMessagerMap();
options = options ? options : std::make_shared<load::Options>();
for (auto iter : *msger_map) {
Expand All @@ -65,14 +70,22 @@ std::shared_ptr<MessagerMap> Hub::InternalLoad(const std::filesystem::path& dir,
if (!ok) {
ATOM_ERROR("load %s failed: %s", name.c_str(), GetErrMsg().c_str());
// restore to old protobuf log handler
#if TABLEAU_PB_LOG_LEGACY
google::protobuf::SetLogHandler(old_handler);
#else
absl::RemoveLogSink(&log_sink);
#endif
return nullptr;
}
ATOM_DEBUG("loaded %s", name.c_str());
}

// restore to old protobuf log handler
#if TABLEAU_PB_LOG_LEGACY
google::protobuf::SetLogHandler(old_handler);
#else
absl::RemoveLogSink(&log_sink);
#endif
return msger_map;
}

Expand Down
51 changes: 42 additions & 9 deletions cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ bool PatchMessage(google::protobuf::Message& dst, const google::protobuf::Messag
// Ensure both messages are of the same type
if (dst_descriptor != src_descriptor) {
SetErrMsg("dst and src are not messages with the same descriptor");
ATOM_ERROR("dst %s and src %s are not messages with the same descriptor", dst_descriptor->name().c_str(),
src_descriptor->name().c_str());
ATOM_ERROR("dst %s and src %s are not messages with the same descriptor",
std::string(dst_descriptor->name()).c_str(), std::string(src_descriptor->name()).c_str());
return false;
}

Expand Down Expand Up @@ -206,18 +206,51 @@ bool PatchMessage(google::protobuf::Message& dst, const google::protobuf::Messag
return true;
}

// refer: https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/stubs/logging.h
#if TABLEAU_PB_LOG_LEGACY
// refer: https://github.com/protocolbuffers/protobuf/blob/v3.19.3/src/google/protobuf/stubs/logging.h
void ProtobufLogHandler(google::protobuf::LogLevel level, const char* filename, int line, const std::string& msg) {
static const std::unordered_map<int, log::Level> kLevelMap = {{google::protobuf::LOGLEVEL_INFO, log::kInfo},
{google::protobuf::LOGLEVEL_WARNING, log::kWarn},
{google::protobuf::LOGLEVEL_ERROR, log::kError},
{google::protobuf::LOGLEVEL_FATAL, log::kFatal}};
#define TABLEAU_PB_LOG_INFO google::protobuf::LOGLEVEL_INFO
#define TABLEAU_PB_LOG_WARNING google::protobuf::LOGLEVEL_WARNING
#define TABLEAU_PB_LOG_ERROR google::protobuf::LOGLEVEL_ERROR
#define TABLEAU_PB_LOG_FATAL google::protobuf::LOGLEVEL_FATAL
#define TABLEAU_PB_LOG_LEVEL level
#define TABLEAU_PB_LOG_FILENAME filename
#define TABLEAU_PB_LOG_LINE line
#define TABLEAU_PB_LOG_MESSAGE msg
#else
// refer: https://github.com/abseil/abseil-cpp/blob/20250512.1/absl/log/log_entry.h
void ProtobufAbslLogSink::Send(const absl::LogEntry& entry) {
#define TABLEAU_PB_LOG_INFO absl::LogSeverity::kInfo
#define TABLEAU_PB_LOG_WARNING absl::LogSeverity::kWarning
#define TABLEAU_PB_LOG_ERROR absl::LogSeverity::kError
#define TABLEAU_PB_LOG_FATAL absl::LogSeverity::kFatal
#define TABLEAU_PB_LOG_LEVEL entry.log_severity()
#define TABLEAU_PB_LOG_FILENAME std::string(entry.source_filename()).c_str()
#define TABLEAU_PB_LOG_LINE entry.source_line()
#define TABLEAU_PB_LOG_MESSAGE std::string(entry.text_message()).c_str()
#endif

static const std::unordered_map<decltype(TABLEAU_PB_LOG_LEVEL), log::Level> kLevelMap = {
{TABLEAU_PB_LOG_INFO, log::kInfo},
{TABLEAU_PB_LOG_WARNING, log::kWarn},
{TABLEAU_PB_LOG_ERROR, log::kError},
{TABLEAU_PB_LOG_FATAL, log::kFatal}};
log::Level lvl = log::kWarn; // default
auto iter = kLevelMap.find(level);
auto iter = kLevelMap.find(TABLEAU_PB_LOG_LEVEL);
if (iter != kLevelMap.end()) {
lvl = iter->second;
}
ATOM_LOGGER_CALL(tableau::log::DefaultLogger(), lvl, "[libprotobuf %s:%d] %s", filename, line, msg.c_str());
ATOM_LOGGER_CALL(tableau::log::DefaultLogger(), lvl, "[libprotobuf %s:%d] %s", TABLEAU_PB_LOG_FILENAME,
TABLEAU_PB_LOG_LINE, TABLEAU_PB_LOG_MESSAGE);

#undef TABLEAU_PB_LOG_INFO
#undef TABLEAU_PB_LOG_WARNING
#undef TABLEAU_PB_LOG_ERROR
#undef TABLEAU_PB_LOG_FATAL
#undef TABLEAU_PB_LOG_LEVEL
#undef TABLEAU_PB_LOG_FILENAME
#undef TABLEAU_PB_LOG_LINE
#undef TABLEAU_PB_LOG_MESSAGE
}
} // namespace util
} // namespace tableau
22 changes: 22 additions & 0 deletions cmd/protoc-gen-cpp-tableau-loader/embed/util.pc.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
#pragma once
#include <google/protobuf/message.h>
#include <google/protobuf/stubs/common.h>

#include <chrono>
#include <filesystem>
#include <string>

// Protobuf versions before v4.22.0 (GOOGLE_PROTOBUF_VERSION < 4022000) use the legacy
// logging interface (LogLevel, SetLogHandler). Newer versions removed it in favor of Abseil logging.
#define TABLEAU_PB_LOG_LEGACY (GOOGLE_PROTOBUF_VERSION < 4022000)

#if !TABLEAU_PB_LOG_LEGACY
#include <absl/log/log_entry.h>
#include <absl/log/log_sink.h>
#include <absl/log/log_sink_registry.h>
#endif

namespace tableau {
const std::string& GetErrMsg();
void SetErrMsg(const std::string& msg);
Expand Down Expand Up @@ -57,7 +68,18 @@ const std::string& Format2Ext(Format fmt);
// PatchMessage patches src into dst, which must be a message with the same descriptor.
bool PatchMessage(google::protobuf::Message& dst, const google::protobuf::Message& src);

#if TABLEAU_PB_LOG_LEGACY
// ProtobufLogHandler redirects protobuf internal logs to tableau logger.
// Only available for protobuf < v4.22.0, as newer versions removed the old logging interface.
void ProtobufLogHandler(google::protobuf::LogLevel level, const char* filename, int line, const std::string& msg);
#else
// ProtobufAbslLogSink redirects protobuf/Abseil logs to tableau logger.
// For protobuf >= v4.22.0, which uses Abseil logging (absl::LogSink).
class ProtobufAbslLogSink : public absl::LogSink {
public:
void Send(const absl::LogEntry& entry) override;
};
#endif

class TimeProfiler {
protected:
Expand Down
5 changes: 4 additions & 1 deletion cmd/protoc-gen-cpp-tableau-loader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/tableauio/loader/internal/options"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/types/descriptorpb"
"google.golang.org/protobuf/types/pluginpb"
)

Expand Down Expand Up @@ -50,7 +51,9 @@ func main() {
protogen.Options{
ParamFunc: flags.Set,
}.Run(func(gen *protogen.Plugin) error {
gen.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
gen.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL | pluginpb.CodeGeneratorResponse_FEATURE_SUPPORTS_EDITIONS)
gen.SupportedEditionsMinimum = descriptorpb.Edition_EDITION_PROTO3
gen.SupportedEditionsMaximum = descriptorpb.Edition_EDITION_2024
for _, f := range gen.Files {
if !options.NeedGenFile(f) {
continue
Expand Down
2 changes: 1 addition & 1 deletion cmd/protoc-gen-cpp-tableau-loader/messager.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func genCppMessage(g *protogen.GeneratedFile, message *protogen.Message) {
orderedMapGenerator := orderedmap.NewGenerator(g, message)
indexGenerator := indexes.NewGenerator(g, indexDescriptor, message)

g.P("const std::string ", messagerName, "::kProtoName = ", cppFullName, `::GetDescriptor()->name();`)
g.P("const std::string ", messagerName, "::kProtoName = std::string(", cppFullName, `::GetDescriptor()->name());`)
g.P()
g.P("bool ", messagerName, "::Load(const std::filesystem::path& dir, Format fmt, std::shared_ptr<const load::MessagerOptions> options /* = nullptr */) {")
g.P(helper.Indent(1), "tableau::util::TimeProfiler profiler;")
Expand Down
5 changes: 4 additions & 1 deletion cmd/protoc-gen-csharp-tableau-loader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/tableauio/loader/internal/options"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/types/descriptorpb"
"google.golang.org/protobuf/types/pluginpb"
)

Expand All @@ -24,7 +25,9 @@ func main() {
protogen.Options{
ParamFunc: flags.Set,
}.Run(func(gen *protogen.Plugin) error {
gen.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
gen.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL | pluginpb.CodeGeneratorResponse_FEATURE_SUPPORTS_EDITIONS)
gen.SupportedEditionsMinimum = descriptorpb.Edition_EDITION_PROTO3
gen.SupportedEditionsMaximum = descriptorpb.Edition_EDITION_2024
for _, f := range gen.Files {
if !options.NeedGenFile(f) {
continue
Expand Down
5 changes: 4 additions & 1 deletion cmd/protoc-gen-go-tableau-loader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/tableauio/loader/internal/options"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/types/descriptorpb"
"google.golang.org/protobuf/types/pluginpb"
)

Expand All @@ -27,7 +28,9 @@ func main() {
protogen.Options{
ParamFunc: flags.Set,
}.Run(func(gen *protogen.Plugin) error {
gen.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
gen.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL | pluginpb.CodeGeneratorResponse_FEATURE_SUPPORTS_EDITIONS)
gen.SupportedEditionsMinimum = descriptorpb.Edition_EDITION_PROTO3
gen.SupportedEditionsMaximum = descriptorpb.Edition_EDITION_2024
for _, f := range gen.Files {
if !options.NeedGenFile(f) {
continue
Expand Down
Loading
Loading