Skip to content

Commit 0f95214

Browse files
authored
add brotli.jam (#552)
1 parent ac2c65a commit 0f95214

3 files changed

Lines changed: 276 additions & 0 deletions

File tree

src/tools/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+
}

test/libbrotli.py

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/usr/bin/env python3
2+
3+
# Copy-paste-modify from libzstd.py
4+
# Copyright (C) 2013 Steven Watanabe
5+
# Distributed under the Boost Software License, Version 1.0.
6+
# (See accompanying file LICENSE.txt or copy at
7+
# https://www.bfgroup.xyz/b2/LICENSE.txt)
8+
9+
import BoostBuild
10+
import MockToolset
11+
12+
t = BoostBuild.Tester(arguments=['toolset=mock', '--ignore-site-config', '--user-config='], pass_toolset=0)
13+
14+
MockToolset.create(t)
15+
16+
# Generic definitions that aren't configuration specific
17+
common_stuff = '''
18+
source_file('test.cpp', 'test.cpp')
19+
source_file('main.cpp', 'int main() {}')
20+
source_file('brotli/decode.h.cpp', '#include <brotli/decode.h>\\n')
21+
action('-c -x c++ $main.cpp -o $main.o')
22+
'''
23+
t.write('test.cpp', 'test.cpp')
24+
25+
for lib in ('brotlicommon', 'brotlidec', 'brotlienc'):
26+
27+
# Default initialization - static library
28+
t.rm('bin')
29+
t.write("Jamroot.jam", """
30+
path-constant here : . ;
31+
using brotli ;
32+
exe test : test.cpp /brotli//%(lib)s : : <link>static <link>shared ;
33+
""" % {'lib': lib})
34+
35+
MockToolset.set_expected(t, common_stuff + '''
36+
action('$main.o --static-lib=%(lib)s -o $config.exe')
37+
action('-c -x c++ $brotli/decode.h.cpp -o $brotli/decode.h.o')
38+
action('-c -x c++ $test.cpp -o $test.o')
39+
action('$test.o --static-lib=%(lib)s -o $test')
40+
''' % {'lib': lib})
41+
t.run_build_system()
42+
t.expect_addition('bin/mock/debug/test.exe')
43+
t.expect_addition('bin/mock/debug/link-static/test.exe')
44+
45+
# Default initialization - shared library
46+
t.rm('bin')
47+
t.write("Jamroot.jam", """
48+
path-constant here : . ;
49+
using brotli ;
50+
exe test : test.cpp /brotli//%(lib)s : : <link>static <link>shared ;
51+
""" % {'lib': lib})
52+
53+
MockToolset.set_expected(t, common_stuff + '''
54+
action('$main.o --shared-lib=%(lib)s -o $config.exe')
55+
action('-c -x c++ $brotli/decode.h.cpp -o $brotli/decode.h.o')
56+
action('-c -x c++ $test.cpp -o $test.o')
57+
action('$test.o --shared-lib=%(lib)s -o $test')
58+
''' % {'lib': lib})
59+
t.run_build_system()
60+
t.expect_addition('bin/mock/debug/test.exe')
61+
t.expect_addition('bin/mock/debug/link-static/test.exe')
62+
63+
# Initialization in explicit location - static library
64+
t.rm('bin')
65+
t.write("Jamroot.jam", """
66+
path-constant here : . ;
67+
using brotli : : <%(lib)s-name>my%(lib)s <include>$(here)/brotli <search>$(here)/brotli ;
68+
exe test : test.cpp /brotli//%(lib)s : : <link>static <link>shared ;
69+
""" % {'lib': lib})
70+
71+
t.write('brotli/brotli/decode.h', 'brotli')
72+
73+
MockToolset.set_expected(t, common_stuff + '''
74+
action('$main.o -L./brotli --static-lib=my%(lib)s -o $config.exe')
75+
action('-c -x c++ $test.cpp -I./brotli -o $test.o')
76+
action('$test.o -L./brotli --static-lib=my%(lib)s -o $test')
77+
''' % {'lib': lib})
78+
t.run_build_system()
79+
t.expect_addition('bin/mock/debug/test.exe')
80+
t.expect_addition('bin/mock/debug/link-static/test.exe')
81+
82+
# Initialization in explicit location - shared library
83+
t.rm('bin')
84+
t.write("Jamroot.jam", """
85+
path-constant here : . ;
86+
using brotli : : <%(lib)s-name>my%(lib)s <include>$(here)/brotli <search>$(here)/brotli ;
87+
exe test : test.cpp /brotli//%(lib)s : : <link>static <link>shared ;
88+
""" % {'lib': lib})
89+
90+
MockToolset.set_expected(t, common_stuff + '''
91+
action('$main.o -L./brotli --shared-lib=my%(lib)s -o $config.exe')
92+
action('-c -x c++ $test.cpp -I./brotli -o $test.o')
93+
action('$test.o -L./brotli --shared-lib=my%(lib)s -o $test')
94+
''' % {'lib': lib})
95+
t.run_build_system()
96+
t.expect_addition('bin/mock/debug/test.exe')
97+
t.expect_addition('bin/mock/debug/link-static/test.exe')
98+
99+
# Initialization in explicit location - both static and shared libraries
100+
t.rm('bin')
101+
t.write("Jamroot.jam", """
102+
path-constant here : . ;
103+
using brotli : : <%(lib)s-name>my%(lib)s <include>$(here)/brotli <search>$(here)/brotli ;
104+
exe test : test.cpp /brotli//%(lib)s
105+
: <link>shared:<define>SHARED : <link>static <link>shared ;
106+
""" % {'lib': lib})
107+
108+
MockToolset.set_expected(t, common_stuff + '''
109+
action('$main.o -L./brotli --static-lib=my%(lib)s -o $config.exe')
110+
action('$main.o -L./brotli --shared-lib=my%(lib)s -o $config.exe')
111+
action('-c -x c++ $test.cpp -I./brotli -o $test-static.o')
112+
action('-c -x c++ $test.cpp -I./brotli -DSHARED -o $test-shared.o')
113+
action('$test-static.o -L./brotli --static-lib=my%(lib)s -o $test')
114+
action('$test-shared.o -L./brotli --shared-lib=my%(lib)s -o $test')
115+
''' % {'lib': lib})
116+
t.run_build_system()
117+
t.expect_addition('bin/mock/debug/test.exe')
118+
t.expect_addition('bin/mock/debug/link-static/test.exe')
119+
120+
t.cleanup()

test/test_all.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ def reorder_tests(tests, first_test):
410410
"inline",
411411
"install_build_no",
412412
"lang_asm",
413+
"libbrotli",
413414
"lib_source_property",
414415
"lib_zlib",
415416
"libjpeg",

0 commit comments

Comments
 (0)