Repository navigation
Expand file tree
/
Copy pathbuild.jam
More file actions
142 lines (130 loc) · 6.42 KB
/
Copy pathbuild.jam
File metadata and controls
142 lines (130 loc) · 6.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# Copyright (c) 2026 WebCpp.org
#
# Distributed under the Boost Software License, Version 1.0. (See
# accompanying file LICENSE_1_0.txt or copy at
# https://www.boost.org/LICENSE_1_0.txt)
#
# asio: Boost.Asio natively, and on emscripten Boost.Asio's own io_context
# suspended into the browser's event loop. A program uses
# /webcpp/asio//asio.
project /webcpp/asio ;
import feature ;
import numbers ;
import webcpp ;
import webcpp-target ;
use-project /webcpp/asio-runtime : src ;
path-constant ASIO_SOURCE_DIR : src ;
include $(ASIO_SOURCE_DIR)/sources.jam ;
# The stack Asyncify saves a suspension in, in bytes: 8192 unless a program
# asks for more with <asyncify-stack-size>, propagated so that asio's usage
# requirements read it and their flag ends last on emcc's command line,
# where emcc keeps the last. Its values are powers of two; those below 8192
# are refused, by an #error of config.hpp that says why.
#
# 8192 was set on 2026-10-11 as twice 4096, the smallest power of two with
# which every test of asio passed in every build b2 linked then, measured
# with Emscripten 6.0.11 as the bytes each unwind wrote: the deepest build
# was release, compiled with -O3 and linked at -O0, whose deepest suspension
# wrote 3,540 bytes, and with 2048 its tests trapped. Since 2026-11-15 b2
# links release at -O3, and debug, linked at -O0 as before, is the deepest
# build: asyncify_stack measured at most 1,168 bytes there and 388 in
# release (848 and 304 without exceptions), and with 2048 no test of the
# asyncify lane trapped in either build, so that rule alone would now give
# 4096. The owner decided on 2026-11-15 that it stays 8192. Programs ship
# release builds, where the deepest suspension of the libraries built on
# asio wrote 564 bytes (trystero's room test; asio's 388), so that the rest
# is left to the program's own frames, whose depth asio cannot know; debug,
# for development and the tests, reached 2,344 (the same test), within the
# half asyncify_stack asks. 8192 is also the default and the floor those
# libraries and their programs are tested against, and a smaller size would
# make a program whose frames fit only the larger stack trap at run time,
# with no warning before.
# The test asyncify_stack measures each build on every run, and fails when
# a suspension of the run family leaves less than half of the stack; a new
# way to suspend, such as a coroutine's, is measured there.
feature.feature asyncify-stack-size
: 8192 16384 32768 65536 131072 262144 524288 1048576
256 512 1024 2048 4096
: propagated ;
# The usage requirement of asyncify-stack-size under Asyncify: the flag, or
# the define that refuses a size below asio's.
rule asyncify-stack ( properties * )
{
if [ feature.get-values <toolset> : $(properties) ] = emscripten
&& [ feature.get-values <webcpp-suspend> : $(properties) ] = asyncify
{
local size = [ feature.get-values <asyncify-stack-size> : $(properties) ] ;
if [ numbers.less $(size) 8192 ]
{
return <define>WEBCPP_ASIO_ASYNCIFY_STACK_SIZE_REFUSED ;
}
return <linkflags>-sASYNCIFY_STACK_SIZE=$(size) ;
}
}
# What a program on emscripten compiles once: the JavaScript functions asio
# calls, the run family's yield among them
# (include/webcpp/asio/browser/src.hpp), linked into every program on
# emscripten by asio's usage requirements below.
obj browser-src : src/$(ASIO_EMSCRIPTEN_RUNTIME) : <include>include <library>/boost//headers
<library>/webcpp/config//config ;
explicit browser-src ;
# Single-thread Emscripten needs BOOST_ASIO_DISABLE_THREADS. A pthread build
# supplies the POSIX thread implementation instead. Boost's inline namespace
# differs with and without threads, so every translation unit must agree.
# The browser's
# values reach C++ through embind: -lembind, a free feature, which a usage
# requirement keeps.
#
# Each suspension variant links its own flags. The suspending imports are
# Emscripten's __syscall_poll and asio's yield, which Emscripten finds
# itself, so no list of imports is given. ASYNCIFY_IGNORE_INDIRECT is not
# set, since the path from main to select passes the virtual
# scheduler_task::run. ASYNCIFY_STACK_SIZE is asyncify-stack-size's, above.
# The tag names every program on asio Boost's way, with its variant:
# reactor-60-d-jspi.js.
# EM_JS_DEPS is read after the native link in Emscripten 6.0.11. Keep the
# bridge's stack helpers exported even when an optimized JSPI runtime does
# not otherwise need them; JavaScript calls both through stackSave/Restore.
# tag::asio[]
alias headers : : : : <include>include <library>/boost//headers
<library>/webcpp/config//config ;
alias asio : : : : <include>include <library>/boost//headers
<library>/webcpp/config//config
<toolset>clang-wasip2:<library>/webcpp/asio-runtime//runtime
<toolset>clang-wasip3:<library>/webcpp/asio-runtime//runtime
<toolset>emscripten:<linkflags>-lembind
<toolset>emscripten:<linkflags>-Wl,--export=emscripten_stack_get_current
<toolset>emscripten:<linkflags>-Wl,--export=_emscripten_stack_restore
<toolset>emscripten,<threading>multi:<linkflags>-Wl,--wrap=__syscall_poll
<toolset>emscripten:<source>browser-src
<toolset>emscripten,<webcpp-suspend>jspi:<linkflags>-sJSPI
<toolset>emscripten,<webcpp-suspend>asyncify:<linkflags>-sASYNCIFY
<conditional>@asyncify-stack
<toolset>emscripten:<tag>@webcpp%suspend-tag ;
# end::asio[]
# tag::openssl[]
rule openssl-linked ( properties * )
{
if [ webcpp-target.target-of $(properties) ] in native wasip2 wasip3
{
return <library>/webcpp/third_party//openssl
<define>WEBCPP_ASIO_HAS_OPENSSL=1 ;
}
}
# Refused on Emscripten: every source of a program built for emscripten
# that names it stops at the forced include, whose message says what to
# write. Quoted, as the Jamroot quotes Boost's directory, for a path that
# holds a space.
path-constant WEBCPP_ASIO_ROOT : . ;
alias openssl : : : : <conditional>@openssl-linked
<toolset>emscripten:<cflags>"-include \"$(WEBCPP_ASIO_ROOT)/src/openssl_on_webassembly.hpp\""
<toolset>emscripten:<cxxflags>"-include \"$(WEBCPP_ASIO_ROOT)/src/openssl_on_webassembly.hpp\"" ;
# end::openssl[]
# Browser tests exercise the settings adapter without linking OpenSSL.
alias openssl-tests : : : : <conditional>@openssl-linked ;
explicit openssl-tests ;
# An explicit portable trust policy, separate from the raw OpenSSL context.
# tag::tls[]
alias tls : : : : <library>asio <library>openssl
<library>/webcpp/third_party//ca_certificates ;
# end::tls[]