From 923ad8ab9b27fcbf30f7142d2aa88e6c036c1cd1 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sun, 22 Jun 2014 19:38:47 +0300 Subject: [PATCH] Invoke Rust via wrapper script. --- build.py | 9 +++++++++ ninjabackend.py | 14 ++++++++++---- rustrunner.py | 11 ++++++----- test cases/rust/1 basic/installed_files.txt | 2 +- test cases/rust/1 basic/meson.build | 2 +- 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/build.py b/build.py index 753ede779..3a4d4e361 100644 --- a/build.py +++ b/build.py @@ -137,6 +137,7 @@ class BuildTarget(): self.process_kwargs(kwargs, environment) if len(self.sources) == 0 and len(self.generated) == 0: raise InvalidArguments('Build target %s has no sources.' % name) + self.validate_sources() def process_objectlist(self, objects): assert(isinstance(objects, list)) @@ -164,6 +165,14 @@ class BuildTarget(): else: 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): return self.kwargs diff --git a/ninjabackend.py b/ninjabackend.py index 67b26d765..cdef50a4f 100644 --- a/ninjabackend.py +++ b/ninjabackend.py @@ -505,14 +505,15 @@ class NinjaBackend(backends.Backend): target_name = os.path.join(target.subdir, target.get_filename()) args = ['--crate-type'] if isinstance(target, build.Executable): - args.append('bin') + cratetype = 'bin' elif isinstance(target, build.SharedLibrary): - args.append('dylib') + cratetype = 'dylib' else: raise InvalidArguments('Unknown target type for rustc.') + args.append(cratetype) args += rustc.get_buildtype_args(self.environment.coredata.buildtype) depfile = target_name + '.d' - args += ['--out-dir', target.subdir, '-o', target.get_filename()] + args += ['--out-dir', target.subdir] args += ['--dep-info', depfile] orderdeps = [os.path.join(t.subdir, t.get_filename()) for t in target.link_targets] linkdirs = {} @@ -527,6 +528,7 @@ class NinjaBackend(backends.Backend): element.add_orderdep(orderdeps) element.add_item('ARGS', args) element.add_item('targetdep', depfile) + element.add_item('cratetype', cratetype) element.write(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): rule = 'rule %s_COMPILER\n' % compiler.get_language() 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' depfile = ' depfile = $out.d\n' + depstyle = ' deps = gcc\n' outfile.write(rule) outfile.write(command) diff --git a/rustrunner.py b/rustrunner.py index 18700c111..4af196be4 100755 --- a/rustrunner.py +++ b/rustrunner.py @@ -28,12 +28,11 @@ def delete_old_crates(target_name, target_type): if target_type == 'dylib': (base, suffix) = os.path.splitext(target_name) 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]] 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): try: @@ -53,6 +52,8 @@ if __name__ == '__main__': retval = invoke_rust(rustc_command) if retval != 0: sys.exit(retval) - delete_old_crates(target_name, target_type) - touch_file(target_name) + if target_type != "bin": + delete_old_crates(target_name, target_type) + touch_file(target_name) + diff --git a/test cases/rust/1 basic/installed_files.txt b/test cases/rust/1 basic/installed_files.txt index 88164df9e..429fde786 100644 --- a/test cases/rust/1 basic/installed_files.txt +++ b/test cases/rust/1 basic/installed_files.txt @@ -1 +1 @@ -bin/rustprog +bin/prog diff --git a/test cases/rust/1 basic/meson.build b/test cases/rust/1 basic/meson.build index 1c2f9260c..7cd84b611 100644 --- a/test cases/rust/1 basic/meson.build +++ b/test cases/rust/1 basic/meson.build @@ -1,4 +1,4 @@ project('rustprog', 'rust') -e = executable('rustprog', 'prog.rs', install : true) +e = executable('prog', 'prog.rs', install : true) test('rusttest', e)