Skip to content

Commit 5d222c1

Browse files
authored
Use common include directory for all ports (#9983)
We already use a common "lib" directory to install all the libs. This change simply installs headers in the same common "sysroot". This makes the ports install more like normal "make install" scripts would.
1 parent ac78b15 commit 5d222c1

26 files changed

+209
-150
lines changed

ChangeLog.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@ See docs/process.md for how version tagging works.
1717

1818
Current Trunk
1919
-------------
20-
- Removed `timestamp` field from mouse, wheel, devicemotion and deviceorientation
21-
events. The presence of a `timestamp` on these events was slightly arbitrary,
22-
and populating this field caused a small profileable overhead that all users
23-
might not care about. It is easy to get a timestamp of an event by calling
24-
`emscripten_get_now()` or `emscripten_performance_now()` inside the event
25-
handler function of any event.
20+
- All ports now install their headers into a shared directory under
21+
`EM_CACHE`. This should not really be a user visible change although one
22+
side effect is that once a give ports is built its headers are then
23+
universally accessible, just like the library is universally available as
24+
`-l<name>`.
25+
- Removed `timestamp` field from mouse, wheel, devicemotion and
26+
deviceorientation events. The presence of a `timestamp` on these events was
27+
slightly arbitrary, and populating this field caused a small profileable
28+
overhead that all users might not care about. It is easy to get a timestamp of
29+
an event by calling `emscripten_get_now()` or `emscripten_performance_now()`
30+
inside the event handler function of any event.
2631
- Add fine-grained options for specific legacy browser support,
2732
`MIN_FIREFOX_VERSION`, `MIN_SAFARI_VERSION`, `MIN_IE_VERSION`,
2833
`MIN_EDGE_VERSION`, `MIN_CHROME_VERSION`. The existing `LEGACY_VM_SUPPORT`

embuilder.py

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
from tools import shared
1919
from tools.system_libs import Library
2020

21-
C_BARE = '''
22-
int main() {}
23-
'''
21+
C_BARE = 'int main() {}'
2422

2523
SYSTEM_LIBRARIES = Library.get_all_variations()
2624
SYSTEM_TASKS = list(SYSTEM_LIBRARIES.keys())
@@ -60,35 +58,23 @@
6058
force = False
6159

6260

63-
def print_help():
61+
def get_usage():
6462
all_tasks = SYSTEM_TASKS + USER_TASKS
6563
all_tasks.sort()
66-
print('''
67-
Emscripten System Builder Tool
68-
==============================
64+
return '''embuilder.py [flags]... OPERATION TARGET [TARGET]...
6965
7066
You can use this tool to manually build parts of the emscripten system
7167
environment. In general emcc will build them automatically on demand, so
7268
you do not strictly need to use this tool, but it gives you more control
7369
over the process (in particular, if emcc does this automatically, and you
7470
are running multiple build commands in parallel, confusion can occur).
7571
76-
Usage:
77-
78-
embuilder.py OPERATION TASK1 [TASK2..] [--pic] [--lto]
79-
8072
Available operations and tasks:
8173
8274
build %s
8375
8476
Issuing 'embuilder.py build ALL' causes each task to be built.
8577
86-
Flags:
87-
88-
--force Force rebuild of target (by removing it first)
89-
--lto Build bitcode files, for LTO with the LLVM wasm backend
90-
--pic Build as position independent code (used by MAIN_MODULE/SIDE_MODULE)
91-
9278
It is also possible to build native_optimizer manually by using CMake. To
9379
do that, run
9480
@@ -97,7 +83,7 @@ def print_help():
9783
3. make (or mingw32-make/vcbuild/msbuild on Windows)
9884
9985
and set up the location to the native optimizer in ~/.emscripten
100-
''' % '\n '.join(all_tasks))
86+
''' % '\n '.join(all_tasks)
10187

10288

10389
def build(src, result_libs, args=[]):
@@ -125,28 +111,22 @@ def build(src, result_libs, args=[]):
125111
shared.exit_with_error('not seeing that requested library %s has been built because file %s does not exist' % (lib, shared.Cache.get_path(lib)))
126112

127113

128-
def build_port(port_name, lib_name, params):
129-
build(C_BARE, [lib_name] if lib_name else [], params)
114+
def build_port(port_name, lib_name, params, extra_source=''):
115+
build(extra_source + '\n' + C_BARE, [lib_name] if lib_name else [], params)
130116

131117

132118
def main():
133119
global force
134-
parser = argparse.ArgumentParser(description=__doc__, usage="%(prog)s [operation] [targets ...]",
135-
add_help=False)
136-
parser.add_argument('--help', '-h', action='store_true', help='print help message')
120+
parser = argparse.ArgumentParser(description=__doc__, usage=get_usage())
137121
parser.add_argument('--lto', action='store_true', help='build bitcode object for LTO')
138122
parser.add_argument('--pic', action='store_true',
139123
help='build relocatable objects for suitable for dynamic linking')
140124
parser.add_argument('--force', action='store_true',
141125
help='force rebuild of target (by removing it first)')
142-
parser.add_argument('operation')
143-
parser.add_argument('targets', nargs='+')
126+
parser.add_argument('operation', help='currently only "build" is supported')
127+
parser.add_argument('targets', nargs='+', help='see above')
144128
args = parser.parse_args()
145129

146-
if args.help:
147-
print_help()
148-
return 0
149-
150130
if args.operation != 'build':
151131
shared.exit_with_error('unfamiliar operation: ' + args.operation)
152132

@@ -215,7 +195,7 @@ def main():
215195
elif what == 'native_optimizer':
216196
build(C_BARE, ['optimizer.2.exe'], ['-O2', '-s', 'WASM=0'])
217197
elif what == 'icu':
218-
build_port('icu', libname('libicuuc'), ['-s', 'USE_ICU=1'])
198+
build_port('icu', libname('libicuuc'), ['-s', 'USE_ICU=1'], '#include "unicode/ustring.h"')
219199
elif what == 'zlib':
220200
build_port('zlib', 'libz.a', ['-s', 'USE_ZLIB=1'])
221201
elif what == 'bzip2':
@@ -239,9 +219,9 @@ def main():
239219
elif what == 'sdl2-image':
240220
build_port('sdl2-image', libname('libSDL2_image'), ['-s', 'USE_SDL=2', '-s', 'USE_SDL_IMAGE=2'])
241221
elif what == 'sdl2-image-png':
242-
build_port('sdl2-image', libname('libSDL2_image'), ['-s', 'USE_SDL=2', '-s', 'USE_SDL_IMAGE=2', '-s', 'SDL2_IMAGE_FORMATS=["png"]'])
222+
build_port('sdl2-image', libname('libSDL2_image_png'), ['-s', 'USE_SDL=2', '-s', 'USE_SDL_IMAGE=2', '-s', 'SDL2_IMAGE_FORMATS=["png"]'])
243223
elif what == 'sdl2-image-jpg':
244-
build_port('sdl2-image', libname('libSDL2_image'), ['-s', 'USE_SDL=2', '-s', 'USE_SDL_IMAGE=2', '-s', 'SDL2_IMAGE_FORMATS=["jpg"]'])
224+
build_port('sdl2-image', libname('libSDL2_image_jpg'), ['-s', 'USE_SDL=2', '-s', 'USE_SDL_IMAGE=2', '-s', 'SDL2_IMAGE_FORMATS=["jpg"]'])
245225
elif what == 'sdl2-net':
246226
build_port('sdl2-net', libname('libSDL2_net'), ['-s', 'USE_SDL=2', '-s', 'USE_SDL_NET=2'])
247227
elif what == 'sdl2-mixer':

tests/runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ def do_run(self, src, expected_output, args=[], output_nicerizer=None,
11871187
def get_freetype_library(self):
11881188
if '-Werror' in self.emcc_args:
11891189
self.emcc_args.remove('-Werror')
1190-
return self.get_library('freetype', os.path.join('objs', '.libs', 'libfreetype.a'), configure_args=['--disable-shared'])
1190+
return self.get_library('freetype', os.path.join('objs', '.libs', 'libfreetype.a'), configure_args=['--disable-shared', '--without-zlib'])
11911191

11921192
def get_poppler_library(self):
11931193
# The fontconfig symbols are all missing from the poppler build

tests/test_browser.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3221,7 +3221,9 @@ def test_cocos2d_hello(self):
32213221
cocos2d_root = os.path.join(system_libs.Ports.get_build_dir(), 'cocos2d')
32223222
preload_file = os.path.join(cocos2d_root, 'samples', 'HelloCpp', 'Resources') + '@'
32233223
self.btest('cocos2d_hello.cpp', reference='cocos2d_hello.png', reference_slack=1,
3224-
args=['-s', 'USE_COCOS2D=3', '-s', 'ERROR_ON_UNDEFINED_SYMBOLS=0', '--std=c++11', '--preload-file', preload_file, '--use-preload-plugins'],
3224+
args=['-s', 'USE_COCOS2D=3', '-s', 'ERROR_ON_UNDEFINED_SYMBOLS=0', '--std=c++11',
3225+
'--preload-file', preload_file, '--use-preload-plugins',
3226+
'-Wno-inconsistent-missing-override'],
32253227
message='You should see Cocos2d logo')
32263228

32273229
def test_async(self):

tests/test_other.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,10 @@ def verify_includes(stderr):
798798
includes = stderr[start:end]
799799
includes = [i.strip() for i in includes.splitlines()[1:-1]]
800800
for i in includes:
801-
self.assertContained(path_from_root('system'), i)
801+
if shared.Cache.dirname in i:
802+
self.assertContained(shared.Cache.dirname, i)
803+
else:
804+
self.assertContained(path_from_root('system'), i)
802805

803806
err = run_process([PYTHON, EMCC, path_from_root('tests', 'hello_world.c'), '-v'], stderr=PIPE).stderr
804807
verify_includes(err)

tools/ports/boost_headers.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,25 @@ def create():
2525

2626
# includes
2727
source_path_include = os.path.join(ports.get_dir(), 'boost_headers', 'boost')
28-
dest_path_include = os.path.join(ports.get_build_dir(), 'boost_headers', 'boost')
28+
dest_path_include = os.path.join(ports.get_include_dir(), 'boost')
29+
shared.try_delete(dest_path_include)
2930
shutil.copytree(source_path_include, dest_path_include)
3031

3132
# write out a dummy cpp file, to create an empty library
3233
# this is needed as emscripted ports expect this, even if it is not used
33-
open(os.path.join(ports.get_build_dir(), 'boost_headers', 'dummy.cpp'), 'w').write('static void dummy() {}')
34+
dummy_file = os.path.join(ports.get_build_dir(), 'boost_headers', 'dummy.cpp')
35+
shared.safe_ensure_dirs(os.path.dirname(dummy_file))
36+
with open(dummy_file, 'w') as f:
37+
f.write('static void dummy() {}')
3438

3539
commands = []
3640
o_s = []
37-
o = os.path.join(ports.get_build_dir(), 'boost_headers', 'dummy.cpp.o')
38-
command = [shared.PYTHON, shared.EMCC, '-c', os.path.join(ports.get_build_dir(), 'boost_headers', 'dummy.cpp'), '-o', o]
41+
obj = dummy_file + '.o'
42+
command = [shared.PYTHON, shared.EMCC, '-c', dummy_file, '-o', obj]
3943
commands.append(command)
4044
ports.run_commands(commands)
4145
final = os.path.join(ports.get_build_dir(), 'boost_headers', libname)
42-
o_s.append(o)
46+
o_s.append(obj)
4347
ports.create_lib(final, o_s)
4448
return final
4549

@@ -53,7 +57,7 @@ def clear(ports, shared):
5357
def process_args(ports, args, settings, shared):
5458
if settings.USE_BOOST_HEADERS == 1:
5559
get(ports, settings, shared)
56-
args += ['-Xclang', '-isystem' + os.path.join(ports.get_build_dir(), 'boost_headers'), '-DBOOST_ALL_NO_LIB']
60+
args += ['-DBOOST_ALL_NO_LIB']
5761
return args
5862

5963

tools/ports/bullet.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,20 @@ def create():
2626

2727
shutil.rmtree(dest_path, ignore_errors=True)
2828
shutil.copytree(source_path, dest_path)
29-
3029
src_path = os.path.join(dest_path, 'bullet', 'src')
30+
src_path = os.path.join(dest_path, 'bullet', 'src')
31+
32+
dest_include_path = os.path.join(ports.get_include_dir(), 'bullet')
33+
for base, dirs, files in os.walk(src_path):
34+
for f in files:
35+
if os.path.splitext(f)[1] != '.h':
36+
continue
37+
fullpath = os.path.join(base, f)
38+
relpath = os.path.relpath(fullpath, src_path)
39+
target = os.path.join(dest_include_path, relpath)
40+
shared.safe_ensure_dirs(os.path.dirname(target))
41+
shutil.copyfile(fullpath, target)
42+
3143
includes = []
3244
for root, dirs, files in os.walk(src_path, topdown=False):
3345
for dir in dirs:
@@ -47,7 +59,7 @@ def clear(ports, shared):
4759
def process_args(ports, args, settings, shared):
4860
if settings.USE_BULLET == 1:
4961
get(ports, settings, shared)
50-
args += ['-Xclang', '-isystem' + os.path.join(shared.Cache.get_path('ports-builds'), 'bullet', 'bullet', 'src')]
62+
args += ['-I' + os.path.join(ports.get_include_dir(), 'bullet')]
5163
return args
5264

5365

tools/ports/bzip2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def create():
4343

4444
final = os.path.join(ports.get_build_dir(), 'bzip2', 'libbz2.a')
4545
ports.create_lib(final, o_s)
46+
ports.install_headers(source_path)
4647
return final
4748

4849
return [shared.Cache.get('libbz2.a', create, what='port')]
@@ -55,7 +56,6 @@ def clear(ports, shared):
5556
def process_args(ports, args, settings, shared):
5657
if settings.USE_BZIP2 == 1:
5758
get(ports, settings, shared)
58-
args += ['-Xclang', '-isystem' + os.path.join(shared.Cache.get_path('ports-builds'), 'bzip2')]
5959
return args
6060

6161

tools/ports/cocos2d.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ def create():
2828
cocos2d_root = os.path.join(cocos2d_src, 'Cocos2d-' + TAG)
2929
cocos2dx_root = os.path.join(cocos2d_root, 'cocos2dx')
3030
cocos2dx_src = make_source_list(cocos2d_root, cocos2dx_root)
31-
cocos2dx_includes = make_includes(cocos2d_root, cocos2dx_root)
31+
cocos2dx_includes = make_includes(cocos2d_root)
3232

3333
cocos2d_build = os.path.join(ports.get_build_dir(), 'cocos2d')
34+
shared.try_delete(os.path.join(cocos2d_build, 'samples'))
3435
shutil.copytree(os.path.join(cocos2d_root, 'samples', 'Cpp'),
3536
os.path.join(cocos2d_build, 'samples'))
3637

@@ -41,8 +42,7 @@ def create():
4142
shared.safe_ensure_dirs(os.path.dirname(o))
4243
command = [shared.PYTHON,
4344
shared.EMCC,
44-
'-c',
45-
os.path.join(cocos2dx_root, 'proj.emscripten', src),
45+
'-c', src,
4646
'-Wno-overloaded-virtual',
4747
'-Wno-deprecated-declarations',
4848
'-D__CC_PLATFORM_FILEUTILS_CPP__',
@@ -68,6 +68,11 @@ def create():
6868
ports.run_commands(commands)
6969
final = os.path.join(cocos2d_build, libname)
7070
ports.create_lib(final, o_s)
71+
72+
for dirname in cocos2dx_includes:
73+
target = os.path.join('cocos2d', os.path.relpath(dirname, cocos2d_root))
74+
ports.install_header_dir(dirname, target=target)
75+
7176
return final
7277

7378
return [shared.Cache.get(libname, create, what='port')]
@@ -86,13 +91,8 @@ def process_dependencies(settings):
8691
def process_args(ports, args, settings, shared):
8792
if settings.USE_COCOS2D == 3:
8893
get(ports, settings, shared)
89-
cocos2d_build = os.path.join(ports.get_dir(), 'cocos2d')
90-
cocos2d_root = os.path.join(cocos2d_build, 'Cocos2d-' + TAG)
91-
cocos2dx_root = os.path.join(cocos2d_root, 'cocos2dx')
92-
cocos2dx_includes = make_includes(cocos2d_root, cocos2dx_root)
93-
args += ['-Xclang']
94-
for include in cocos2dx_includes:
95-
args.append('-isystem' + include)
94+
for include in make_includes(os.path.join(ports.get_include_dir(), 'cocos2d')):
95+
args.append('-I' + include)
9696
return args
9797

9898

@@ -133,30 +133,30 @@ def add_makefile(makefile):
133133
return sources
134134

135135

136-
def make_includes(cocos2d_root, cocos2dx_root):
137-
return [os.path.join(cocos2d_root, 'CocosDenshion', 'include'),
138-
os.path.join(cocos2d_root, 'extensions'),
139-
os.path.join(cocos2d_root, 'extensions', 'AssetsManager'),
140-
os.path.join(cocos2d_root, 'extensions', 'CCArmature'),
141-
os.path.join(cocos2d_root, 'extensions', 'CCBReader'),
142-
os.path.join(cocos2d_root, 'extensions', 'GUI', 'CCControlExtension'),
143-
os.path.join(cocos2d_root, 'extensions', 'GUI', 'CCEditBox'),
144-
os.path.join(cocos2d_root, 'extensions', 'GUI', 'CCScrollView'),
145-
os.path.join(cocos2d_root, 'extensions', 'network'),
146-
os.path.join(cocos2d_root, 'extensions', 'Components'),
147-
os.path.join(cocos2d_root, 'extensions', 'LocalStorage'),
148-
os.path.join(cocos2d_root, 'extensions', 'physics_nodes'),
149-
os.path.join(cocos2d_root, 'extensions', 'spine'),
150-
os.path.join(cocos2d_root, 'external'),
151-
os.path.join(cocos2d_root, 'external', 'chipmunk', 'include', 'chipmunk'),
152-
cocos2dx_root,
153-
os.path.join(cocos2dx_root, 'cocoa'),
154-
os.path.join(cocos2dx_root, 'include'),
155-
os.path.join(cocos2dx_root, 'kazmath', 'include'),
156-
os.path.join(cocos2dx_root, 'platform'),
157-
os.path.join(cocos2dx_root, 'platform', 'emscripten'),
158-
os.path.join(cocos2dx_root, 'platform', 'third_party', 'linux', 'libfreetype2'),
159-
os.path.join(cocos2dx_root, 'platform', 'third_party', 'common', 'etc'),
160-
os.path.join(cocos2dx_root, 'platform', 'third_party', 'emscripten', 'libtiff', 'include'),
161-
os.path.join(cocos2dx_root, 'platform', 'third_party', 'emscripten', 'libjpeg'),
162-
os.path.join(cocos2dx_root, 'platform', 'third_party', 'emscripten', 'libwebp')]
136+
def make_includes(root):
137+
return [os.path.join(root, 'CocosDenshion', 'include'),
138+
os.path.join(root, 'extensions'),
139+
os.path.join(root, 'extensions', 'AssetsManager'),
140+
os.path.join(root, 'extensions', 'CCArmature'),
141+
os.path.join(root, 'extensions', 'CCBReader'),
142+
os.path.join(root, 'extensions', 'GUI', 'CCControlExtension'),
143+
os.path.join(root, 'extensions', 'GUI', 'CCEditBox'),
144+
os.path.join(root, 'extensions', 'GUI', 'CCScrollView'),
145+
os.path.join(root, 'extensions', 'network'),
146+
os.path.join(root, 'extensions', 'Components'),
147+
os.path.join(root, 'extensions', 'LocalStorage'),
148+
os.path.join(root, 'extensions', 'physics_nodes'),
149+
os.path.join(root, 'extensions', 'spine'),
150+
os.path.join(root, 'external'),
151+
os.path.join(root, 'external', 'chipmunk', 'include', 'chipmunk'),
152+
os.path.join(root, 'cocos2dx'),
153+
os.path.join(root, 'cocos2dx', 'cocoa'),
154+
os.path.join(root, 'cocos2dx', 'include'),
155+
os.path.join(root, 'cocos2dx', 'kazmath', 'include'),
156+
os.path.join(root, 'cocos2dx', 'platform'),
157+
os.path.join(root, 'cocos2dx', 'platform', 'emscripten'),
158+
os.path.join(root, 'cocos2dx', 'platform', 'third_party', 'linux', 'libfreetype2'),
159+
os.path.join(root, 'cocos2dx', 'platform', 'third_party', 'common', 'etc'),
160+
os.path.join(root, 'cocos2dx', 'platform', 'third_party', 'emscripten', 'libtiff', 'include'),
161+
os.path.join(root, 'cocos2dx', 'platform', 'third_party', 'emscripten', 'libjpeg'),
162+
os.path.join(root, 'cocos2dx', 'platform', 'third_party', 'emscripten', 'libwebp')]

tools/ports/freetype.py

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

66
import os
77
import shutil
8-
from subprocess import Popen
98

109
TAG = 'version_1'
1110
HASH = '0d0b1280ba0501ad0a23cf1daa1f86821c722218b59432734d3087a89acd22aabd5c3e5e1269700dcd41e87073046e906060f167c032eb91a3ac8c5808a02783'
@@ -103,8 +102,10 @@ def create():
103102
ports.run_commands(commands)
104103
final = os.path.join(ports.get_build_dir(), 'freetype', 'libfreetype.a')
105104
shared.try_delete(final)
106-
Popen([shared.LLVM_AR, 'rc', final] + o_s).communicate()
107-
assert os.path.exists(final)
105+
shared.run_process([shared.LLVM_AR, 'rc', final] + o_s)
106+
107+
ports.install_header_dir(os.path.join(dest_path, 'include'),
108+
target=os.path.join('freetype2', 'freetype'))
108109
return final
109110

110111
return [shared.Cache.get('libfreetype.a', create, what='port')]
@@ -117,7 +118,8 @@ def clear(ports, shared):
117118
def process_args(ports, args, settings, shared):
118119
if settings.USE_FREETYPE == 1:
119120
get(ports, settings, shared)
120-
args += ['-Xclang', '-isystem' + os.path.join(shared.Cache.get_path('ports-builds'), 'freetype/include')]
121+
args += ['-I' + os.path.join(ports.get_include_dir(), 'freetype2', 'freetype')]
122+
121123
return args
122124

123125

0 commit comments

Comments
 (0)