Commit Graph

3231 Commits

Author SHA1 Message Date
Nicolas Werner ebf5757c59 cmake: parse project version
This properly sets the project version in projects meson generates from
cmake projects. This allows dependency fallbacks to properly check the
version constraints in dependency calls when falling back to a cmake
subproject. Before this would fail, because the project version was
undefined.
2023-12-12 20:14:26 -05:00
arch1t3cht af0464352a vs: Manually link generated .o files
Fixes #12550 .

VS automatically links CustomBuild outputs ending in .obj or .res,
but others need to be included explicitly.
2023-12-10 22:01:03 -05:00
Eli Schwartz 5f659af870
ninja backend: don't hide all compiler warnings for transpiled languages
This was originally added for vala only, with the rationale that vala
generates bad code that has warnings. Unfortunately, the rationale was
fatally flawed. The compiler warns about a number of things, which the
user can control depending on their code (or their code generator's
code), but some of those things are absolutely critical to warn about.

In particular, GCC 14 and clang 17 are updating their defaults to warn
-- and error by default for -- invalid C code that breaks the standard,
but has been silently accepted for over 20 years "because lots of people
do it". The code in question is UB, and compilers will generate faulty
machine code that behaves erroneously and probably has a mass of CVEs
waiting to happen.

Compiler warnings are NOT safe to just... universally turn off. Compiler
warnings could be either:

- coding style lints

- threatening statements that the code is factually and behaviorally wrong

There is no magic bullet to ignore the former while respecting the
latter. And the very last thing we should ever do is pass `-w`, since
that causes ALL warnings to be disabled, even the manually added
`-Werror=XXX`.

If vala generated code creates warnings, then the vala compiler can
decrease the log level by generating better code, or by adding warning
suppression pragmas for *specific* issues, such as unused functions.
2023-12-05 19:51:56 -05:00
Andres Freund 30184a48a0 macos: Skip as-needed test, the linker is too smart
The new linker in Sonoma / Xcode 15 considers the dependency via the
initializer sufficient to pull in the library. The man page now notes:
  The linker never dead strips initialization and termination routines.
  They are considered "roots" of the dead strip graph.

I could not find a good way to skip only if the linker version is new
enough. Before long everyone will be using the new linker anyway...
2023-12-04 23:54:59 +02:00
Randy Eckenrode dcff439df0 Fix test failure on Darwin on a case-sensitive fs
This was encountered while looking into an issue with
https://github.com/NixOS/nixpkgs/pull/268583.

I run my Nix store on case-sensitive APFS, so the test fails due to
trying to link `-framework ldap` instead of `-framework LDAP`.
2023-12-04 16:23:59 +02:00
Andres Freund 4ddaef8133 macos: Fix test case for constructor_priority when using gcc
GCC does not support constructor_priority on macos. It's possibly not the only
platform for which that is the case, but...
2023-12-03 14:04:46 +02:00
Xavier Claessens 85e4ee5b54 File: Add full_path() method
This is needed now that str.format() is not allowing it any more. It is
also more consistent with other objects that have that method as well,
such as build targets.

Fixes: #12406
2023-11-24 22:15:14 +02:00
David Seifert 8928669a69
Fix unity builds (#12452)
* unity builds: correct integer ceiling division

* edge case failure with unity builds:
  - static archive bar that gets installed, that links with another static
    archive foo that does not get installed
  - the number of files in static archive foo is divisible by unity_size

would yield an error with ninja:

  ninja: error: 'subprojects/foo/src/libfoo.a.p/meson-generated_foo-unity1.cpp.o', needed by 'src/libbar.a', missing and no known rule to make it

* unity builds: test for build failure when #files is divisible by unity_size
2023-11-18 11:08:41 +02:00
Eli Schwartz 398c4b2287
dependencies: allow get_variable to define multiple pkgconfig defines
It was previously impossible to do this:

```
dep.get_pkgconfig_variable(
    'foo',
    define_variable: ['prefix', '/usr', 'datadir', '/usr/share'],
)
```

since get_pkgconfig_variable mandated exactly two (if any) arguments.

However, you could do this:
```
dep.get_variable(
    'foo',
    pkgconfig_define: ['prefix', '/usr', 'datadir', '/usr/share'],
)
```

It would silently do the wrong thing, by defining "prefix" as
`/usr=datadir=/usr/share`, which might not "matter" if only datadir was
used in the "foo" variable as the unmodified value might be adequate.

The actual intention of anyone writing such a meson.build is that they
aren't sure whether the .pc file uses ${prefix} or ${datadir} (or which
one gets used, might have changed between versions of that .pc file,
even).

A recent refactor made this into a hard error, which broke some projects
that were doing this and inadvertently depending on some .pc file that
only used the second variable. (This was "fine" since the result was
essentially meaningful, and even resulted in behavior identical to the
intended behavior if both projects were installed into the same prefix
-- in which case there's nothing to remap.)

Re-allow this. There are two ways we could re-allow this:
- ignore it with a warning
- add a new feature to allow actually doing this

Since the use case which triggered this bug actually has a pretty good
reason to want to do this, it makes sense to add the new feature.

Fixes https://bugs.gentoo.org/916576
Fixes https://github.com/containers/bubblewrap/issues/609
2023-11-14 14:59:12 -05:00
Xavier Claessens 2da53e943a rust: Add transitive dependencies to ninja rules
In the case r1 -> s1 -> s2 where s1 and s2 are uninstalled C static
libraries, the libs1.a rule does not depend on libs2.a. That means that
r1 rule must depend on both s1 and s2.
2023-11-13 23:17:14 +02:00
Jussi Pakkanen 97dc8801a6 Renumber test dirs for rc3. 2023-11-12 19:18:06 +02:00
Jussi Pakkanen 8f89ce8a70
Merge pull request #12485 from xclaesse/rust-link-regress
rust: Fix linking with C libraries in subdir
2023-11-12 17:09:51 +02:00
Xavier Claessens d25d8e2772 rust: Fix linking with C libraries (again)
Pass link arguments directly down to linker by using `-C link-args=`
instead of letting rustc/linker resolve `-l` arguments. This solves
problems with e.g. +verbatim not being portable. Note that we also pass
`-l` args as `-Clink-args=-l` because rustc would otherwise reorder
arguments and put `-lstdc++` before `-Clink-args=libfoo++.a`.

However, when building a rlib/staticlib we should still use `-l`
arguments because that allows rustc to bundle static libraries we
link-whole. In that case, since there is no platform specific dynamic
linker, +verbatim works.

This also fix installed staticlib that now bundle uninstalled static
libraries it links to (recursively). This is done by putting them all
into self.link_whole_targets instead of putting their objects into
self.objects, and let rustc do the bundling. This has the extra
advantage that rustc can bundle static libries built with CustomTarget.

Disable bundling in all other cases, otherwise we could end up with
duplicated objects in static libraries, in diamond dependency graph
case.

Fixes: #12484
2023-11-09 16:20:01 -05:00
Jussi Pakkanen 2ea284bac1 Prohibit symlinks in test data dir because they get mangled by setup.py. 2023-11-07 21:52:14 +02:00
Eli Schwartz ccff0f43b2
tests: skip llvm modules test more thoroughly
The bug that is referenced in the SKIP message was merged in time for
the most recent llvm 16.x release. However, due to the graciousness of
the LLVM developers, a very reasonable response was taken:

LLVM will not merge ("the average"?) bugfixes during the final point
release of a release series, as judged by their willingness to continue
maintaining a major release of LLVM (????????) because merging a bugfix
could theoretically cause a new bug instead and that Simply Is Not
Done™. It could result in truly tragic outcomes, like having to release
another bugfix.

This innovative approach to bug solving has advanced the science of
computing forward by decades. Sadly, it comes at a downside: software
doesn't work. At this point it becomes obvious that llvm 16 in general
will simply not work with Meson, and this is "expected", so bump the
version checking for our SKIP to match reality.
2023-11-06 14:45:24 -05:00
Christoph Reiter 2d538c58cb Fix visibility attribute support check for GCC on Windows
has_function_attribute() depends on -Wattributes being emitted when an attribute
is not supported by the compiler. In case of GCC on Window (at least) there is no
warning in case the attribute is used on a declaration. Only once there is also a
function definition does it emit a warning like:

a.c: In function ‘foo’:
a.c:8:1: warning: visibility attribute not supported in this configuration; ignored [-Wattributes]
    8 | }

To fix this add a dummy function definition to all visibility compiler checks in meson.

The tests in "197 function attributes" only checked for positive return result on on-msvc
compilers, except one special case for dllexport/dllimport. Refactor the tests a bit so
one can specify also a negative expected result, and add tests for all visibility attribute
variants.
2023-11-04 23:36:03 -04:00
Xavier Claessens 06b9d1e75a rust: proc-macro should be ignored in transitive dependencies
Fixes: #12459
2023-11-02 14:15:09 -04:00
Sebastian Dröge 204563751e rust: Add unit test for transitive rust dependencies 2023-11-02 07:55:32 -04:00
Jussi Pakkanen 20bcca3972 Handle path behaviour change in Python 3.12. 2023-10-27 17:43:03 +03:00
Jussi Pakkanen 3bbe66e971 Condense test directories for RC1. 2023-10-27 17:43:03 +03:00
Dylan Baker 450b3db378 modules/rust: Add a test that bindgen drops arguments it shouldn't use
This does require hacking up the test pretty badly, since we need to not
ever pass GCC these invalid values. But it's preferable to writing
another project test I think.

Co-Authored-by: Nirbheek Chauhan <nirbheek@centricular.com>
2023-10-20 20:21:08 +05:30
Nirbheek Chauhan 890dd31cb0 test cases/15 llvm: Skip cmake when llvm == 17.0
There's a bug in the zstd find_package module:
e7fc7540da (r130257253)
2023-10-19 09:43:49 +05:30
Dylan Baker 658fe7243b modules/rust: remove rust_crate_type for test() method
This is required to test non-executable targets when they set an
explicit type.
2023-10-16 17:31:12 -07:00
Tristan Partin c0a5da8649 Use -idirafter when adding Apple framework include paths
System headers will continue to "preempt" the framework headers. This
should allow both <GStreamer/gst/gst.h> and <gst/gst.h>
2023-10-12 05:13:55 +05:30
Xavier Claessens dc329f0f04 interpreter: Add support for cargo subproject 2023-10-09 21:13:58 -04:00
Dylan Baker 013536fcb4 interpreter: add <lang>_(static|shared)_args
Which allow passing arguments specifically to the static or shared
libraries.

For design, this is all handled in the interpreter, by the build layer
the arguments are combined into the existing fields. This limits changes
required in the mid and backend layers
2023-10-09 17:33:48 -04:00
Dylan Baker cbca191948 interpreter: Handle BuildTarget.vala_args as Files in the interpreter
Way back in Meson 0.25, support was added to `vala_args` for Files.
Strangely, this was never added to any other language, though it's been
discussed before. For type safety, it makes more sense to handle this in
the interpreter level, and pass only strings into the build IR.

This is accomplished by adding a `depend_files` field to the
`BuildTarget` class (which is not exposed to the user), and adding the
depend files into that field, while converting the arguments to relative
string paths. This ensures both the proper build dependencies happen, as
well as that the arguments are always strings.
2023-10-09 17:33:48 -04:00
Nomura 3cac6ea545 Add env kwarg in generator.process() 2023-10-05 09:59:43 -07:00
Dudemanguy adb1a360b9 build: use suffix when getting target id for exes
When checking target names, meson explictly forbids having multiple
targets with the same name. This is good, but it is strict and it is
impossible to have targets with the same basename and differing suffixes
(e.g. foo and foo.bin) in the same directory. Allow this for executables
by including the suffix (if it exists) in the interal target id. So foo
would be foo@exe and foo.bin would be foo.bin@exe.
2023-10-05 08:43:38 -07:00
Marvin Scholz 00007e197e test: get_define: do not use assert incorrectly
This should be an error, not an assert as it asserts nothing,
in fact, if this wouldn't error out because of the wrong type
passed to the assert, it would even do the wrong thing.

Follow-up to #12223
2023-10-04 08:15:42 -04:00
Eli Schwartz ecf261330c
tests: fix test case to not import distutils on python 3.12
Testing the correctness of the `modules: ` kwarg can be done with other
guaranteed stdlib modules that are even more guaranteed since they
didn't get deprecated for removal.
2023-10-02 23:53:39 -04:00
Alan Coopersmith 710a753c78 nasm tests: skip asm language test on Solaris & illumos
The code in this test to make Linux system calls is not compatible
with the SunOS kernel system call conventions.
2023-10-02 17:55:00 -04:00
Dylan Baker 32be9bd6de add support for vs_module_defs to Executables
fixes: #9254
2023-09-28 14:35:01 -04:00
Dylan Baker 5421c24ea0 fix using a CustomTargetIndex for vs_module_defs
Because `CustomTargetIndex`es don't have a `subdir` property, but they do
implement the `get_subdir()` method
2023-09-28 14:35:01 -04:00
Lei YU dac25ba9a8 unittest: Fix clang-tidy-fix
The unittest case for `clang-tidy-fix` checks if the whole project is in
git or not, and skips if not.

Fix this by creating a temporary git repo, copy the test files and run
the tests, following how `clang-format` does.

It also reverts some help code introduced in the previous test.

Tested: Verify the test case passes.

Signed-off-by: Lei YU <yulei.sh@bytedance.com>
2023-09-28 10:54:39 -04:00
Albert Tang fb6fd5aa17 tests: Skip "withIncludeFile" for PCH on Xcode backend
Xcode always fails here because this makes the PCH not be the first
included header, causing Xcode to ignore it completely. There is no
way around this.
2023-09-26 02:34:45 -04:00
Eli Schwartz c3fe1b046d
tests: fix broken promises with linker scripts
This has never, ever, ever worked. You can get away with it a tiny, tiny
bit, iff you magically assume several things about both internal
implementations, as well as the project source layout and builddir
location.

This can be witnessed by the way using files() was mercilessly tortured
through joining the undefined stringified format value of the file to
the current source dir... because it didn't actually *work*, the
stringified value isn't an absolute path or a builddir-relative one, but
it works as long as you do it from the root meson.build file.

Furthermore, this triggers a deprecation warning if you do it. And using
it for files() is frivolous, the "static map file" case was correct all
along.

Fix the configure_file case to demonstrate the same painful hoops we
must jump through to get custom_target outputs to work correctly.

Fixes #12259
2023-09-25 23:50:40 -04:00
Dylan Baker d5546bdcea rust: apply global, project, and environment C args to bindgen
This means that arguments set via `add_global_arguments`,
`add_project_arguments` and by either the `-Dc_args` or `CFLAGS` are
applied to bindgen as well. This can be important when, among other
things, #defines are set via these mechanisms.

Fixes: #12065
2023-09-25 13:05:04 -07:00
Xavier Claessens 49e7e3b9cc Allow to fallback to cmake subproject
The method can be overridden by setting the `method` key in the wrap
file and always defaults to 'meson'. cmake.subproject() is still needed
in case specific cmake options need to be passed.

This also makes it easier to extend to other methods in the future e.g.
cargo.
2023-09-22 15:50:26 -04:00
Xavier Claessens 7592003484 Rust: Prevent linking Rust ABI with C library/executable 2023-09-19 13:54:49 -04:00
Xavier Claessens bdf1f3c0e2 Rust: Remove unit test already covered in "rust/4 polyglot" 2023-09-19 13:54:49 -04:00
Xavier Claessens 10dcd87d00 Rust: Replace rust_crate_type with rust_abi
Meson already knows if it's a shared or static library, user only need
to specify the ABI (Rust or C).
2023-09-19 13:54:49 -04:00
Dylan Baker 8ccdb88137 Rust: Add a rust.proc_macro() method 2023-09-19 13:54:49 -04:00
Xavier Claessens dec85c41a9 Remove get_configtool_variable()
This also makes it more consistent with get_pkgconfig_variable() which
always return empty value instead of failing when the variable does not
exist. Linking that to self.required makes no sense and was never
documented any way.
2023-09-18 13:51:27 -04:00
Xavier Claessens 30d7f506c7 Remove get_pkgconfig_variable()
Make sure that pkgconfig_define is a pair of strings and not a list with
more than 2 strings.
2023-09-18 13:51:27 -04:00
Arsen Arsenović 0af126fec7 install_{data,headers,subdir}: implement follow_symlinks
This permits users who rely on following symlinks to stay on the old
default of following them.
2023-09-13 21:44:40 -04:00
Charles Brunet 923b95f3d1 Fix assertion raised with invalid option name
When option name contains more that one dot, it should be detected
earlier to prevent an assert to be raised.

Fixes #11904.
2023-09-13 16:55:38 +05:30
Jussi Pakkanen d2dfef5205
Merge pull request #12152 from bruchar1/ast-preserve-all
Preserve whitespaces and comments in AST
2023-09-12 17:50:13 +03:00
Charles Brunet 57178e8ae7 fix bug with openssl when cmake is missing
Fixes #12098

DependencyFactory was returning a lambda, but it has no log_tried() function
2023-09-12 17:31:32 +05:30
Charles Brunet 14e35b63c0 parser: allow whitespaces and comments in cont_eol
FIXME: another approach would be to consider cont_eol as comment (i.e.
add backslash and whitespaces to the comment regex). In both cases it
works until we want to parse comments separately.

TODO?: handle eol_cont inside a string (to split long string without
breaking lines). Probably a bad idea and better to simply join a
multiline string.
2023-09-11 07:51:19 -04:00