Can build simple Swift executables.

pull/330/head
Jussi Pakkanen 9 years ago
parent d5bdfb5906
commit d92504797f
  1. 86
      compilers.py
  2. 21
      environment.py
  3. 5
      interpreter.py
  4. 1
      run_tests.py
  5. 3
      test cases/swift/1 exe/meson.build
  6. 1
      test cases/swift/1 exe/prog.swift

@ -92,6 +92,11 @@ mono_buildtype_args = {'plain' : [],
'debugoptimized': ['-debug', '-optimize+'],
'release' : ['-optimize+']}
swift_buildtype_args = {'plain' : [],
'debug' : ['-g'],
'debugoptimized': ['-g', '-O'],
'release' : ['-O']}
gnu_winlibs = ['-lkernel32', '-luser32', '-lgdi32', '-lwinspool', '-lshell32',
'-lole32', '-loleaut32', '-luuid', '-lcomdlg32', '-ladvapi32']
@ -948,6 +953,87 @@ class RustCompiler(Compiler):
def get_buildtype_args(self, buildtype):
return rust_buildtype_args[buildtype]
class SwiftCompiler(Compiler):
def __init__(self, exelist, version):
super().__init__(exelist, version)
self.version = version
self.id = 'llvm'
self.language = 'swift'
self.is_cross = False
def get_id(self):
return self.id
def get_linker_exelist(self):
return self.exelist
def name_string(self):
return ' '.join(self.exelist)
def needs_static_linker(self):
return True
def get_exelist(self):
return self.exelist
def get_werror_args(self):
return ['--fatal-warnings']
def get_language(self):
return self.language
def get_dependency_gen_args(self, outtarget, outfile):
return ['-emit-dependencies']
def get_depfile_suffix(self):
return 'd'
def get_output_args(self, target):
return ['-o', target]
def get_linker_output_args(self, target):
return ['-o', target]
def get_warn_args(self, level):
return []
def get_buildtype_args(self, buildtype):
return swift_buildtype_args[buildtype]
def get_buildtype_linker_args(self, buildtype):
return []
def get_std_exe_link_args(self):
return ['-emit-executable']
def build_rpath_args(self, *args):
return [] # FIXME
def get_include_args(self, dirname):
return ['-I' + dirname]
def get_compile_only_args(self):
return ['-c']
def sanity_check(self, work_dir):
src = 'swifttest.swift'
source_name = os.path.join(work_dir, src)
output_name = os.path.join(work_dir, 'swifttest')
ofile = open(source_name, 'w')
ofile.write('''1 + 2
''')
ofile.close()
pc = subprocess.Popen(self.exelist + ['-emit-executable', '-o', output_name, src], cwd=work_dir)
pc.wait()
if pc.returncode != 0:
raise EnvironmentException('Swift compiler %s can not compile programs.' % self.name_string())
if subprocess.call(output_name) != 0:
raise EnvironmentException('Executables created by Swift compiler %s are not runnable.' % self.name_string())
def can_compile(self, filename):
suffix = filename.split('.')[-1]
return suffix in ('swift')
class VisualStudioCCompiler(CCompiler):
std_warn_args = ['/W3']
std_opt_args= ['/O2']

@ -19,6 +19,10 @@ import configparser
build_filename = 'meson.build'
class EnvironmentException(coredata.MesonException):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def find_coverage_tools():
gcovr_exe = 'gcovr'
lcov_exe = 'lcov'
@ -457,6 +461,23 @@ class Environment():
return RustCompiler(exelist, version)
raise EnvironmentException('Unknown compiler "' + ' '.join(exelist) + '"')
def detect_swift_compiler(self):
exelist = ['swiftc']
try:
p = subprocess.Popen(exelist + ['-v'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except OSError:
raise EnvironmentException('Could not execute Swift compiler "%s"' % ' '.join(exelist))
(_, err) = p.communicate()
err = err.decode()
vmatch = re.search(Environment.version_regex, err)
if vmatch:
version = vmatch.group(0)
else:
version = 'unknown version'
if 'Swift' in err:
return SwiftCompiler(exelist, version)
raise EnvironmentException('Unknown compiler "' + ' '.join(exelist) + '"')
def detect_static_linker(self, compiler):
if compiler.is_cross:
linker = self.cross_info.config['binaries']['ar']

@ -1474,6 +1474,11 @@ class Interpreter():
comp = self.environment.detect_fortran_compiler(False)
if need_cross_compiler:
cross_comp = self.environment.detect_fortran_compiler(True)
elif lang == 'swift':
comp = self.environment.detect_swift_compiler()
if need_cross_compiler:
raise InterpreterException('Cross compilation with Swift is not working yet.')
#cross_comp = self.environment.detect_fortran_compiler(True)
else:
raise InvalidCode('Tried to use unknown language "%s".' % lang)
comp.sanity_check(self.environment.get_scratch_dir())

@ -254,6 +254,7 @@ def detect_tests_to_run():
all_tests.append(('rust', gather_tests('test cases/rust'), False if shutil.which('rustc') else True))
all_tests.append(('objective c', gather_tests('test cases/objc'), False if not mesonlib.is_windows() else True))
all_tests.append(('fortran', gather_tests('test cases/fortran'), False if shutil.which('gfortran') else True))
all_tests.append(('swift', gather_tests('test cases/swift'), False if shutil.which('swiftc') else True))
return all_tests
def run_tests(extra_args):

@ -0,0 +1,3 @@
project('swift exe', 'swift')
test('swifttest', executable('swifttest', 'prog.swift'))

@ -0,0 +1 @@
print("Swift executable is working.")
Loading…
Cancel
Save