Invoke Rust via wrapper script.

pull/15/head
Jussi Pakkanen 11 years ago
parent 147e04ac80
commit 923ad8ab9b
  1. 9
      build.py
  2. 14
      ninjabackend.py
  3. 11
      rustrunner.py
  4. 2
      test cases/rust/1 basic/installed_files.txt
  5. 2
      test cases/rust/1 basic/meson.build

@ -137,6 +137,7 @@ class BuildTarget():
self.process_kwargs(kwargs, environment) self.process_kwargs(kwargs, environment)
if len(self.sources) == 0 and len(self.generated) == 0: if len(self.sources) == 0 and len(self.generated) == 0:
raise InvalidArguments('Build target %s has no sources.' % name) raise InvalidArguments('Build target %s has no sources.' % name)
self.validate_sources()
def process_objectlist(self, objects): def process_objectlist(self, objects):
assert(isinstance(objects, list)) assert(isinstance(objects, list))
@ -164,6 +165,14 @@ class BuildTarget():
else: else:
raise InvalidArguments('Bad source in target %s.' % self.name) raise InvalidArguments('Bad source in target %s.' % self.name)
def validate_sources(self):
if len(self.sources) > 0:
first = os.path.split(self.sources[0])[1]
(base, suffix) = os.path.splitext(first)
if suffix == '.rs':
if self.name != base:
raise InvalidArguments('In Rust targets, the first source file must be named projectname.rs.')
def get_original_kwargs(self): def get_original_kwargs(self):
return self.kwargs return self.kwargs

@ -505,14 +505,15 @@ class NinjaBackend(backends.Backend):
target_name = os.path.join(target.subdir, target.get_filename()) target_name = os.path.join(target.subdir, target.get_filename())
args = ['--crate-type'] args = ['--crate-type']
if isinstance(target, build.Executable): if isinstance(target, build.Executable):
args.append('bin') cratetype = 'bin'
elif isinstance(target, build.SharedLibrary): elif isinstance(target, build.SharedLibrary):
args.append('dylib') cratetype = 'dylib'
else: else:
raise InvalidArguments('Unknown target type for rustc.') raise InvalidArguments('Unknown target type for rustc.')
args.append(cratetype)
args += rustc.get_buildtype_args(self.environment.coredata.buildtype) args += rustc.get_buildtype_args(self.environment.coredata.buildtype)
depfile = target_name + '.d' depfile = target_name + '.d'
args += ['--out-dir', target.subdir, '-o', target.get_filename()] args += ['--out-dir', target.subdir]
args += ['--dep-info', depfile] args += ['--dep-info', depfile]
orderdeps = [os.path.join(t.subdir, t.get_filename()) for t in target.link_targets] orderdeps = [os.path.join(t.subdir, t.get_filename()) for t in target.link_targets]
linkdirs = {} linkdirs = {}
@ -527,6 +528,7 @@ class NinjaBackend(backends.Backend):
element.add_orderdep(orderdeps) element.add_orderdep(orderdeps)
element.add_item('ARGS', args) element.add_item('ARGS', args)
element.add_item('targetdep', depfile) element.add_item('targetdep', depfile)
element.add_item('cratetype', cratetype)
element.write(outfile) element.write(outfile)
def generate_static_link_rules(self, is_cross, outfile): def generate_static_link_rules(self, is_cross, outfile):
@ -613,9 +615,13 @@ class NinjaBackend(backends.Backend):
def generate_rust_compile_rules(self, compiler, outfile): def generate_rust_compile_rules(self, compiler, outfile):
rule = 'rule %s_COMPILER\n' % compiler.get_language() rule = 'rule %s_COMPILER\n' % compiler.get_language()
invoc = ' '.join([ninja_quote(i) for i in compiler.get_exelist()]) invoc = ' '.join([ninja_quote(i) for i in compiler.get_exelist()])
command = ' command = %s $ARGS $in\n' % invoc command = ' command = %s %s $out $cratetype %s $ARGS $in\n' % \
(ninja_quote(sys.executable),
ninja_quote(os.path.join(os.path.split(__file__)[0], "rustrunner.py")),
invoc)
description = ' description = Compiling Rust source $in.\n' description = ' description = Compiling Rust source $in.\n'
depfile = ' depfile = $out.d\n' depfile = ' depfile = $out.d\n'
depstyle = ' deps = gcc\n' depstyle = ' deps = gcc\n'
outfile.write(rule) outfile.write(rule)
outfile.write(command) outfile.write(command)

@ -28,12 +28,11 @@ def delete_old_crates(target_name, target_type):
if target_type == 'dylib': if target_type == 'dylib':
(base, suffix) = os.path.splitext(target_name) (base, suffix) = os.path.splitext(target_name)
crates = glob.glob(base + '-*' + suffix) crates = glob.glob(base + '-*' + suffix)
crates = [(os.stat(i).st_ctime, i) for i in crates] crates = [(os.stat(i).st_mtime, i) for i in crates]
[os.unlink(c[1]) for c in sorted(crates)[:-1]] [os.unlink(c[1]) for c in sorted(crates)[:-1]]
def invoke_rust(rustc_command): def invoke_rust(rustc_command):
return 0 return subprocess.call(rustc_command, shell=False)
#return subprocess.call(rustc_command, shell=False)
def touch_file(fname): def touch_file(fname):
try: try:
@ -53,6 +52,8 @@ if __name__ == '__main__':
retval = invoke_rust(rustc_command) retval = invoke_rust(rustc_command)
if retval != 0: if retval != 0:
sys.exit(retval) sys.exit(retval)
delete_old_crates(target_name, target_type) if target_type != "bin":
touch_file(target_name) delete_old_crates(target_name, target_type)
touch_file(target_name)

@ -1,4 +1,4 @@
project('rustprog', 'rust') project('rustprog', 'rust')
e = executable('rustprog', 'prog.rs', install : true) e = executable('prog', 'prog.rs', install : true)
test('rusttest', e) test('rusttest', e)

Loading…
Cancel
Save