automatically use libcxx when needed

This commit is contained in:
Alon Zakai 2012-01-18 11:35:00 -08:00
Родитель c381523b1c
Коммит 20ce1c2c6e
4 изменённых файлов: 22 добавлений и 8 удалений

8
emcc
Просмотреть файл

@ -469,8 +469,8 @@ try:
# libcxx
def create_libcxx():
print >> sys.stderr, 'emcc: building libcxx for cache'
shared.Building.build_library('libcxx', EMSCRIPTEN_TEMP_DIR, EMSCRIPTEN_TEMP_DIR, ['libcxx.bc'], configure=None, copy_project=True)
return in_temp('libcxx.bc')
shared.Building.build_library('libcxx', shared.EMSCRIPTEN_TEMP_DIR, shared.EMSCRIPTEN_TEMP_DIR, ['libcxx.bc'], configure=None, copy_project=True, source_dir=shared.path_from_root('system', 'lib', 'libcxx'))
return os.path.join(shared.EMSCRIPTEN_TEMP_DIR, 'libcxx', 'libcxx.bc')
def fix_libcxx():
# libcxx probably needs sign correction. # If we are in mode 0, switch to 2. We will add our lines
shared.Settings.CORRECT_SIGNS = 1
@ -479,8 +479,8 @@ try:
libcxx_symbols = filter(lambda symbol: symbol not in dlmalloc_symbols, libcxx_symbols)
libcxx_symbols = set(libcxx_symbols)
for name, create, fix, library_symbols in [('dlmalloc', create_dlmalloc, fix_dlmalloc, dlmalloc_symbols)]:
#('libcxx', create_libcxx, fix_libcxx, libcxx_symbols)]:
for name, create, fix, library_symbols in [('dlmalloc', create_dlmalloc, fix_dlmalloc, dlmalloc_symbols),
('libcxx', create_libcxx, fix_libcxx, libcxx_symbols)]:
need = False
has = False
for input_file in input_files:

8
tests/hello_libcxx.cpp Normal file
Просмотреть файл

@ -0,0 +1,8 @@
#include <iostream>
int main()
{
std::cout << "hello, world!" << std::endl;
return 0;
}

Просмотреть файл

@ -6017,10 +6017,11 @@ elif 'sanity' in str(sys.argv):
try_delete('a.out.js')
# Building a file that *does* need dlmalloc *should* trigger cache generation, but only the first time
for filename, libname in [('hello_malloc.cpp', 'dlmalloc')]:
for filename, libname, otherlibname in [('hello_malloc.cpp', 'dlmalloc', 'libcxx'), ('hello_libcxx.cpp', 'libcxx', 'dlmalloc')]:
for i in range(3):
output = self.do([EMCC, path_from_root('tests', filename)])
assert INCLUDING_MESSAGE.replace('X', libname) in output
assert INCLUDING_MESSAGE.replace('X', otherlibname) not in output
assert (BUILDING_MESSAGE.replace('X', libname) in output) == (i == 0), 'Must only build the first time'
self.assertContained('hello, world!', run_js('a.out.js'))
assert os.path.exists(EMCC_CACHE)

Просмотреть файл

@ -378,20 +378,21 @@ class Building:
Popen(args, stdout=stdout, stderr=stderr, env=env).communicate()[0]
@staticmethod
def build_library(name, build_dir, output_dir, generated_libs, configure=['./configure'], configure_args=[], make=['make'], make_args=['-j', '2'], cache=None, cache_name=None, copy_project=False, env_init={}):
def build_library(name, build_dir, output_dir, generated_libs, configure=['./configure'], configure_args=[], make=['make'], make_args=['-j', '2'], cache=None, cache_name=None, copy_project=False, env_init={}, source_dir=None):
''' Build a library into a .bc file. We build the .bc file once and cache it for all our tests. (We cache in
memory since the test directory is destroyed and recreated for each test. Note that we cache separately
for different compilers).
This cache is just during the test runner. There is a different concept of caching as well, see |Cache|. '''
if type(generated_libs) is not list: generated_libs = [generated_libs]
if source_dir is None: source_dir = path_from_root('tests', name)
temp_dir = build_dir
if copy_project:
project_dir = os.path.join(temp_dir, name)
if os.path.exists(project_dir):
shutil.rmtree(project_dir)
shutil.copytree(path_from_root('tests', name), project_dir) # Useful in debugging sometimes to comment this out, and two lines above
shutil.copytree(source_dir, project_dir) # Useful in debugging sometimes to comment this out, and two lines above
else:
project_dir = build_dir
try:
@ -489,15 +490,19 @@ class Building:
class ret:
defs = []
undefs = []
commons = []
for line in output.split('\n'):
if len(line) == 0: continue
status, symbol = filter(lambda seg: len(seg) > 0, line.split(' '))
if status == 'U':
ret.undefs.append(symbol)
else:
elif status != 'C':
ret.defs.append(symbol)
else:
ret.commons.append(symbol)
ret.defs = set(ret.defs)
ret.undefs = set(ret.undefs)
ret.commons = set(ret.commons)
return ret
@staticmethod