Skip to content

Commit da8b7be

Browse files
committed
remove the last dependences from brotli_sys
1 parent e873e4d commit da8b7be

11 files changed

Lines changed: 414 additions & 168 deletions

File tree

‎.github/workflows/format.yml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ jobs:
3838
- name: Check format
3939
run: git diff --exit-code
4040

41+
- name: Check refcount rules have no unsafe code
42+
run: |
43+
if grep -nw unsafe rules/*/tgt_refcount.rs; then
44+
echo "error: refcount rules must not use unsafe code"
45+
exit 1
46+
fi
47+
4148
- name: Check markdown formatting
4249
run: npx prettier@3.9.8 --check "src/**/*.md"
4350
working-directory: docs

‎.gitignore‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Cargo.lock
55
target/
66

77
rules/rustls/rustls.h
8-
rules/brotli/brotli/
98

109
# Python
1110
*.pyc

‎CMakeLists.txt‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,6 @@ add_custom_target("check"
163163
)
164164

165165
set(RUSTLS_HEADER "${PROJECT_SOURCE_DIR}/rules/rustls/rustls.h")
166-
set(BROTLI_HEADERS
167-
"${PROJECT_SOURCE_DIR}/rules/brotli/brotli/decode.h"
168-
"${PROJECT_SOURCE_DIR}/rules/brotli/brotli/encode.h"
169-
"${PROJECT_SOURCE_DIR}/rules/brotli/brotli/port.h"
170-
"${PROJECT_SOURCE_DIR}/rules/brotli/brotli/types.h")
171166

172167
set(PREPROCESSOR_BIN "${CMAKE_BINARY_DIR}/rule-preprocessor-target/release/rule-preprocessor")
173168
set(PREPROCESSOR_ARTIFACTS "${CMAKE_BINARY_DIR}/rule-preprocessor-target/artifacts.json")
@@ -194,7 +189,7 @@ execute_process(
194189
)
195190

196191
add_custom_command(
197-
OUTPUT ${RUSTLS_HEADER} ${BROTLI_HEADERS} ${RULES_LIB}
192+
OUTPUT ${RUSTLS_HEADER} ${RULES_LIB}
198193
COMMAND ${CARGO_ENV_RULES}
199194
cargo +${RUST_STABLE_VERSION} build --release
200195
--manifest-path "${PROJECT_SOURCE_DIR}/rules/Cargo.toml"
@@ -238,13 +233,14 @@ foreach(_rule_dir IN LISTS rule_subdirs)
238233
if(NOT _cpp_srcs)
239234
continue()
240235
endif()
236+
file(GLOB _rule_headers ${_rule_dir}/*.h)
241237
get_filename_component(_rule_name ${_rule_dir} NAME)
242238
set(_part ${rules_index_parts_dir}/${_rule_name}.json)
243239
add_custom_command(
244240
OUTPUT ${_part}
245241
COMMAND ${CMAKE_COMMAND} -E make_directory ${rules_index_parts_dir}
246242
COMMAND $<TARGET_FILE:cpp-rule-indexer> --dir ${_rule_dir} -o ${_part}
247-
DEPENDS ${_cpp_srcs} ${rule_common_headers} ${rule_indexer_sources} ${RUSTLS_HEADER} ${BROTLI_HEADERS}
243+
DEPENDS ${_cpp_srcs} ${_rule_headers} ${rule_common_headers} ${rule_indexer_sources} ${RUSTLS_HEADER}
248244
VERBATIM
249245
)
250246
list(APPEND rules_index_parts ${_part})

‎rule-preprocessor/src/semantic.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ fn build_rustc_args(crate_root: &Path) -> Vec<String> {
7777
"libcc2rs",
7878
"libcc2rs_macros",
7979
"libc",
80-
"brotli_sys",
8180
"rustls_ffi",
8281
"nix",
8382
"jiff",

‎rules/Cargo.toml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ path = "src/lib.rs"
1111
[dependencies]
1212
libc = "0.2.148"
1313
libcc2rs = { version = "0.1.0", path = "../libcc2rs" }
14-
brotli-sys = "0.3"
1514
rustls-ffi = { version = "0.15.3", default-features = false }
1615
nix = { version = "0.30", features = ["socket", "net", "fs", "poll", "time", "user", "dir", "term", "event", "hostname"] }
1716
jiff = "0.2"

‎rules/brotli/brotli.h‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright (c) 2022-present INESC-ID.
2+
// Distributed under the MIT license that can be found in the LICENSE file.
3+
4+
// The subset of the brotli C API (<brotli/decode.h> and <brotli/encode.h>)
5+
// that the rules use.
6+
7+
#include <stddef.h>
8+
#include <stdint.h>
9+
10+
#define BROTLI_BOOL int
11+
#define BROTLI_ARRAY_PARAM(name)
12+
13+
typedef void *(*brotli_alloc_func)(void *opaque, size_t size);
14+
typedef void (*brotli_free_func)(void *opaque, void *address);
15+
16+
typedef struct BrotliDecoderStateStruct BrotliDecoderState;
17+
18+
typedef enum {
19+
BROTLI_DECODER_RESULT_ERROR = 0,
20+
BROTLI_DECODER_RESULT_SUCCESS = 1,
21+
BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT = 2,
22+
BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT = 3
23+
} BrotliDecoderResult;
24+
25+
typedef enum {
26+
BROTLI_DECODER_NO_ERROR = 0,
27+
BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE = -1,
28+
BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE = -3,
29+
BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET = -4,
30+
BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME = -5,
31+
BROTLI_DECODER_ERROR_FORMAT_CL_SPACE = -6,
32+
BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE = -7,
33+
BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT = -8,
34+
BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1 = -9,
35+
BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2 = -10,
36+
BROTLI_DECODER_ERROR_FORMAT_TRANSFORM = -11,
37+
BROTLI_DECODER_ERROR_FORMAT_DICTIONARY = -12,
38+
BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS = -13,
39+
BROTLI_DECODER_ERROR_FORMAT_PADDING_1 = -14,
40+
BROTLI_DECODER_ERROR_FORMAT_PADDING_2 = -15,
41+
BROTLI_DECODER_ERROR_INVALID_ARGUMENTS = -20,
42+
BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES = -21,
43+
BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS = -22,
44+
BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP = -25,
45+
BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1 = -26,
46+
BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2 = -27,
47+
BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES = -30
48+
} BrotliDecoderErrorCode;
49+
50+
typedef enum BrotliEncoderMode {
51+
BROTLI_MODE_GENERIC = 0,
52+
BROTLI_MODE_TEXT = 1,
53+
BROTLI_MODE_FONT = 2
54+
} BrotliEncoderMode;
55+
56+
BrotliDecoderState *BrotliDecoderCreateInstance(brotli_alloc_func alloc_func,
57+
brotli_free_func free_func,
58+
void *opaque);
59+
void BrotliDecoderDestroyInstance(BrotliDecoderState *state);
60+
BrotliDecoderResult BrotliDecoderDecompress(size_t encoded_size,
61+
const uint8_t *encoded_buffer,
62+
size_t *decoded_size,
63+
uint8_t *decoded_buffer);
64+
BrotliDecoderResult
65+
BrotliDecoderDecompressStream(BrotliDecoderState *state, size_t *available_in,
66+
const uint8_t **next_in, size_t *available_out,
67+
uint8_t **next_out, size_t *total_out);
68+
const uint8_t *BrotliDecoderTakeOutput(BrotliDecoderState *state, size_t *size);
69+
BrotliDecoderErrorCode
70+
BrotliDecoderGetErrorCode(const BrotliDecoderState *state);
71+
uint32_t BrotliDecoderVersion(void);
72+
BROTLI_BOOL BrotliEncoderCompress(int quality, int lgwin,
73+
BrotliEncoderMode mode, size_t input_size,
74+
const uint8_t *input_buffer,
75+
size_t *encoded_size,
76+
uint8_t *encoded_buffer);

0 commit comments

Comments
 (0)