Skip to content

Commit

Permalink
build libcxx into a .a archive
Browse files Browse the repository at this point in the history
  • Loading branch information
kripken committed Apr 7, 2015
1 parent 3467507 commit 301e4ad
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions tools/system_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ def build_libcxx(src_dirname, lib_filename, files, lib_opts, has_noexcept_versio
commands.append([shared.PYTHON, shared.EMXX, srcfile, '-o', o, '-std=c++11'] + opts)
o_s.append(o)
run_commands(commands)
shared.Building.link(o_s, in_temp(lib_filename))
if lib_filename.endswith('.bc'):
shared.Building.link(o_s, in_temp(lib_filename))
elif lib_filename.endswith('.a'):
shared.Building.emar('cr', in_temp(lib_filename), o_s)
else:
raise Exception('unknown suffix ' + lib_filename)
return in_temp(lib_filename)

# libc
Expand Down Expand Up @@ -615,7 +620,7 @@ def create_libcxx():
'regex.cpp',
'strstream.cpp'
]
return build_libcxx(os.path.join('system', 'lib', 'libcxx'), 'libcxx.bc', libcxx_files, ['-Oz', '-Wno-warn-absolute-paths', '-I' + shared.path_from_root('system', 'lib', 'libcxxabi', 'include')], has_noexcept_version=True)
return build_libcxx(os.path.join('system', 'lib', 'libcxx'), 'libcxx.a', libcxx_files, ['-Oz', '-Wno-warn-absolute-paths', '-I' + shared.path_from_root('system', 'lib', 'libcxxabi', 'include')], has_noexcept_version=True)

def apply_libcxx(need):
assert shared.Settings.QUANTUM_SIZE == 4, 'We do not support libc++ with QUANTUM_SIZE == 1'
Expand Down Expand Up @@ -725,15 +730,16 @@ class Dummy:
# Go over libraries to figure out which we must include
def maybe_noexcept(name):
if shared.Settings.DISABLE_EXCEPTION_CATCHING:
name += '_noexcept'
base, suffix = name.split('.')
name = base + '_noexcept' + '.' + suffix
return name
ret = []
has = need = None
for name, create, apply_, library_symbols, deps in [(maybe_noexcept('libcxx'), create_libcxx, apply_libcxx, libcxx_symbols, ['libcextra', 'libcxxabi']),
('libcextra', create_libcextra, lambda x: True, libcextra_symbols, ['libc']),
('libcxxabi', create_libcxxabi, apply_libcxxabi, libcxxabi_symbols, ['libc']),
('gl', create_gl, lambda x: True, gl_symbols, ['libc']),
('libc', create_libc, apply_libc, libc_symbols, [])]:
for name, create, apply_, library_symbols, deps in [(maybe_noexcept('libcxx.a'), create_libcxx, apply_libcxx, libcxx_symbols, ['libcextra.bc', 'libcxxabi.bc']),
('libcextra.bc', create_libcextra, lambda x: True, libcextra_symbols, ['libc.bc']),
('libcxxabi.bc', create_libcxxabi, apply_libcxxabi, libcxxabi_symbols, ['libc.bc']),
('gl.bc', create_gl, lambda x: True, gl_symbols, ['libc.bc']),
('libc.bc', create_libc, apply_libc, libc_symbols, [])]:
force_this = force_all or name in force
if not force_this:
need = set()
Expand All @@ -753,9 +759,10 @@ def maybe_noexcept(name):
if apply_(need):
# We need to build and link the library in
logging.debug('including %s' % name)
libfile = shared.Cache.get(name, create)
libfile = shared.Cache.get(name, create, extension=name.split('.')[-1])
ret.append(libfile)
force = force.union(deps)
ret.sort(key=lambda x: x.endswith('.a')) # make sure to put .a files at the end.
return ret

#---------------------------------------------------------------------------
Expand Down

0 comments on commit 301e4ad

Please sign in to comment.