Fix Rust to work with 1.3 release. Closes #277.
This commit is contained in:
parent
7c9c03b430
commit
d952812b1b
4
build.py
4
build.py
|
@ -620,6 +620,8 @@ class StaticLibrary(BuildTarget):
|
||||||
raise InvalidArguments('Static libraries not supported for C#.')
|
raise InvalidArguments('Static libraries not supported for C#.')
|
||||||
self.prefix = environment.get_static_lib_prefix()
|
self.prefix = environment.get_static_lib_prefix()
|
||||||
self.suffix = environment.get_static_lib_suffix()
|
self.suffix = environment.get_static_lib_suffix()
|
||||||
|
if len(self.sources) > 0 and self.sources[0].endswith('.rs'):
|
||||||
|
self.suffix = 'rlib'
|
||||||
self.filename = self.prefix + self.name + '.' + self.suffix
|
self.filename = self.prefix + self.name + '.' + self.suffix
|
||||||
|
|
||||||
def get_import_filename(self):
|
def get_import_filename(self):
|
||||||
|
@ -642,6 +644,8 @@ class SharedLibrary(BuildTarget):
|
||||||
else:
|
else:
|
||||||
self.prefix = environment.get_shared_lib_prefix()
|
self.prefix = environment.get_shared_lib_prefix()
|
||||||
self.suffix = environment.get_shared_lib_suffix()
|
self.suffix = environment.get_shared_lib_suffix()
|
||||||
|
if len(self.sources) > 0 and self.sources[0].endswith('.rs'):
|
||||||
|
self.suffix = 'rlib'
|
||||||
self.importsuffix = environment.get_import_lib_suffix()
|
self.importsuffix = environment.get_import_lib_suffix()
|
||||||
self.filename = self.prefix + self.name + '.' + self.suffix
|
self.filename = self.prefix + self.name + '.' + self.suffix
|
||||||
|
|
||||||
|
|
|
@ -824,14 +824,14 @@ class NinjaBackend(backends.Backend):
|
||||||
if isinstance(target, build.Executable):
|
if isinstance(target, build.Executable):
|
||||||
cratetype = 'bin'
|
cratetype = 'bin'
|
||||||
elif isinstance(target, build.SharedLibrary):
|
elif isinstance(target, build.SharedLibrary):
|
||||||
cratetype = 'dylib'
|
cratetype = 'rlib'
|
||||||
elif isinstance(target, build.StaticLibrary):
|
elif isinstance(target, build.StaticLibrary):
|
||||||
cratetype = 'lib'
|
cratetype = 'rlib'
|
||||||
else:
|
else:
|
||||||
raise InvalidArguments('Unknown target type for rustc.')
|
raise InvalidArguments('Unknown target type for rustc.')
|
||||||
args.append(cratetype)
|
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]
|
args += ['--out-dir', target.subdir]
|
||||||
args += ['--emit', 'dep-info', '--emit', 'link']
|
args += ['--emit', 'dep-info', '--emit', 'link']
|
||||||
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]
|
||||||
|
@ -976,12 +976,9 @@ 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 %s $out $cratetype %s $ARGS $in\n' % \
|
command = ' command = %s $ARGS $in\n' % invoc
|
||||||
(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 = $targetdep\n'
|
||||||
|
|
||||||
depstyle = ' deps = gcc\n'
|
depstyle = ' deps = gcc\n'
|
||||||
outfile.write(rule)
|
outfile.write(rule)
|
||||||
|
@ -1375,7 +1372,7 @@ rule FORTRAN_DEP_HACK
|
||||||
def get_fortran_orderdeps(self, target, compiler):
|
def get_fortran_orderdeps(self, target, compiler):
|
||||||
if compiler.language != 'fortran':
|
if compiler.language != 'fortran':
|
||||||
return []
|
return []
|
||||||
return [os.path.join(self.get_target_dir(lt), lt.filename) for lt in target.link_targets]
|
return [os.path.join(self.get_target_dir(lt), lt.get_filename()) for lt in target.link_targets]
|
||||||
|
|
||||||
def generate_msvc_pch_command(self, target, compiler, pch):
|
def generate_msvc_pch_command(self, target, compiler, pch):
|
||||||
if len(pch) != 2:
|
if len(pch) != 2:
|
||||||
|
|
|
@ -1,64 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
# Copyright 2014 The Meson development team
|
|
||||||
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
"""This is a wrapper script to run the Rust compiler. It is needed
|
|
||||||
because:
|
|
||||||
|
|
||||||
- output file name of Rust compilation is not knowable at command
|
|
||||||
execution time (no, --crate-name can't be used)
|
|
||||||
- need to delete old crates so nobody uses them by accident
|
|
||||||
"""
|
|
||||||
|
|
||||||
import sys, os, subprocess, glob
|
|
||||||
|
|
||||||
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_mtime, i) for i in crates]
|
|
||||||
[os.unlink(c[1]) for c in sorted(crates)[:-1]]
|
|
||||||
if target_type == 'lib':
|
|
||||||
(base, suffix) = os.path.splitext(target_name)
|
|
||||||
crates = glob.glob(base + '-*' + '.rlib') # Rust does not use .a
|
|
||||||
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 subprocess.call(rustc_command, shell=False)
|
|
||||||
|
|
||||||
def touch_file(fname):
|
|
||||||
try:
|
|
||||||
os.unlink(fname)
|
|
||||||
except FileNotFoundError:
|
|
||||||
pass
|
|
||||||
open(fname, 'w').close()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
if len(sys.argv) < 3:
|
|
||||||
print('This script is internal to Meson. Do not run it on its own.')
|
|
||||||
print("%s <target name> <target type> <rustc invokation cmd line>")
|
|
||||||
sys.exit(1)
|
|
||||||
target_name = sys.argv[1]
|
|
||||||
target_type = sys.argv[2]
|
|
||||||
rustc_command = sys.argv[3:]
|
|
||||||
retval = invoke_rust(rustc_command)
|
|
||||||
if retval != 0:
|
|
||||||
sys.exit(retval)
|
|
||||||
if target_type != "bin":
|
|
||||||
delete_old_crates(target_name, target_type)
|
|
||||||
touch_file(target_name)
|
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
bin/prog
|
usr/bin/prog
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
bin/prog
|
usr/bin/prog
|
||||||
lib/libstuff-e4d2ee75-1.0.so
|
usr/lib/libstuff.rlib
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
#![crate_id = "stuff#1.0"]
|
#![crate_name = "stuff"]
|
||||||
|
|
||||||
pub fn explore() -> &'static str { "librarystring" }
|
pub fn explore() -> &'static str { "librarystring" }
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
bin/prog
|
usr/bin/prog
|
||||||
lib/libstuff-e4d2ee75-1.0.rlib
|
usr/lib/libstuff.rlib
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
#![crate_id = "stuff#1.0"]
|
#![crate_name = "stuff"]
|
||||||
|
|
||||||
pub fn explore() -> &'static str { "librarystring" }
|
pub fn explore() -> &'static str { "librarystring" }
|
||||||
|
|
Loading…
Reference in New Issue