Skip to content

Commit 90123e9

Browse files
tidefieldcopybara-github
authored andcommitted
Add CMake build config
PiperOrigin-RevId: 923291564
1 parent 7743a6f commit 90123e9

14 files changed

Lines changed: 255 additions & 90 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
binding: [pixel_bridge, deflate, saphyr, serde_json]
15+
binding: [pixel_bridge, deflate, saphyr, serde_json, zip]
1616
steps:
1717
- name: Checkout code
1818
uses: actions/checkout@v4
1919

2020
- name: Set up Rust
2121
uses: actions-rust-lang/setup-rust-toolchain@v1
2222
with:
23+
toolchain: nightly-2026-05-19
2324
# NOTE: b/514328084 - Crubit generates some code that causes unused-imports warnings. By
2425
# default rustflags is "-D warnings" causing the build to fail.
2526
rustflags: ""

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ C++ wrappers (using Crubit) for Rust libraries.
1010
| pixel_bridge | [image](https://crates.io/crates/image) | Compiles |
1111
| saphyr | [saphyr](https://crates.io/crates/saphyr) | Compiles |
1212
| serde_json | [serde_json](https://crates.io/crates/serde_json) | Compiles |
13+
| zip | [zip](https://crates.io/crates/zip) | Compiles |
1314

1415
## Contributing
1516

zip/CMakeLists.txt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
cmake_minimum_required(VERSION 3.22)
2+
3+
set(CMAKE_CXX_STANDARD 20)
4+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
5+
set(CMAKE_C_COMPILER clang)
6+
set(CMAKE_CXX_COMPILER clang++)
7+
8+
project(zip
9+
VERSION 0.1.0
10+
LANGUAGES CXX)
11+
12+
include(FetchContent)
13+
14+
FetchContent_Declare(
15+
Corrosion
16+
# NOTE: Replace with https://github.com/corrosion-rs/corrosion once
17+
# http://github.com/corrosion-rs/corrosion/pull/666 is merged.
18+
GIT_REPOSITORY https://github.com/thunderseethe/corrosion
19+
GIT_TAG master
20+
)
21+
22+
FetchContent_MakeAvailable(Corrosion)
23+
24+
corrosion_experimental_crubit(rust)
25+
corrosion_import_crate(MANIFEST_PATH rust/Cargo.toml)
26+
27+
FetchContent_Declare(
28+
absl
29+
GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git
30+
FIND_PACKAGE_ARGS NAMES absl
31+
)
32+
FetchContent_MakeAvailable(absl)
33+
34+
add_library(zip_converters converters.cc converters.h)
35+
target_link_libraries(zip_converters PRIVATE rust absl::status absl::statusor absl::strings absl::span)
36+
37+
# Include the root directory for crubit_helpers/string_conversions.h
38+
target_include_directories(zip_converters PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/..)
39+
40+
add_library(zip_file file.cc file.h)
41+
target_link_libraries(zip_file PRIVATE zip_converters rust absl::status absl::status_macros absl::statusor)
42+
43+
add_library(zip_read read.cc read.h)
44+
target_link_libraries(zip_read PRIVATE zip_converters zip_file rust absl::status_macros absl::statusor absl::strings absl::span)
45+
46+
add_library(zip_write write.cc write.h)
47+
target_link_libraries(zip_write PRIVATE zip_converters zip_file rust absl::status absl::status_macros absl::statusor absl::strings absl::span)
48+
49+
add_executable(zip_example main.cc)
50+
target_link_libraries(zip_example PRIVATE rust zip_converters zip_file zip_read zip_write absl::statusor absl::strings)

zip/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Zip
2+
3+
Wrapper for the [zip](https://crates.io/crates/zip) crate.
4+
5+
## Usage
6+
7+
Requires installation of clang and a nightly version of Rust.
8+
9+
```
10+
rustup default nightly-2026-05-19
11+
rustup component add rust-src rustc-dev llvm-tools-preview
12+
13+
cd zip
14+
cmake -B build
15+
cmake --build build --parallel
16+
17+
build/zip_example
18+
```

zip/converters.cc

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <utility>
66

77
#include "crubit_helpers/string_conversions.h"
8-
#include "rust/zip_wrapper.h"
8+
#include "crubit/rust.h"
99
#include "absl/status/status.h"
1010
#include "absl/status/statusor.h"
1111
#include "absl/strings/match.h"
@@ -25,7 +25,7 @@ enum class RustCallSite {
2525
kResultUnit,
2626
};
2727

28-
std::string FromRustVecU8(const zip_wrapper::VecU8& vec) {
28+
std::string FromRustVecU8(const rust::VecU8& vec) {
2929
return std::string(security::crubit_helpers::StringViewFromVecU8(vec));
3030
}
3131

@@ -73,7 +73,7 @@ absl::Status RustErrorToStatus(std::string err_str, RustCallSite call_site) {
7373
} // namespace
7474

7575
absl::StatusOr<RustVecU8Wrapper> FromRustResultVecU8(
76-
rs_std::Result<zip_wrapper::VecU8, zip_wrapper::VecU8> result_vec_u8) {
76+
rs_std::Result<rust::VecU8, rust::VecU8> result_vec_u8) {
7777
if (!result_vec_u8.has_value()) {
7878
return RustErrorToStatus(FromRustVecU8(std::move(result_vec_u8).err()),
7979
RustCallSite::kResultVecU8);
@@ -82,16 +82,16 @@ absl::StatusOr<RustVecU8Wrapper> FromRustResultVecU8(
8282
}
8383

8484
absl::Status FromRustResultUnit(
85-
rs_std::Result<uint8_t, zip_wrapper::VecU8> result_unit) {
85+
rs_std::Result<uint8_t, rust::VecU8> result_unit) {
8686
if (!result_unit.has_value()) {
8787
return RustErrorToStatus(FromRustVecU8(std::move(result_unit).err()),
8888
RustCallSite::kResultUnit);
8989
}
9090
return absl::OkStatus();
9191
}
9292

93-
absl::StatusOr<zip_wrapper::BufferedZipArchive> FromRustBufferedZipArchive(
94-
rs_std::Result<zip_wrapper::BufferedZipArchive, zip_wrapper::VecU8>
93+
absl::StatusOr<rust::BufferedZipArchive> FromRustBufferedZipArchive(
94+
rs_std::Result<rust::BufferedZipArchive, rust::VecU8>
9595
result_buffered_zip_archive) {
9696
if (!result_buffered_zip_archive.has_value()) {
9797
return RustErrorToStatus(
@@ -101,8 +101,8 @@ absl::StatusOr<zip_wrapper::BufferedZipArchive> FromRustBufferedZipArchive(
101101
return std::move(result_buffered_zip_archive).value();
102102
}
103103

104-
absl::StatusOr<zip_wrapper::FsZipArchive> FromRustFsZipArchive(
105-
rs_std::Result<zip_wrapper::FsZipArchive, zip_wrapper::VecU8>
104+
absl::StatusOr<rust::FsZipArchive> FromRustFsZipArchive(
105+
rs_std::Result<rust::FsZipArchive, rust::VecU8>
106106
result_fs_zip_archive) {
107107
if (!result_fs_zip_archive.has_value()) {
108108
return RustErrorToStatus(
@@ -112,8 +112,8 @@ absl::StatusOr<zip_wrapper::FsZipArchive> FromRustFsZipArchive(
112112
return std::move(result_fs_zip_archive).value();
113113
}
114114

115-
absl::StatusOr<zip_wrapper::BufferedZipFile> FromRustBufferedZipFile(
116-
rs_std::Result<zip_wrapper::BufferedZipFile, zip_wrapper::VecU8>
115+
absl::StatusOr<rust::BufferedZipFile> FromRustBufferedZipFile(
116+
rs_std::Result<rust::BufferedZipFile, rust::VecU8>
117117
result_buffered_zip_file) {
118118
if (!result_buffered_zip_file.has_value()) {
119119
return RustErrorToStatus(
@@ -123,8 +123,8 @@ absl::StatusOr<zip_wrapper::BufferedZipFile> FromRustBufferedZipFile(
123123
return std::move(result_buffered_zip_file).value();
124124
}
125125

126-
absl::StatusOr<zip_wrapper::FsZipFile> FromRustFsZipFile(
127-
rs_std::Result<zip_wrapper::FsZipFile, zip_wrapper::VecU8>
126+
absl::StatusOr<rust::FsZipFile> FromRustFsZipFile(
127+
rs_std::Result<rust::FsZipFile, rust::VecU8>
128128
result_fs_zip_file) {
129129
if (!result_fs_zip_file.has_value()) {
130130
return RustErrorToStatus(FromRustVecU8(std::move(result_fs_zip_file).err()),
@@ -133,8 +133,8 @@ absl::StatusOr<zip_wrapper::FsZipFile> FromRustFsZipFile(
133133
return std::move(result_fs_zip_file).value();
134134
}
135135

136-
absl::StatusOr<zip_wrapper::BufferedZipWriter> FromRustBufferedZipWriter(
137-
rs_std::Result<zip_wrapper::BufferedZipWriter, zip_wrapper::VecU8>
136+
absl::StatusOr<rust::BufferedZipWriter> FromRustBufferedZipWriter(
137+
rs_std::Result<rust::BufferedZipWriter, rust::VecU8>
138138
result_buffered_zip_writer) {
139139
if (!result_buffered_zip_writer.has_value()) {
140140
return RustErrorToStatus(
@@ -144,8 +144,8 @@ absl::StatusOr<zip_wrapper::BufferedZipWriter> FromRustBufferedZipWriter(
144144
return std::move(result_buffered_zip_writer).value();
145145
}
146146

147-
absl::StatusOr<zip_wrapper::FsZipWriter> FromRustFsZipWriter(
148-
rs_std::Result<zip_wrapper::FsZipWriter, zip_wrapper::VecU8>
147+
absl::StatusOr<rust::FsZipWriter> FromRustFsZipWriter(
148+
rs_std::Result<rust::FsZipWriter, rust::VecU8>
149149
result_fs_zip_writer) {
150150
if (!result_fs_zip_writer.has_value()) {
151151
return RustErrorToStatus(

zip/converters.h

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,62 @@
44
#include <utility>
55

66
#include "crubit_helpers/string_conversions.h"
7-
#include "rust/zip_wrapper.h"
7+
#include <chrono>
8+
#include <ctime>
9+
#include "absl/time/time.h"
10+
11+
// Workaround for Crubit generating `namespace time` (from the Rust `time` crate)
12+
// which collides with the C standard library `time()` function in the global namespace.
13+
// The macro renames Crubit's namespace to `crubit_time_namespace` during header parsing.
14+
#define time crubit_time_namespace
15+
#include "crubit/rust.h"
16+
#undef time
817
#include "absl/status/status.h"
918
#include "absl/status/statusor.h"
1019
#include "absl/strings/string_view.h"
1120

1221
namespace security::zip {
1322

14-
// A wrapper around zip_wrapper::VecU8 that provides an interface to view the
23+
// A wrapper around rust::VecU8 that provides an interface to view the
1524
// underlying data as an absl::string_view.
1625
class RustVecU8Wrapper {
1726
public:
1827
RustVecU8Wrapper() = default;
19-
explicit RustVecU8Wrapper(zip_wrapper::VecU8 vec_u8)
28+
explicit RustVecU8Wrapper(rust::VecU8 vec_u8)
2029
: vec_u8_(std::move(vec_u8)) {}
2130

2231
absl::string_view AsStringView() const {
2332
return security::crubit_helpers::StringViewFromVecU8(vec_u8_);
2433
}
2534

2635
private:
27-
zip_wrapper::VecU8 vec_u8_;
36+
rust::VecU8 vec_u8_;
2837
};
2938

3039
absl::StatusOr<RustVecU8Wrapper> FromRustResultVecU8(
31-
rs_std::Result<zip_wrapper::VecU8, zip_wrapper::VecU8> result_vec_u8);
40+
rs_std::Result<rust::VecU8, rust::VecU8> result_vec_u8);
3241
absl::Status FromRustResultUnit(
33-
rs_std::Result<uint8_t, zip_wrapper::VecU8> result_unit);
42+
rs_std::Result<uint8_t, rust::VecU8> result_unit);
3443

35-
absl::StatusOr<zip_wrapper::BufferedZipArchive> FromRustBufferedZipArchive(
36-
rs_std::Result<zip_wrapper::BufferedZipArchive, zip_wrapper::VecU8>
44+
absl::StatusOr<rust::BufferedZipArchive> FromRustBufferedZipArchive(
45+
rs_std::Result<rust::BufferedZipArchive, rust::VecU8>
3746
result_buffered_zip_archive);
38-
absl::StatusOr<zip_wrapper::FsZipArchive> FromRustFsZipArchive(
39-
rs_std::Result<zip_wrapper::FsZipArchive, zip_wrapper::VecU8>
47+
absl::StatusOr<rust::FsZipArchive> FromRustFsZipArchive(
48+
rs_std::Result<rust::FsZipArchive, rust::VecU8>
4049
result_fs_zip_archive);
4150

42-
absl::StatusOr<zip_wrapper::BufferedZipFile> FromRustBufferedZipFile(
43-
rs_std::Result<zip_wrapper::BufferedZipFile, zip_wrapper::VecU8>
51+
absl::StatusOr<rust::BufferedZipFile> FromRustBufferedZipFile(
52+
rs_std::Result<rust::BufferedZipFile, rust::VecU8>
4453
result_buffered_zip_file);
45-
absl::StatusOr<zip_wrapper::FsZipFile> FromRustFsZipFile(
46-
rs_std::Result<zip_wrapper::FsZipFile, zip_wrapper::VecU8>
54+
absl::StatusOr<rust::FsZipFile> FromRustFsZipFile(
55+
rs_std::Result<rust::FsZipFile, rust::VecU8>
4756
result_fs_zip_file);
4857

49-
absl::StatusOr<zip_wrapper::BufferedZipWriter> FromRustBufferedZipWriter(
50-
rs_std::Result<zip_wrapper::BufferedZipWriter, zip_wrapper::VecU8>
58+
absl::StatusOr<rust::BufferedZipWriter> FromRustBufferedZipWriter(
59+
rs_std::Result<rust::BufferedZipWriter, rust::VecU8>
5160
result_buffered_zip_writer);
52-
absl::StatusOr<zip_wrapper::FsZipWriter> FromRustFsZipWriter(
53-
rs_std::Result<zip_wrapper::FsZipWriter, zip_wrapper::VecU8>
61+
absl::StatusOr<rust::FsZipWriter> FromRustFsZipWriter(
62+
rs_std::Result<rust::FsZipWriter, rust::VecU8>
5463
result_fs_zip_writer);
5564

5665
} // namespace security::zip

zip/file.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#include "crubit_helpers/string_conversions.h"
77
#include "converters.h"
8-
#include "rust/zip_wrapper.h"
8+
#include "crubit/rust.h"
99
#include "absl/status/status.h"
1010
#include "absl/status/status_macros.h"
1111
#include "absl/status/statusor.h"
@@ -14,21 +14,21 @@ namespace security::zip {
1414
namespace {
1515

1616
absl::StatusOr<CompressionMethod> ToSecurityZipCompressionMethod(
17-
zip_wrapper::CompressionMethod rust_method) {
17+
rust::CompressionMethod rust_method) {
1818
switch (rust_method.tag) {
19-
case zip_wrapper::CompressionMethod::Tag::Stored:
19+
case rust::CompressionMethod::Tag::Stored:
2020
return CompressionMethod::kStored;
21-
case zip_wrapper::CompressionMethod::Tag::Deflated:
21+
case rust::CompressionMethod::Tag::Deflated:
2222
return CompressionMethod::kDeflated;
23-
case zip_wrapper::CompressionMethod::Tag::Bzip2:
23+
case rust::CompressionMethod::Tag::Bzip2:
2424
return CompressionMethod::kBzip2;
25-
case zip_wrapper::CompressionMethod::Tag::Zstd:
25+
case rust::CompressionMethod::Tag::Zstd:
2626
return CompressionMethod::kZstd;
27-
case zip_wrapper::CompressionMethod::Tag::Lzma:
27+
case rust::CompressionMethod::Tag::Lzma:
2828
return CompressionMethod::kLzma;
29-
case zip_wrapper::CompressionMethod::Tag::Xz:
29+
case rust::CompressionMethod::Tag::Xz:
3030
return CompressionMethod::kXz;
31-
case zip_wrapper::CompressionMethod::Tag::Unsupported:
31+
case rust::CompressionMethod::Tag::Unsupported:
3232
return absl::InvalidArgumentError("Unsupported compression method");
3333
}
3434
return absl::InvalidArgumentError("Unknown compression method");
@@ -54,7 +54,7 @@ absl::StatusOr<bool> BufferedZipFile::IsDir() const {
5454
}
5555
absl::StatusOr<std::string> BufferedZipFile::GetFileName() const {
5656
ABSL_RETURN_IF_ERROR(CheckNone());
57-
zip_wrapper::VecU8 name_vec = zip_.get_file_name();
57+
rust::VecU8 name_vec = zip_.get_file_name();
5858
return std::string(security::crubit_helpers::StringViewFromVecU8(name_vec));
5959
}
6060
absl::StatusOr<CompressionMethod> BufferedZipFile::GetCompressionMethod()
@@ -85,7 +85,7 @@ absl::StatusOr<bool> FsZipFile::IsDir() const {
8585
}
8686
absl::StatusOr<std::string> FsZipFile::GetFileName() const {
8787
ABSL_RETURN_IF_ERROR(CheckNone());
88-
zip_wrapper::VecU8 name_vec = zip_.get_file_name();
88+
rust::VecU8 name_vec = zip_.get_file_name();
8989
return std::string(security::crubit_helpers::StringViewFromVecU8(name_vec));
9090
}
9191
absl::StatusOr<CompressionMethod> FsZipFile::GetCompressionMethod() const {

zip/file.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <variant>
88

99
#include "converters.h"
10-
#include "rust/zip_wrapper.h"
10+
#include "crubit/rust.h"
1111
#include "absl/status/status.h"
1212
#include "absl/status/statusor.h"
1313

@@ -27,7 +27,7 @@ enum class CompressionMethod : int32_t {
2727

2828
class BufferedZipFile final {
2929
public:
30-
explicit BufferedZipFile(zip_wrapper::BufferedZipFile zip)
30+
explicit BufferedZipFile(rust::BufferedZipFile zip)
3131
: zip_(std::move(zip)) {}
3232
absl::StatusOr<bool> IsFile() const;
3333
absl::StatusOr<bool> IsDir() const;
@@ -38,14 +38,14 @@ class BufferedZipFile final {
3838

3939
private:
4040
absl::Status CheckNone() const;
41-
zip_wrapper::BufferedZipFile zip_;
41+
rust::BufferedZipFile zip_;
4242
friend class BufferedZipWriter;
4343
friend class FsZipWriter;
4444
};
4545

4646
class FsZipFile final {
4747
public:
48-
explicit FsZipFile(zip_wrapper::FsZipFile zip) : zip_(std::move(zip)) {}
48+
explicit FsZipFile(rust::FsZipFile zip) : zip_(std::move(zip)) {}
4949
absl::StatusOr<bool> IsFile() const;
5050
absl::StatusOr<bool> IsDir() const;
5151
bool IsNone() const;
@@ -55,18 +55,18 @@ class FsZipFile final {
5555

5656
private:
5757
absl::Status CheckNone() const;
58-
zip_wrapper::FsZipFile zip_;
58+
rust::FsZipFile zip_;
5959
friend class BufferedZipWriter;
6060
friend class FsZipWriter;
6161
};
6262

6363
class ZipFile final {
6464
public:
65-
static ZipFile FromFile(zip_wrapper::FsZipFile zip) {
65+
static ZipFile FromFile(rust::FsZipFile zip) {
6666
return ZipFile(FsZipFile(std::move(zip)));
6767
}
6868

69-
static ZipFile FromBuffer(zip_wrapper::BufferedZipFile zip) {
69+
static ZipFile FromBuffer(rust::BufferedZipFile zip) {
7070
return ZipFile(BufferedZipFile(std::move(zip)));
7171
}
7272

0 commit comments

Comments
 (0)