rust.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Copyright 2012-2017 The Meson development team
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. # Unless required by applicable law or agreed to in writing, software
  7. # distributed under the License is distributed on an "AS IS" BASIS,
  8. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. # See the License for the specific language governing permissions and
  10. # limitations under the License.
  11. import subprocess, os.path
  12. from ..mesonlib import EnvironmentException, Popen_safe
  13. from .compilers import Compiler, rust_buildtype_args
  14. class RustCompiler(Compiler):
  15. def __init__(self, exelist, version):
  16. self.language = 'rust'
  17. super().__init__(exelist, version)
  18. self.id = 'rustc'
  19. def needs_static_linker(self):
  20. return False
  21. def name_string(self):
  22. return ' '.join(self.exelist)
  23. def sanity_check(self, work_dir, environment):
  24. source_name = os.path.join(work_dir, 'sanity.rs')
  25. output_name = os.path.join(work_dir, 'rusttest')
  26. with open(source_name, 'w') as ofile:
  27. ofile.write('''fn main() {
  28. }
  29. ''')
  30. pc = subprocess.Popen(self.exelist + ['-o', output_name, source_name], cwd=work_dir)
  31. pc.wait()
  32. if pc.returncode != 0:
  33. raise EnvironmentException('Rust compiler %s can not compile programs.' % self.name_string())
  34. if subprocess.call(output_name) != 0:
  35. raise EnvironmentException('Executables created by Rust compiler %s are not runnable.' % self.name_string())
  36. def get_dependency_gen_args(self, outfile):
  37. return ['--dep-info', outfile]
  38. def get_buildtype_args(self, buildtype):
  39. return rust_buildtype_args[buildtype]
  40. def build_rpath_args(self, build_dir, from_dir, rpath_paths, build_rpath, install_rpath):
  41. return self.build_unix_rpath_args(build_dir, from_dir, rpath_paths, build_rpath, install_rpath)
  42. def get_sysroot(self):
  43. cmd = self.exelist + ['--print', 'sysroot']
  44. p, stdo, stde = Popen_safe(cmd)
  45. return stdo.split('\n')[0]