Invoke Rust via wrapper script.
This commit is contained in:
parent
147e04ac80
commit
923ad8ab9b
9
build.py
9
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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
bin/rustprog
|
||||
bin/prog
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
project('rustprog', 'rust')
|
||||
|
||||
e = executable('rustprog', 'prog.rs', install : true)
|
||||
e = executable('prog', 'prog.rs', install : true)
|
||||
test('rusttest', e)
|
||||
|
|
Loading…
Reference in New Issue