Skip to content

Commit de794c6

Browse files
committed
add brotli service
1 parent ebe1c28 commit de794c6

24 files changed

Lines changed: 1323 additions & 58 deletions

File tree

.github/workflows/ci.yml

Lines changed: 120 additions & 23 deletions
Large diffs are not rendered by default.

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,21 @@ if (ZLIB_FOUND)
165165
target_compile_definitions(boost_rts_zlib PRIVATE BOOST_RTS_SOURCE)
166166
endif ()
167167

168+
# Brotli
169+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
170+
find_package(Brotli)
171+
if (Brotli_FOUND)
172+
file(GLOB_RECURSE BOOST_RTS_BROTLI_SOURCES CONFIGURE_DEPENDS src_brotli/*.cpp src_brotli/*.hpp)
173+
file(GLOB_RECURSE BOOST_RTS_BROTLI_HEADERS CONFIGURE_DEPENDS include/boost/rts/brotli/*.hpp)
174+
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src_brotli PREFIX "src" FILES ${BOOST_RTS_BROTLI_SOURCES})
175+
add_library(boost_rts_brotli build/Jamfile ${BOOST_RTS_BROTLI_HEADERS} ${BOOST_RTS_BROTLI_SOURCES})
176+
add_library(Boost::rts_brotli ALIAS boost_rts_brotli)
177+
target_link_libraries(boost_rts_brotli PUBLIC boost_rts)
178+
target_link_libraries(boost_rts_brotli PRIVATE Brotli::common Brotli::decoder Brotli::encoder)
179+
target_compile_definitions(boost_rts_brotli PUBLIC BOOST_RTS_HAS_BROTLI)
180+
target_compile_definitions(boost_rts_brotli PRIVATE BOOST_RTS_SOURCE)
181+
endif ()
182+
168183
#-------------------------------------------------
169184
#
170185
# Tests

build/Jamfile

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import ac ;
1111
import ../../config/checks/config : requires ;
1212

13-
using zlib ;
14-
1513
constant c11-requires :
1614
[ requires
1715
cxx11_constexpr
@@ -25,40 +23,59 @@ constant c11-requires :
2523
path-constant RTS_ROOT : .. ;
2624

2725
project boost/rts
28-
: requirements
29-
$(c11-requires)
30-
<link>shared:<define>BOOST_RTS_DYN_LINK=1
31-
<link>static:<define>BOOST_RTS_STATIC_LINK=1
32-
<define>BOOST_RTS_SOURCE
33-
: usage-requirements
34-
<link>shared:<define>BOOST_RTS_DYN_LINK=1
35-
<link>static:<define>BOOST_RTS_STATIC_LINK=1
36-
: source-location $(RTS_ROOT)
37-
;
26+
: requirements
27+
$(c11-requires)
28+
<link>shared:<define>BOOST_RTS_DYN_LINK=1
29+
<link>static:<define>BOOST_RTS_STATIC_LINK=1
30+
<define>BOOST_RTS_SOURCE
31+
: usage-requirements
32+
<link>shared:<define>BOOST_RTS_DYN_LINK=1
33+
<link>static:<define>BOOST_RTS_STATIC_LINK=1
34+
: source-location $(RTS_ROOT)
35+
;
3836

3937
alias rts_sources : [ glob-tree-ex ./src : *.cpp ] ;
4038

4139
lib boost_rts
42-
: rts_sources
43-
: requirements
44-
: usage-requirements
45-
;
40+
: rts_sources
41+
: requirements
42+
: usage-requirements
43+
;
4644

4745
boost-install boost_rts ;
4846

49-
5047
# Zlib
48+
using zlib ;
5149

5250
alias rts_zlib_sources : [ glob-tree-ex ./src_zlib : *.cpp ] ;
5351

5452
lib boost_rts_zlib
55-
: rts_zlib_sources
56-
: requirements
57-
<library>/boost/rts//boost_rts
58-
[ ac.check-library /zlib//zlib : <library>/zlib//zlib : <build>no ]
59-
: usage-requirements
60-
<library>/boost/rts//boost_rts
61-
<define>BOOST_RTS_HAS_ZLIB
62-
;
53+
: rts_zlib_sources
54+
: requirements
55+
<library>/boost/rts//boost_rts
56+
[ ac.check-library /zlib//zlib : <library>/zlib//zlib : <build>no ]
57+
: usage-requirements
58+
<library>/boost/rts//boost_rts
59+
<define>BOOST_RTS_HAS_ZLIB
60+
;
6361

6462
boost-install boost_rts_zlib ;
63+
64+
# Brotli
65+
using brotli ;
66+
67+
alias rts_brotli_sources : [ glob-tree-ex ./src_brotli : *.cpp ] ;
68+
69+
lib boost_rts_brotli
70+
: rts_brotli_sources
71+
: requirements
72+
<library>/boost/rts//boost_rts
73+
[ ac.check-library /brotli//brotlicommon : <library>/brotli//brotlicommon : <build>no ]
74+
[ ac.check-library /brotli//brotlidec : <library>/brotli//brotlidec : <build>no ]
75+
[ ac.check-library /brotli//brotlienc : <library>/brotli//brotlienc : <build>no ]
76+
: usage-requirements
77+
<library>/boost/rts//boost_rts
78+
<define>BOOST_RTS_HAS_BROTLI
79+
;
80+
81+
boost-install boost_rts_brotli ;

build/brotli.jam

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# Copyright (c) 2025 Mohammad Nejati
2+
#
3+
# Use, modification and distribution is subject to the Boost Software
4+
# License Version 1.0. (See accompanying file LICENSE.txt or
5+
# https://www.bfgroup.xyz/b2/LICENSE.txt)
6+
7+
# Supports the brotli library
8+
#
9+
# After 'using brotli', the following targets are available:
10+
#
11+
# /brotli//brotlicommon -- The brotli common library
12+
# /brotli//brotlidec -- The brotli decoder library
13+
# /brotli//brotlienc -- The brotli encoder library
14+
15+
import project ;
16+
import ac ;
17+
import errors ;
18+
import feature ;
19+
import "class" : new ;
20+
import targets ;
21+
import path ;
22+
import modules ;
23+
import indirect ;
24+
import property ;
25+
import property-set ;
26+
import args ;
27+
28+
header = brotli/decode.h ;
29+
brotlicommon_names = brotlicommon libbrotlicommon ;
30+
brotlidec_names = brotlidec libbrotlidec ;
31+
brotlienc_names = brotlienc libbrotlienc ;
32+
33+
library-id = 0 ;
34+
35+
.debug = [ args.get-arg debug-configuration ] ;
36+
37+
# Initializes the brotli library.
38+
#
39+
# Options for configuring brotli::
40+
#
41+
# <search>
42+
# The directory containing the brotli binaries.
43+
# <brotlicommon-name>
44+
# Overrides the default name of brotlicommon library.
45+
# <brotlidec-name>
46+
# Overrides the default name of brotlidec library.
47+
# <brotlienc-name>
48+
# Overrides the default name of brotlienc library.
49+
# <include>
50+
# The directory containing the brotli headers.
51+
# <dll-path>
52+
# Extra directories to add to library search paths of consumers during
53+
# runtime (multiple instances are allowed).
54+
#
55+
# If none of these options is specified, then the environmental
56+
# variables BROTLI_LIBRARY_PATH, BROTLI_NAME, and BROTLI_INCLUDE will
57+
# be used instead.
58+
#
59+
# Examples::
60+
#
61+
# # Find brotli in the default system location
62+
# using brotli ;
63+
# # Find brotli in /usr/local
64+
# using brotli : 1.1.0
65+
# : <include>/usr/local/include <search>/usr/local/lib ;
66+
#
67+
rule init (
68+
version ?
69+
# (currently ignored)
70+
71+
: options *
72+
# A list of the options to use
73+
74+
: requirements *
75+
# The requirements for the target
76+
77+
: is-default ?
78+
)
79+
{
80+
local caller = [ project.current ] ;
81+
82+
if ! $(.initialized)
83+
{
84+
.initialized = true ;
85+
86+
project.initialize $(__name__) ;
87+
.project = [ project.current ] ;
88+
project brotli ;
89+
}
90+
91+
local library-path = [ feature.get-values <search> : $(options) ] ;
92+
local include-path = [ feature.get-values <include> : $(options) ] ;
93+
local brotlicommon-name = [ feature.get-values <brotlicommon-name> : $(options) ] ;
94+
local brotlidec-name = [ feature.get-values <brotlidec-name> : $(options) ] ;
95+
local brotlienc-name = [ feature.get-values <brotlienc-name> : $(options) ] ;
96+
local dll-paths = [ property.select <dll-path> : $(options) ] ;
97+
98+
if ! $(options)
99+
{
100+
is-default = true ;
101+
}
102+
103+
condition = [ property-set.create $(requirements) ] ;
104+
condition = [ property-set.create [ $(condition).base ] ] ;
105+
106+
if $(.configured.$(condition))
107+
{
108+
if $(is-default)
109+
{
110+
if $(.debug)
111+
{
112+
ECHO "notice: [brotli] brotli is already configured" ;
113+
}
114+
}
115+
else
116+
{
117+
errors.user-error "brotli is already configured" ;
118+
}
119+
return ;
120+
}
121+
else
122+
{
123+
if $(.debug)
124+
{
125+
ECHO "notice: [brotli] Using pre-installed library" ;
126+
if $(condition)
127+
{
128+
ECHO "notice: [brotli] Condition" [ $(condition).raw ] ;
129+
}
130+
}
131+
132+
local brotlicommon = [ new ac-library brotlicommon : $(.project) : $(condition) :
133+
$(include-path) : $(library-path) : $(brotlicommon-name) ] ;
134+
$(brotlicommon).set-header $(header) ;
135+
$(brotlicommon).set-default-names $(brotlicommon_names) ;
136+
$(brotlicommon).add-usage-requirements $(dll-paths) ;
137+
138+
local brotlidec = [ new ac-library brotlidec : $(.project) : $(condition) :
139+
$(include-path) : $(library-path) : $(brotlidec-name) ] ;
140+
$(brotlidec).set-header $(header) ;
141+
$(brotlidec).set-default-names $(brotlidec_names) ;
142+
$(brotlidec).add-usage-requirements $(dll-paths) ;
143+
144+
local brotlienc = [ new ac-library brotlienc : $(.project) : $(condition) :
145+
$(include-path) : $(library-path) : $(brotlienc-name) ] ;
146+
$(brotlienc).set-header $(header) ;
147+
$(brotlienc).set-default-names $(brotlienc_names) ;
148+
$(brotlienc).add-usage-requirements $(dll-paths) ;
149+
150+
targets.main-target-alternative $(brotlicommon) ;
151+
targets.main-target-alternative $(brotlidec) ;
152+
targets.main-target-alternative $(brotlienc) ;
153+
}
154+
.configured.$(condition) = true ;
155+
}

cmake/FindBrotli.cmake

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#
2+
# Copyright (c) 2025 Mohammad Nejati
3+
#
4+
# Distributed under the Boost Software License, Version 1.0. (See accompanying
5+
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
#
7+
# Official repository: https://github.com/cppalliance/rts
8+
#
9+
10+
# Provides imported targets:
11+
# Brotli::common
12+
# Brotli::decoder
13+
# Brotli::encoder
14+
15+
find_path(Brotli_INCLUDE_DIR "brotli/decode.h")
16+
find_library(Brotli_COMMON_LIBRARY NAMES "brotlicommon")
17+
find_library(Brotli_DEC_LIBRARY NAMES "brotlidec")
18+
find_library(Brotli_ENC_LIBRARY NAMES "brotlienc")
19+
20+
include(FindPackageHandleStandardArgs)
21+
find_package_handle_standard_args(Brotli
22+
REQUIRED_VARS
23+
Brotli_INCLUDE_DIR
24+
Brotli_COMMON_LIBRARY
25+
Brotli_DEC_LIBRARY
26+
Brotli_ENC_LIBRARY
27+
)
28+
29+
if(Brotli_FOUND)
30+
add_library(Brotli::common UNKNOWN IMPORTED)
31+
set_target_properties(Brotli::common PROPERTIES
32+
IMPORTED_LOCATION ${Brotli_COMMON_LIBRARY}
33+
INTERFACE_INCLUDE_DIRECTORIES ${Brotli_INCLUDE_DIR})
34+
35+
add_library(Brotli::decoder UNKNOWN IMPORTED)
36+
set_target_properties(Brotli::decoder PROPERTIES
37+
IMPORTED_LOCATION ${Brotli_DEC_LIBRARY}
38+
INTERFACE_INCLUDE_DIRECTORIES ${Brotli_INCLUDE_DIR})
39+
40+
add_library(Brotli::encoder UNKNOWN IMPORTED)
41+
set_target_properties(Brotli::encoder PROPERTIES
42+
IMPORTED_LOCATION ${Brotli_ENC_LIBRARY}
43+
INTERFACE_INCLUDE_DIRECTORIES ${Brotli_INCLUDE_DIR})
44+
endif()
45+
46+
mark_as_advanced(
47+
Brotli_INCLUDE_DIR
48+
Brotli_COMMON_LIBRARY
49+
Brotli_DEC_LIBRARY
50+
Brotli_ENC_LIBRARY)

include/boost/rts/brotli.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// Copyright (c) 2025 Mohammad Nejati
3+
//
4+
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5+
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
//
7+
// Official repository: https://github.com/cppalliance/rts
8+
//
9+
10+
#ifndef BOOST_RTS_BROTLI_HPP
11+
#define BOOST_RTS_BROTLI_HPP
12+
13+
#include <boost/rts/brotli/decode.hpp>
14+
#include <boost/rts/brotli/encode.hpp>
15+
#include <boost/rts/brotli/types.hpp>
16+
17+
#endif

0 commit comments

Comments
 (0)