Commit Graph

738 Commits

Author SHA1 Message Date
f4d19db25e Use target.aix_so_archive to decide to archive shared library in AIX
Previously, AIX support was updated to archive shared libraries per AIX
platform conventions, which expect .a files that contain .so files. This
is usually correct, but an edge case occurs for loadable plugins, e.g.
what meson creates for `shared_module()`. A notable example is python
extensions (SciPy, for example).

These should *not* be archived, because the .so file itself needs to be
loaded as a plugin. For example, SciPy fails to import in the python
interpreter.

Handle this by differentiating between plugins and regular libraries,
and only archiving when safe to do so.

Fixes #12219
2023-10-31 19:18:17 -04:00
e9e098b73e build: improve the warning for executables with the same name
adb1a360b9 added the feature and also the
usual meson-style warning to users that might be using the feature but
were not targeting a new enough meson version. Well unfortunately the
warning both doesn't actually work (it didn't take different directories
into account) and is also really slow because it creates an O(N^2) loop
for checking this.

Instead, rework this by adding an additional set that stores a tuple
containing the target name and its subdirectory. We only add this tuple
if the target is an executable since it is the only time it will be
relevant. After that, simply check if the name + subdir combination
already exists in the set along with the target being executable. If so,
then we execute FeatureNew which may possibly warn. This is a simply
O(1) lookup which is way faster. Fixes #12404.
2023-10-25 23:43:40 +03:00
1abdd9dd61 interpreter: use typed_kwargs for build_target.name_suffix 2023-10-17 08:09:06 -07:00
9f80a069ec interpreter: use typed_kwargs for build_target.name_prefix 2023-10-17 08:09:06 -07:00
507d8bf4d7 interpreter: use typed_kwargs for build_target.build_by_default
This allows a little bit of cleanup in the build layer, since there is
code now that would always be true and we shouldn't do that.
2023-10-17 08:09:06 -07:00
b2f681c92a build: use a TypedDict for d_features
This allows for better type checking.
2023-10-16 13:28:32 -07:00
9b1efa37fd interpreter: use typed_kwargs for build_target.d_import_dirs 2023-10-16 13:28:32 -07:00
523a27c6f0 build: Use typed_kwargs for language args
This also moves the repacking into the interpreter, making the build
implementation simpler and removing a layering violation. This also
makes use a defaultdict to remove the need to call `.get()`
2023-10-09 17:33:48 -04:00
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
3cac6ea545 Add env kwarg in generator.process() 2023-10-05 09:59:43 -07:00
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
4fadb2a296 msvc: unify debug filename handling
The MSVC code is extremely confusing, and it turns out it actually
constructs debug (pdb) files names/path independently in separate
places. This is really hard to parse. Instead, refactor it so that the
source of the debug filename is within the target itself
(get_debug_filename). Add a couple of generic methods to retrieve the
full path of the debug filename name in the backend and use that when
needed.
2023-10-05 08:43:38 -07:00
937aab09c0 interpreter: handle implib/export_dynamic conflicts in the interpreter
This differentiates export_dynamic being explicitly set to False from it
being unset. This allows us to deprecate explicitly setting
export_dynamic to false, but setting implib. This is already the case in
the other direction, if implib is False but export_dynamic is enabled
then we get a hard error.

This also moves the validation up to the Interpreter and out of the
build level.
2023-09-29 15:52:03 -07:00
32be9bd6de add support for vs_module_defs to Executables
fixes: #9254
2023-09-28 14:35:01 -04:00
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
f4ea89be60 interpreter: use typed_kwargs for build_target(vs_module_defs) 2023-09-28 14:35:01 -04:00
f485a8cf16 interpreter: use typed_kwargs for static_library(pic) 2023-09-28 11:31:56 -07:00
798791baac interpreter: use typed_kwargs for static_library(prelink) 2023-09-28 11:31:56 -07:00
c6f33aed2d Rust: Fix proc-macro usage when cross compiling
Force BUILD machine and allow to link with HOST machine.
2023-09-19 13:54:49 -04:00
7592003484 Rust: Prevent linking Rust ABI with C library/executable 2023-09-19 13:54:49 -04:00
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
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
b2654b2d43 Fix crash when installing a vala library and python sources
Installing python sources causes the python module to call
create_install_data() before Ninja backends adds extra outputs to Vala
targets.

Target objects are supposed to be immutable, adding outputs that late is
totally wrong. Add extra vala outputs immediately, but be careful
because the main output is only added later in post_init(). Luckily
the base class already puts a placeholder item in self.outputs for the
main filename so we can just replace self.outputs[0] instead of
replacing the whole list which would contain vala outputs at that stage.
This is surprisingly what SharedLibrary was already doing.
2023-09-07 10:56:37 -04:00
d5f17bc9ff Rename OptionOverrideProxy to OptionsView and move to coredata
Coredata is where all option handling is done so it makes sense there.
It is a view on a list of options for a given subproject and with
optional overrides. This change prepare for using that view in a more
generic way in the future.
2023-09-07 06:55:07 -04:00
4eb9c84cf9 include_directories: Always add both source and build dirs
Compiler checks were not adding build dir side, which prevents using
headers generated with configure_file().
2023-08-28 20:18:26 -04:00
6f87215f1f build: Simplify import_filename handling
This removes deadcode, vs_import_filename and gcc_import_filename were
not needed.
2023-08-24 18:50:12 -04:00
7cbe37ebd9 Add more descriptive description to CustomTarget
Allow modules using CustomTarget to modify the command description used by ninja backend. This result in more precise logs when building a project.
2023-08-18 00:36:49 -04:00
9d32302032 interpreter: use typed_kwargs for shared_library(darwin_versions) 2023-08-14 09:55:18 -07:00
09bc028c71 interpreter: use typed_kwargs for shared_library(soversion) 2023-08-14 09:55:18 -07:00
cd676e229b interpreter: use typed_kwargs for shared_library(version) 2023-08-14 09:55:18 -07:00
90ce084144 treewide: automatic rewriting of all comment-style type annotations
Performed using https://github.com/ilevkivskyi/com2ann

This has no actual effect on the codebase as type checkers (still)
support both and negligible effect on runtime performance since
__future__ annotations ameliorates that. Technically, the bytecode would
be bigger for non function-local annotations, of which we have many
either way.

So if it doesn't really matter, why do a large-scale refactor? Simple:
because people keep wanting to, but it's getting nickle-and-dimed. If
we're going to do this we might as well do it consistently in one shot,
using tooling that guarantees repeatability and correctness.

Repeat with:

```
com2ann mesonbuild/
```
2023-08-11 13:41:03 -04:00
926c3a6919 Error when an installed static library links to internal custom target
When an installed static library A links to an internal static library B
built using a custom_target(), raise an error instead of a warning. This
is because to be usable, A needs to contain B which would require to
extract the archive to get its objects files.

This used to work, but was printing a warning and was installing a
broken static library, because we used to overlink in many cases, and
that got fixed in Meson 1.2.0. It now fails at link time with symbols
from the custom target not being defined. It's better to turn the
warning into a hard error at configure time.

While at it, noticed this situation can happen for any internal custom
or rust target we link to, recursively.
get_internal_static_libraries_recurse() could be called on CustomTarget
objects which do not implement it, and even if we did not call that
method, it would still fail when trying to call extract_all_objects() on
it.

Fixes: #12006
2023-08-07 05:44:08 -07:00
f3b9db9e9d build.py: improve BuildTarget error message
Improve the error message when a build target is assigned as dependency
of another build target, which allows to better pinpoint where the issue
lies on.

In the example that follow, modules/meson.build:294 is in a for loop
creating library targets from an array of dictionary, and doesn't point
to the location where interop_sw_plugin is assigned with vlc_opengl:

Before:

    modules/meson.build:294:17: ERROR: Tried to use a build target as a dependency.
    You probably should put it in link_with instead.

After:

    modules/meson.build:294:17: ERROR: Tried to use a build target vlc_opengl as a dependency of target interop_sw_plugin.
    You probably should put it in link_with instead.

It would probably be best to directly pinpoint where the assignment was
made but it's probably harder so start simple by saying what is
concerned by the error.
2023-08-06 10:24:26 -04:00
404312c6dd do better sanity check for vs_module_defs input
We allow custom_target() but check for it based on hasattr, ever since
the initial implementation way back in the day, in commit
66a6ea984b. This is a bit broken because
various objects might support that but still aren't supposed to work. We
can actually just use isintance checks like we do immediately above,
which are more accurate and avoid crashes on things that aren't even
targets at all, like run_target(). Although custom_target indexes are
actually targets those didn't work either.

Fixes #9648
2023-07-31 11:00:22 -07:00
1a182ab599 make 'gui_app' an interpreter only concept
Since it's deprecated anyway, we don't really want to plumb it all the
way down into the build and backend layers. Instead, we can just turn
it into a `win_subsystem` value in the interpreter if `win_subsystem`
isn't already set.
2023-07-25 13:29:08 -04:00
1cfbe5279d interpreter: use typed_kwargs for Executable(win_subsystem) 2023-07-25 13:29:08 -04:00
67035a181e interpreter: use typed_kwargs for gui_app 2023-07-25 13:29:08 -04:00
9faf91d14f build: remove useless method call
This does nothing, so just delete it.
2023-07-24 14:24:15 -04:00
c8241d79e4 build: remove BuildTarget.need_install
This would be either the value `kwargs['install']`, or `False`. There
isn't any case that `BuildTarget.need_install` handles that
`BuildTarget.install` doesn't handle, if we just initialized it
correctly. So, just set Target.install correctly in the super
initializer, and do away with need_install.
2023-07-24 14:24:15 -04:00
01b5581a10 build|interpreter: move main_class to typed_kwargs
Also move it into the Jar class. This is an exclusive Jar keyword
argument, and is only used inside java paths, so there's no reason to
have this in all build targets.
2023-07-20 14:20:46 -04:00
0bb1647fd1 move various bits of type-checking only code to TYPE_CHECKING blocks
Mostly detected with flake8-type-checking. Also quote T.cast() first
arguments, since those are not affected by future annotations.
2023-07-19 18:31:37 -04:00
7afc69254d fix implicit_reexport issues and enforce them going forward
This detects cases where module A imports a function from B, and C
imports that same function from A instead of B. It's not part of the API
contract of A, and causes innocent refactoring to break things.
2023-07-19 18:31:37 -04:00
3e3d5e97c3 Fix display of generator 2023-07-13 13:26:33 -04:00
1fef03c0f0 build: dependencies should come after link_with on link command
This fixes regression caused by
3162b901ca
that changes the order in which libraries are put on the link command.

In addition, that commit was wrong because libraries from dependencies
were processed before process_compiler() is called, which that commit
wanted to avoid.
2023-07-10 23:12:24 +03:00
cd63853ad2 build: Fix linking multiple libraries and some are promoted
When a link() is promoted to link_whole() we still have to handle the
rest of the list.

Fixes: #11956
2023-07-10 23:12:24 +03:00
8369dbbfec build: use self.compilers instead of all_compilers for stdlib langs
We need a union of the compilers used by the target, and by those used
by all dependencies, not all the compilers in all projects. We do,
however, need to look compilers up from all possible compilers, as a
dependency that is a subproject could use a language not present in the
current project.
2023-07-05 07:17:26 -04:00
d391e5281c Merge pull request #11742 from xclaesse/link-whole-cases
Fix niche cases when linking static libs
2023-07-05 01:10:58 +03:00
772cb92624 rust: get stdlib arguments for non-rust languages when linking
Otherwise we might not get things like libstdc++, which we need.
2023-06-27 11:53:18 -07:00
a1ef957e34 linkers: delay implementations import until detect is run
This saves on a 1500-line import at startup and may be skipped entirely
if no compiled languages are used. In exchange, we move the
implementation to a new file that is imported instead.

Followup to commit ab20eb5bbc.
2023-06-26 13:10:33 -04:00
6c480085d5 rust: PIC is always enabled
rustc enables PIC by default and Meson currently has no way to force
disabling PIC, it can only force enable or use compiler's default.
2023-06-07 13:18:58 -04:00