aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.py4
-rw-r--r--ninjabackend.py15
-rwxr-xr-xrustrunner.py64
-rw-r--r--test cases/rust/1 basic/installed_files.txt2
-rw-r--r--test cases/rust/2 sharedlib/installed_files.txt4
-rw-r--r--test cases/rust/2 sharedlib/stuff.rs2
-rw-r--r--test cases/rust/3 staticlib/installed_files.txt4
-rw-r--r--test cases/rust/3 staticlib/stuff.rs2
8 files changed, 17 insertions, 80 deletions
diff --git a/build.py b/build.py
index 6d263f1..8b372f3 100644
--- a/build.py
+++ b/build.py
@@ -620,6 +620,8 @@ class StaticLibrary(BuildTarget):
raise InvalidArguments('Static libraries not supported for C#.')
self.prefix = environment.get_static_lib_prefix()
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
def get_import_filename(self):
@@ -642,6 +644,8 @@ class SharedLibrary(BuildTarget):
else:
self.prefix = environment.get_shared_lib_prefix()
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.filename = self.prefix + self.name + '.' + self.suffix
diff --git a/ninjabackend.py b/ninjabackend.py
index 0c1d3ba..ce78f67 100644
--- a/ninjabackend.py
+++ b/ninjabackend.py
@@ -824,14 +824,14 @@ class NinjaBackend(backends.Backend):
if isinstance(target, build.Executable):
cratetype = 'bin'
elif isinstance(target, build.SharedLibrary):
- cratetype = 'dylib'
+ cratetype = 'rlib'
elif isinstance(target, build.StaticLibrary):
- cratetype = 'lib'
+ cratetype = 'rlib'
else:
raise InvalidArguments('Unknown target type for rustc.')
args.append(cratetype)
args += rustc.get_buildtype_args(self.environment.coredata.buildtype)
- depfile = target_name + '.d'
+ depfile = target.name + '.d'
args += ['--out-dir', target.subdir]
args += ['--emit', 'dep-info', '--emit', 'link']
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):
rule = 'rule %s_COMPILER\n' % compiler.get_language()
invoc = ' '.join([ninja_quote(i) for i in compiler.get_exelist()])
- 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)
+ command = ' command = %s $ARGS $in\n' % invoc
description = ' description = Compiling Rust source $in.\n'
- depfile = ' depfile = $out.d\n'
+ depfile = ' depfile = $targetdep\n'
depstyle = ' deps = gcc\n'
outfile.write(rule)
@@ -1375,7 +1372,7 @@ rule FORTRAN_DEP_HACK
def get_fortran_orderdeps(self, target, compiler):
if compiler.language != 'fortran':
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):
if len(pch) != 2:
diff --git a/rustrunner.py b/rustrunner.py
deleted file mode 100755
index 6c20bb3..0000000
--- a/rustrunner.py
+++ /dev/null
@@ -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)
-
-
diff --git a/test cases/rust/1 basic/installed_files.txt b/test cases/rust/1 basic/installed_files.txt
index 429fde7..61eda27 100644
--- a/test cases/rust/1 basic/installed_files.txt
+++ b/test cases/rust/1 basic/installed_files.txt
@@ -1 +1 @@
-bin/prog
+usr/bin/prog
diff --git a/test cases/rust/2 sharedlib/installed_files.txt b/test cases/rust/2 sharedlib/installed_files.txt
index 0606d1f..5a7c7d6 100644
--- a/test cases/rust/2 sharedlib/installed_files.txt
+++ b/test cases/rust/2 sharedlib/installed_files.txt
@@ -1,2 +1,2 @@
-bin/prog
-lib/libstuff-e4d2ee75-1.0.so
+usr/bin/prog
+usr/lib/libstuff.rlib
diff --git a/test cases/rust/2 sharedlib/stuff.rs b/test cases/rust/2 sharedlib/stuff.rs
index 5e1dcc2..8cabc62 100644
--- a/test cases/rust/2 sharedlib/stuff.rs
+++ b/test cases/rust/2 sharedlib/stuff.rs
@@ -1,3 +1,3 @@
-#![crate_id = "stuff#1.0"]
+#![crate_name = "stuff"]
pub fn explore() -> &'static str { "librarystring" }
diff --git a/test cases/rust/3 staticlib/installed_files.txt b/test cases/rust/3 staticlib/installed_files.txt
index 4c3dfed..5a7c7d6 100644
--- a/test cases/rust/3 staticlib/installed_files.txt
+++ b/test cases/rust/3 staticlib/installed_files.txt
@@ -1,2 +1,2 @@
-bin/prog
-lib/libstuff-e4d2ee75-1.0.rlib
+usr/bin/prog
+usr/lib/libstuff.rlib
diff --git a/test cases/rust/3 staticlib/stuff.rs b/test cases/rust/3 staticlib/stuff.rs
index 5e1dcc2..8cabc62 100644
--- a/test cases/rust/3 staticlib/stuff.rs
+++ b/test cases/rust/3 staticlib/stuff.rs
@@ -1,3 +1,3 @@
-#![crate_id = "stuff#1.0"]
+#![crate_name = "stuff"]
pub fn explore() -> &'static str { "librarystring" }