Skip to content

Commit 4bda788

Browse files
committed
Build a complete sysroot in the cache directory
Rather than adding various include paths, copy any needed headers into the sysroot along with any libraries. This means that emscripten can work a lot more like the traditional cross compiler (e.g. clang -target=xxx --sysroot=yyy), and we can start to think of the emscripten driver as a seperate thing to the sysroot. Fixes: #9353
1 parent d0e647b commit 4bda788

File tree

12 files changed

+103
-48
lines changed

12 files changed

+103
-48
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ Current Trunk
2727
may notice that `RelWithDebInfo` will now include debug info (it did not
2828
before, which appears to have been an error), and that `Release` will
2929
use `-O3` instead of `-O2` (which is a better choice anyhow). (#13083)
30+
- Emscripten now builds a complete sysroot insde the EM_CACHE directory.
31+
This includes the system headers which get copied into place there rather
32+
than adding a sequence of extra include directories.
3033

3134
2.0.11: 12/17/2020
3235
------------------

embuilder.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ def main():
171171
if force:
172172
library.erase()
173173
library.get_path()
174+
elif what == 'sysroot':
175+
if force:
176+
shared.Cache.erase_file('sysroot_install.stamp')
177+
system_libs.ensure_sysroot()
174178
elif what == 'struct_info':
175179
if force:
176180
shared.Cache.erase_file('generated_struct_info.json')

emcc.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,12 +1331,6 @@ def filter_out_duplicate_dynamic_libs(inputs):
13311331
'_emscripten_stack_get_end',
13321332
'_emscripten_stack_set_limits']
13331333

1334-
if not compile_only and not options.post_link:
1335-
ldflags = shared.emsdk_ldflags(newargs)
1336-
for f in ldflags:
1337-
newargs.append(f)
1338-
add_link_flag(len(newargs), f)
1339-
13401334
# SSEx is implemented on top of SIMD128 instruction set, but do not pass SSE flags to LLVM
13411335
# so it won't think about generating native x86 SSE code.
13421336
newargs = [x for x in newargs if x not in shared.SIMD_INTEL_FEATURE_TOWER and x not in shared.SIMD_NEON_FLAGS]
@@ -1950,6 +1944,7 @@ def is_link_flag(flag):
19501944

19511945
compile_args = [a for a in newargs if a and not is_link_flag(a)]
19521946
cflags = calc_cflags(options)
1947+
system_libs.ensure_sysroot()
19531948
system_libs.add_ports_cflags(cflags, shared.Settings)
19541949

19551950
def use_cxx(src):
@@ -1976,9 +1971,8 @@ def get_compiler(cxx):
19761971
return CC
19771972

19781973
def get_clang_command(src_file):
1979-
cxx = use_cxx(src_file)
1980-
per_file_cflags = shared.get_cflags(args, cxx)
1981-
return get_compiler(cxx) + cflags + per_file_cflags + compile_args + [src_file]
1974+
per_file_cflags = shared.get_cflags(args)
1975+
return get_compiler(use_cxx(src_file)) + cflags + per_file_cflags + compile_args + [src_file]
19821976

19831977
def get_clang_command_asm(src_file):
19841978
asflags = shared.get_clang_flags()
@@ -2070,6 +2064,10 @@ def compile_source_file(i, input_file):
20702064
if specified_target and specified_target.startswith('-'):
20712065
exit_with_error('invalid output filename: `%s`' % specified_target)
20722066

2067+
ldflags = shared.emsdk_ldflags(newargs)
2068+
for f in ldflags:
2069+
add_link_flag(sys.maxsize, f)
2070+
20732071
using_lld = not (link_to_object and shared.Settings.LTO)
20742072
link_flags = filter_link_flags(link_flags, using_lld)
20752073

src/struct_info.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,7 +1454,7 @@
14541454
]
14551455
},
14561456
{
1457-
"file": "../lib/libc/musl/src/internal/pthread_impl.h",
1457+
"file": "system/lib/libc/musl/src/internal/pthread_impl.h",
14581458
"structs": {
14591459
"pthread": [
14601460
"threadStatus",
@@ -1477,7 +1477,7 @@
14771477
"defines": ["__ATTRP_C11_THREAD"]
14781478
},
14791479
{
1480-
"file": "../lib/libc/musl/src/internal/libc.h",
1480+
"file": "system/lib/libc/musl/src/internal/libc.h",
14811481
"structs": {
14821482
"libc": [
14831483
"global_locale"

system/lib/fetch/asmfs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <emscripten/emscripten.h>
1616
#include <emscripten/fetch.h>
1717
#include <emscripten/threading.h>
18-
#include <libc/fcntl.h>
18+
#include <fcntl.h>
1919
#include <math.h>
2020
#include <string.h>
2121
#include <sys/stat.h>

tests/test_other.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,10 @@ def test_emcc_asm_v_wasm(self):
480480
def test_emcc_cflags(self):
481481
output = self.run_process([EMCC, '--cflags'], stdout=PIPE)
482482
flags = output.stdout.strip()
483-
self.assertContained(shared.shlex_join(shared.emsdk_cflags([], False)), flags)
483+
self.assertContained(shared.shlex_join(shared.emsdk_cflags([])), flags)
484484
output = self.run_process([EMXX, '--cflags'], stdout=PIPE)
485485
flags = output.stdout.strip()
486-
self.assertContained(shared.shlex_join(shared.emsdk_cflags([], True)), flags)
486+
self.assertContained(shared.shlex_join(shared.emsdk_cflags([])), flags)
487487
# check they work
488488
cmd = [CLANG_CXX, path_from_root('tests', 'hello_world.cpp')] + shlex.split(flags.replace('\\', '\\\\')) + ['-c', '-o', 'out.o']
489489
self.run_process(cmd)

tests/test_sanity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,10 +691,10 @@ def test_embuilder_wasm_backend(self):
691691
# the --lto flag makes us build wasm-bc
692692
self.do([EMCC, '--clear-cache'])
693693
self.run_process([EMBUILDER, 'build', 'libemmalloc'])
694-
self.assertExists(os.path.join(config.CACHE, 'wasm'))
694+
self.assertExists(os.path.join(config.CACHE, 'sysroot', 'lib', 'wasm32-emscripten'))
695695
self.do([EMCC, '--clear-cache'])
696696
self.run_process([EMBUILDER, 'build', 'libemmalloc', '--lto'])
697-
self.assertExists(os.path.join(config.CACHE, 'wasm-lto'))
697+
self.assertExists(os.path.join(config.CACHE, 'sysroot', 'lib', 'wasm32-emscripten', 'lto'))
698698

699699
def test_binaryen_version(self):
700700
restore_and_set_up()

tools/cache.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,32 @@ def erase(self):
8484
def get_path(self, name):
8585
return os.path.join(self.dirname, name)
8686

87+
def get_sysroot_dir(self, absolute):
88+
if absolute:
89+
return os.path.join(self.dirname, 'sysroot')
90+
return 'sysroot'
91+
8792
def get_include_dir(self):
88-
return os.path.join(self.dirname, 'include')
93+
return os.path.join(self.get_sysroot_dir(absolute=True), 'include')
8994

90-
def get_lib_dir(self):
91-
subdir = 'wasm'
95+
def get_lib_dir(self, absolute):
96+
path = os.path.join(self.get_sysroot_dir(absolute=absolute), 'lib')
97+
if shared.Settings.MEMORY64:
98+
path = os.path.join(path, 'wasm64-emscripten')
99+
else:
100+
path = os.path.join(path, 'wasm32-emscripten')
101+
# if relevant, use a subdir of the cache
102+
subdir = []
92103
if shared.Settings.LTO:
93-
subdir += '-lto'
104+
subdir.append('lto')
94105
if shared.Settings.RELOCATABLE:
95-
subdir += '-pic'
96-
if shared.Settings.MEMORY64:
97-
subdir += '-memory64'
98-
return subdir
106+
subdir.append('pic')
107+
if subdir:
108+
path = os.path.join(path, '-'.join(subdir))
109+
return path
99110

100111
def get_lib_name(self, name):
101-
return os.path.join(self.get_lib_dir(), name)
112+
return os.path.join(self.get_lib_dir(absolute=False), name)
102113

103114
def erase_lib(self, name):
104115
self.erase_file(self.get_lib_name(name))

tools/gen_struct_info.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ def inspect_code(headers, cpp_opts, structs, defines):
246246
'-O0',
247247
'-Werror',
248248
'-Wno-format',
249+
'-I', shared.path_from_root(),
249250
'-s', 'BOOTSTRAPPING_STRUCT_INFO=1',
250251
'-s', 'WARN_ON_UNDEFINED_SYMBOLS=0',
251252
'-s', 'STRICT=1',

tools/ports/regal.py

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

4747
# includes
4848
source_path_include = os.path.join(ports.get_dir(), 'regal', 'regal-' + TAG, 'include', 'GL')
49-
ports.install_header_dir(source_path_include)
49+
ports.install_headers(source_path_include, target='GL')
5050

5151
# build
5252
srcs_regal = ['regal/RegalShaderInstance.cpp',

0 commit comments

Comments
 (0)