Skip to content

Commit ed4c39c

Browse files
committed
Add support for "local" subdirectory of sysroot
Automatically add `sysroot/local/include` and `sysroot/local/lib` to the include and library path. Also, use this new local subdirectory by default in emscripten by passing `--prefix=<sysroot>/local`. This should make `emconfigure + make install` work out of the box. Also, add `sysroot/lib` to the library path which allows libraries installed via `./configure --prefix=<sysroot>` and then `make install` to be found automativally. Fixes: #13753
1 parent b7267b5 commit ed4c39c

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

emcc.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,11 @@ def emsdk_ldflags(user_args):
663663
if os.environ.get('EMMAKEN_NO_SDK'):
664664
return []
665665

666+
sysroot = shared.Cache.get_sysroot_dir()
666667
library_paths = [
667-
shared.Cache.get_lib_dir(absolute=True)
668+
os.path.join(sysroot, 'local', 'lib'),
669+
os.path.join(sysroot, shared.Cache.get_lib_dir()),
670+
os.path.join(sysroot, 'lib'),
668671
]
669672
ldflags = ['-L' + l for l in library_paths]
670673

@@ -680,7 +683,7 @@ def emsdk_ldflags(user_args):
680683

681684

682685
def emsdk_cflags(user_args):
683-
cflags = ['--sysroot=' + shared.Cache.get_sysroot_dir(absolute=True)]
686+
cflags = ['--sysroot=' + shared.Cache.get_sysroot_dir()]
684687

685688
def array_contains_any_of(hay, needles):
686689
for n in needles:
@@ -713,7 +716,14 @@ def array_contains_any_of(hay, needles):
713716
if array_contains_any_of(user_args, SIMD_NEON_FLAGS):
714717
cflags += ['-D__ARM_NEON__=1']
715718

716-
return cflags + ['-Xclang', '-iwithsysroot' + os.path.join('/include', 'compat')]
719+
include_paths = [
720+
'/local/include',
721+
'/include/compat',
722+
]
723+
for p in include_paths:
724+
cflags += ['-Xclang', '-iwithsysroot' + p]
725+
726+
return cflags
717727

718728

719729
def get_clang_flags():

tools/building.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ def configure(args, stdout=None, stderr=None, env=None, cflags=[], **kwargs):
319319
# compilation with emcc, but instead do builds natively with Clang. This
320320
# is a heuristic emulation that may or may not work.
321321
env['EMMAKEN_JUST_CONFIGURE'] = '1'
322+
if not any(a.startswith('--prefix') for a in args):
323+
sysroot = os.path.join(shared.Cache.get_sysroot_dir())
324+
args.append('--prefix=' + os.path.join(shared.Cache.get_sysroot_dir(), 'local'))
325+
322326
if EM_BUILD_VERBOSE >= 2:
323327
stdout = None
324328
if EM_BUILD_VERBOSE >= 1:

tools/cache.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,14 @@ def erase(self):
8888
def get_path(self, name):
8989
return os.path.join(self.dirname, name)
9090

91-
def get_sysroot_dir(self, absolute):
92-
if absolute:
93-
return os.path.join(self.dirname, 'sysroot')
94-
return 'sysroot'
91+
def get_sysroot_dir(self):
92+
return os.path.join(self.dirname, 'sysroot')
9593

9694
def get_include_dir(self):
97-
return os.path.join(self.get_sysroot_dir(absolute=True), 'include')
95+
return os.path.join(self.get_sysroot_dir(), 'include')
9896

99-
def get_lib_dir(self, absolute):
100-
path = os.path.join(self.get_sysroot_dir(absolute=absolute), 'lib')
97+
def get_lib_dir(self):
98+
path = os.path.join('sysroot', 'lib')
10199
if shared.Settings.MEMORY64:
102100
path = os.path.join(path, 'wasm64-emscripten')
103101
else:
@@ -113,7 +111,7 @@ def get_lib_dir(self, absolute):
113111
return path
114112

115113
def get_lib_name(self, name):
116-
return os.path.join(self.get_lib_dir(absolute=False), name)
114+
return os.path.join(self.get_lib_dir(), name)
117115

118116
def erase_lib(self, name):
119117
self.erase_file(self.get_lib_name(name))

0 commit comments

Comments
 (0)