Commit Graph

49 Commits

Author SHA1 Message Date
Dylan Baker 9b83fc5ece ninja: fix handling of rust structured_sources in rare case
In the even that all of the inputs are generated, and they're all
generated into the same folder, and there are no subfolders, we would
fail to correctly handle all of the files after the main file. Let's fix
that.t
2022-03-21 11:26:52 -07:00
Jussi Pakkanen 69ade4f4cf
Merge pull request #9339 from dcbaker/submit/structured_sources
Structured Sources
2022-03-13 01:01:55 +02:00
Dylan Baker c08b6e29d9 Add support for rust proc-macro crates 2022-03-07 18:35:31 -05:00
Dylan Baker 038d072364 tests/rust: Add a test for structured inputs 2022-03-07 12:33:33 -08:00
Alyssa Ross 3596b6b19a ninjabackend: fix rust program names with dashes
This substitution matches the behaviour of rustc[1] when inferring
crate name based on file name.

[1]: 4e8fb743cc/compiler/rustc_session/src/output.rs (L88)
2022-02-10 15:05:37 -08:00
Zach Reizner 6383eb2279 ninjabackend: treat link_whole_targets like link_targets for Rust targets
For static library crates that depend on other internal static library
crates, all link_with targets get promoted to link_whole targets. Due to
a bug, only link_with targets are considered when generating a Rust
target for the ninja backend. This made it impossible to link a Rust
static library with another internal Rust static library.

This change fixes that issue by chaining link_whole_targets with
link_targets, just like many other languages within the ninja backend.
2022-02-02 19:36:14 +02:00
Dylan Baker f45a21af1e tests/rust polyglot: we need to link with bcrypt.lib as well 2021-12-09 15:57:45 -05:00
Volker Weißmann 2c079d855e Added warning if run_command is called without the check kwarg 2021-10-30 22:26:28 -04:00
Christian Clauss a5020857f3 Fix typos discovered by codespell 2021-10-10 16:12:25 -04:00
Dominique Leuenberger 7ad54cce49 tests/rust: add libm to fix build with rust 1.55
Fixes #9309
2021-09-29 10:14:23 -07:00
Dylan Baker 30202a2402 compilers/rust: Add support for clippy
Clippy is a compiler wrapper for rust that provides an extra layer of
linting. It's quite popular, but unfortunately doesn't provide the
output of the compiler that it's wrapping in it's output, so we don't
detect that clippy is rustc. This small patch adds a new compiler class
(that is the Rustc class with a different id) and the necessary logic to
detect that clippy is in fact rustc)

Fixes: #8767
2021-09-24 18:48:48 -07:00
Nirbheek Chauhan d80baf8a2b test cases/rust: clang-cl also needs extra_winlibs 2021-08-17 19:58:23 -07:00
Daniel Mensinger c4b8e03895
tests: both_library test improvements
This switches some `shared_library()` calls to `library()` and adds
one new CI matrix entries for -Ddefault_library={static, both}.
2021-06-22 21:09:25 +02:00
Dylan Baker e7e04c814b Add a rust test for internal c linkage
We have code to support this, but no tests. That seems pretty bad.
And better yet, it doesn't work on MSVC in some cases.
2021-05-18 09:34:36 -07:00
Jussi Pakkanen a1c8376f42 Add test to build a mixed C/Rust shared library. 2021-03-10 14:55:57 -08:00
Jordan Justen e127e47d7a tests/rust: Add rust case linking to libm in rust static library
When building on Linux, I see:

rustc -C linker=cc --color=always --crate-type rlib --crate-name rs_math -g --emit dep-info=rs_math.d --emit link -L /usr/lib/x86_64-linux-gnu -o librs_math.rlib -l static=m ../rs_math.rs
error: failed to add native library /usr/lib/x86_64-linux-gnu/libm.a: file too small to be an archive

I think the "file too small to be an archive" message is coming from
libLLVM, and is a case of LLVM not handling this type of "script
archive". So, possibly this is just LLVM not handling a linking case.

The rust_args usage in meson.build is invalid, but required to
reproduce the issue in the test case. Perhaps meson should
automatically add the library include path via the dep_m meson object,
or maybe the meson.build can add the link path in a better way.

Changing '-l static=m' to '-l dylib=m' appears to fix this case. (See
comments in meson.build.)
2021-02-26 11:58:47 -08:00
Dylan Baker 6544f151db rust: fix linking with external dependencies
Rust can link with any dependency that uses c linkage, which is pretty
much what we assume across the board anyway.
2021-02-23 16:22:56 -08:00
Jordan Justen 5edbc0acd7 tests/rust: Add rust case linking to zlib dependency
Reworks:
 * Add MESON_SKIP_TEST error for darwin from polyglot test
 * Remove dependencies from executable

Dylan's changes:
 * Add support for both static and shared testing
 * Test with pkg-config, cmake, and system
 * reformat to meson's style

Co-authored-by: Dylan Baker <dylan@pnwbakers.com>
2021-02-23 11:31:05 -08:00
Dylan Baker b28235428d rust: Add a module wrapper for bindgen
This has a couple of advantages over rolling it by hand:
1. it correctly handles include_directories objects, which is always
   handy
2. it correctly generates a depfile for you, which makes it more
   reliable
3. it requires less typing
2021-02-06 10:27:04 -08:00
Dylan Baker d02149ad90 tests/rust: Add a generated library to generated main test
Which is broken, of course.
2021-01-21 10:59:15 -08:00
Dylan Baker 27ca7ed67a tests/rust: Add subdir to generated sources test 2021-01-21 10:59:15 -08:00
Dylan Baker bff0b41525 rust: Accept generated sources for main.rs
There are still caveats here. Rust/cargo handles generated sources by
writing out all targets of a single repo into a single output directory,
setting a path to that via a build-time environment variable, and then
include those files via a set of functions and macros. Meson's build
layout is naturally different, and ninja makes working with environment
variables at compile time difficult.

Fixes #8157
2021-01-19 10:14:10 -08:00
Dylan Baker 3d80a88bd3 modules: Add an unstable-rust module
Like other language specific modules this module is module for holding
rust specific helpers. This commit adds a test() function, which
simplifies using rust's internal unittest mechanism.

Rust tests are generally placed in the same code files as they are
testing, in contrast to languages like C/C++ and python which generally
place the tests in separate translation units. For meson this is
somewhat problematic from a repetition point of view, as the only
changes are generally adding --test, and possibly some dependencies.

The rustmod.test() method provides a mechanism to remove the repatition:
it takes a rust target, copies it, and then addes the `--test` option,
then creates a Test() target with the `rust` protocol. You can pass
additional dependencies via the `dependencies` keyword. This all makes
for a nice, DRY, test definition.
2021-01-05 15:10:50 -08:00
Dylan Baker d89ec98b47 mtest: Add support for rust unit tests
Rust has it's own built in unit test format, which is invoked by
compiling a rust executable with the `--test` flag to rustc. The tests
are then run by simply invoking that binary. They output a custom test
format, which this patch adds parsing support for. This means that we
can report each subtest in the junit we generate correctly, which should
be helpful for orchestration systems like gitlab and jenkins which can
parse junit XML.
2021-01-05 10:23:41 -08:00
Dylan Baker 91bf84eaa5 tests/rust: dynamic linking doesn't work on darwin
This is a bug, and needs to be fixed, but in the short term testing
other rust functionality on darwin is an improvement over testing none.
2020-11-11 07:42:40 -08:00
Dylan Baker 7860a6aeab rust: implement support for --edition
Using the std option, so now `rust_std=..` will work. I've chosen to use
"std" even though rust calls these "editions", as meson refers to
language versions as "standards", which makes meson feel more uniform,
and be less surprising.

Fixes: #5100
2020-11-05 21:24:20 +02:00
Daniel Mensinger 8e60b8c146
test: merge installed_files.txt into test.json 2020-02-25 21:47:42 +01:00
Michael Hirsch, Ph.D 83b4e981c4 Use strict function prototypes 2019-11-18 22:21:36 +02:00
Jussi Pakkanen 2cabda8d68 Fix the last remaining Rust install file list. 2019-06-22 00:55:30 +03:00
Jussi Pakkanen 9c68d8f3f2 Run Rust shared library test via rustup to get the environment right. 2019-06-22 00:09:30 +03:00
Jussi Pakkanen 94ca81b228 Add Rust generated pdbs to list of installed files. 2019-06-21 23:11:56 +03:00
Jussi Pakkanen 8361da5c52 Fix setup so test suite runs with rustc + MSVC. Closes: 5099 2019-03-24 20:56:06 +02:00
Jussi Pakkanen cd63ca9c19 Support Rust targets with more than one source file. Closes #3632. 2018-06-17 15:39:59 +03:00
Adam C. Foltzer 3332f33649 Fix Rust compiler-private library ambiguity
When building a Rust target with Rust library dependencies, an
`--extern` argument is now specified to avoid ambiguity between the
dependency library, and any crates of the same name in `rustc`'s
private sysroot.

Includes an illustrative test case.
2018-02-22 22:16:58 +02:00
Adam C. Foltzer 281294286e Fix Rust shared polyglot test case for cross-compilation
The crate-type in this case should have been `cdylib` since it's
linking via C, rather than the default `dylib` that is meant for
linking via `rustc`.
2018-02-02 11:31:47 -08:00
Adam C. Foltzer 4eda3ca0fc add `crate-name` to Rust target args
This is required for downstream Rust dependencies to properly import
libraries using `extern crate`.
2017-07-22 03:49:39 +03:00
Adam C. Foltzer 35fae9d019 fix failing Rust test cases 2017-06-14 11:50:35 -07:00
Adam C. Foltzer 69b18cf7e9 rename `crate_type` to `rust_crate_type` per @TingPing 2017-06-14 08:39:41 -07:00
Adam C. Foltzer bdd4c45b17 Enhance Rust support
- Adds a `crate_type` kwarg to library targets, allowing the different
  types of Rust [linkage][1].
- Shared libraries use the `dylib` crate type by default, but can also
  be `cdylib`
- Static libraries use the `rlib` crate type by default, but can also
  be `staticlib`
- If any Rust target has shared library dependencies, add the
  appropriate linker arguments, including rpath for the sysroot of the
  Rust compiler

[1]: https://doc.rust-lang.org/reference/linkage.html
2017-06-09 15:14:02 -07:00
Patrick Griffis b520a4f030 rust: Support rust_args 2017-05-08 15:25:52 -04:00
Patrick Griffis 9929e0efac rust: Support executable name differing from source name 2017-03-29 21:09:51 +03:00
Nirbheek Chauhan 45c8557dc6 Fix tests for the new library/executable naming scheme
Also add new tests for the platform-specific and compiler-specific
versioning scheme.

A rough summary is:

1. A bug in how run_tests.py:validate_install checked for files has been
   fixed. Earlier it wasn't checking the install directory properly.
2. Shared libraries are no longer installed in common tests, and the
   library name/path testing is now done in platform-specific tests.
3. Executables are now always called something?exe in the
   installed_files.txt file, and the suffix automatically corrected
   depending on the platform.
4. If a test installs a file called 'no-installed-files', the installed
   files for that test are not validated. This is required to implement
   compiler-specific tests for library names/paths such as MSVC vs MinGW
5. The platform-specific file renaming in run_tests.py has been mostly
   removed since it is broken for shared libraries and isn't needed for
   static libraries.
6. run_tests.py now reports all missing and extra files. The logic for
   finding these has been reworked.
2016-07-01 20:50:47 +05:30
Jussi Pakkanen d952812b1b Fix Rust to work with 1.3 release. Closes #277. 2015-10-11 23:30:52 +03:00
Jussi Pakkanen 2d23a44e6e Deal with Rust static libraries, too. 2014-06-23 20:53:20 +03:00
Jussi Pakkanen 2366f822d2 Install Rust shared libraries. 2014-06-23 20:29:18 +03:00
Jussi Pakkanen 923ad8ab9b Invoke Rust via wrapper script. 2014-06-22 19:38:47 +03:00
Jussi Pakkanen 7b4595e07c Set up dependencies for Rust linking. Does not work fully yet. 2014-06-19 00:25:15 +03:00
Jussi Pakkanen bf4708eb83 Build a shared Rust library. 2014-06-19 00:02:19 +03:00
Jussi Pakkanen f22376701b Can compile very basic Rust programs. 2014-06-18 01:22:55 +03:00