Commit Graph

13770 Commits

Author SHA1 Message Date
Dylan Baker a227768b37 compilers/cpp: try to do a better job of detecting libc++ vs libstdc++
Currently, we hardcode libc++ for MacOS (and derivatives), and libstdc++
for all other cases. Clang had some hackery to make this work in many
cases. However, this doesn't always work, namely if you try to to use
Rust as the linker when libc++ is required.

This implementation does, as an optimization, provide a hardcoded list
of OSes we know always use libc++, and otherwise will attempt to detect
it. As a second optimization, the detected values are cached, so the
lookup is only done once

fixes: #11921
2023-06-29 13:36:47 -07:00
Dylan Baker f58bd2ae11 compilers/cpp: use a Mixin to share the stdlib flags between clang++ and g++
Which will make subsequent work easier
2023-06-29 11:57:10 -07:00
Dylan Baker a4b597a7b7 compilers/cpp: use a list comprehension instead of a for loop
It's slightly faster, and less code
2023-06-29 11:56:10 -07:00
Dylan Baker 59cfbf68e0 compilers/cpp: Actually add the search dirs to for gcc
We calculate them, but then don't use them. Clang does use them, so this
looks like a simple oversight
2023-06-29 11:56:08 -07:00
Jussi Pakkanen 9a6a95483c Bump version number for rc1. 2023-06-28 17:50:49 +03:00
GertyP 36bf53bdfd
Experimental 'genvslite' WIP. (#11049)
* Capture all compile args from the first round of ninja backend generation for all languages used in building the targets so that these args, defines, and include paths can be applied to the .vcxproj's intellisense fields for all buildtypes/configurations.

Solution generation is now set up for mutiple build configurations (buildtypes) when using '--genvslite'.

All generated vcxprojs invoke the same high-level meson compile to build all targets;  there's no selective target building (could add this later).  Related to this, we skip pointlessly generating vcxprojs for targets that aren't buildable (BuildTarget-derived), which aren't of interest to the user anyway.

When using --genvslite, no longer inject '<ProjectReference ...>' dependencies on which a generated .vcxproj depends because that imposes a forced visual studio build dependency, which we don't want, since we're essentially bypassing VS's build in favour of running 'meson compile ...'.

When populating the vcxproj's shared intellisense defines, include paths, and compiler options fields, we choose the most frequent src file language, since this means more project src files can simply reference the project shared fields and fewer files of non-primary language types need to populate their full set of intellisense fields.  This makes for smaller .vcxproj files.

Paths for generated source/header/etc files, left alone, would be added to solution projects relative to the '..._vs' build directory, where they're never generated;  they're generated under the respective '..._[debug/opt/release]' ninja build directories that correspond to the solution build configuration. Although VS doesn't allow conditional src/header listings in vcxprojs (at least not in a simple way that I'm aware of), we can ensure these generated sources get adjusted to at least reference locations under one of the concrete build directories (I've chosen '..._debug') under which they will be generated.

Testing with --genvslite has revealed that, in some cases, the presence of 'c:\windows\system32;c:\windows' on the 'Path' environment variable (via the make-style project's ExecutablePath element) is critical to getting the 'meson compile ...' build to succeed.  Not sure whether this is some 'find and guess' implicit defaults behaviour within meson or within the MSVC compiler that some projects may rely on. Feels weird but not sure of a better solution than forcibly adding these to the Path environment variable (the Executable Path property of the project).

Added a new windows-only test to windowstests.py ('test_genvslite') to exercise the --genvslite option along with checking that the 'msbuild' command invokes the 'meson compile ...' of the build-type-appropriate-suffixed temporary build dir and checks expected program output.

Check and report error if user specifies a non-ninja backend with a 'genvslite' setup, since that conflicts with the stated behaviour of genvslite.  Also added this test case to 'WindowsTests.test_genvslite'

I had problems tracking down some problematic environment variable behaviour, which appears to need a work-around. See further notes on VSINSTALLDIR, in windowstests.py, test_genvslite.
'meson setup --help' clearly states that positional arguments are ... [builddir] [sourcedir].  However, BasePlatformTests.init(...) was passing these in the order [sourcedir] [builddir].  This was producing failures, saying, "ERROR: Neither directory contains a build file meson.build." but when using the correct ordering, setup now succeeds.

Changed regen, run_tests, and run_install utility projects to be simpler makefile projects instead, with commands to invoke the appropriate '...meson.py --internal regencheck ...' (or install/test) on the '[builddir]_[buildtype]' as appropriate for the curent VS configuration.  Also, since the 'regen.vcxproj' utility didn't work correctly with '--genvslite' setup build dirs, and getting it to fully work would require more non-trivial intrusion into new parts of meson (i.e. '--internal regencheck', '--internal regenerate', and perhaps also 'setup --reconfigure'), for now, the REGEN project is replaced with a simpler, lighter-weight RECONFIGURE utility proj, which is unlinked from any solution build dependencies and which simply runs 'meson setup --reconfigure [builddir]_[buildtype] [srcdir]' on each of the ninja-backend build dirs for each buildtype.
Yes, although this will enable the building/compiling to be correctly configured, it can leave the solution/vcxprojs stale and out-of-date, it's simple for the user to 'meson setup --genvslite ...' to fully regenerate an updated, correct solution again. However, I've noted this down as a 'fixme' to consider implementing the full regen behaviour for the genvslite case.

* Review feedback changes -
- Avoid use of 'captured_compile_args_per_buildtype_and_target' as an 'out' param.
- Factored a little msetup.py, 'run(...)' macro/looping setup steps, for genvslite, out into a 'run_genvslite_setup' func.

* Review feedback:  Fixed missing spaces between multi-line strings.

* 'backend_name' assignment gets immediately overwritten in 'genvslite' case so moved it into else/non-genvslite block.

* Had to bump up 'test cases/unit/113 genvslites/...' up to 114; it collided with a newly added test dir again.

* Changed validation of 'capture' and 'captured_compile_args_...' to use MesonBugException instead of MesonException.

* Changed some function param and closing brace indentation.
2023-06-28 15:29:57 +03:00
Jussi Pakkanen 9e1e4cafd5 Condense test directory names for release. 2023-06-28 15:28:52 +03:00
Eli Schwartz 712a772643
fix setuptools deprecation warning for renamed metadata key
Licenses can be plural, so the official key here has an "s" at the end
and triggers a deprecation warning for the old name.
2023-06-28 02:20:51 -04:00
Eli Schwartz bab04ac587
add additional setuptools metadata pointing to the source repository
Currently, PyPI shows one link for meson -- to the homepage (the docs
site). Provide an additional convenient link to the github repo.
2023-06-28 02:20:51 -04:00
Jussi Pakkanen a4fb8dcc41
Merge pull request #11902 from dcbaker/submit/rust-module-enhancements
Rust module enhancements for mesa
2023-06-27 23:57:13 +03:00
Aditya Kamath 8946bc05f7
Archive shared library in AIX (#11850)
* Archive shared library in AIX

This code change to ensure we archive shared libraries in AIX.

The things we do are:
Archive shared library
Install archived shared library
Build all must build the archived shared library
blibpath must have the archived shared library dependency.

* Archive shared library in AIX.

Made changes as per the review comments given in the first
PR request.

They are:-
Use self.environment.machines[t.for_machine].is_aix()
Remove trial spaces
Use of val instead of internal
Changed comments wherever requested

* Space after octothorpe

* Fixed failed test case causing build break during install section

* Moved AIX specific code to AIXDynamicLinker from backend

* Fix indentation, trailing spaces, add type annotations and Linux/macOS build break

* Remove some more trailing space issues

* Fixed the wrong return type in linkers
2023-06-27 22:02:32 +03:00
Dylan Baker 6bfb47a455 rust: Override the default MSVCRT when linking Rust and !rust together
Rust by default links with the default MSVCRT, (dynamic, release).
MSVCRT's cannot be mixed, so if Meson compiles a C or C++ library and
links it with the debug MSVCRT, then tries to link that with the Rust
library there will be failures. There is no built-in way to fix this for
rustc, so as a workaround we inject the correct arguments early in the
linker line (before any libs at least) to change the runtime. This seems
to work and is recommended as workaround in the upstream rust bug
report: https://github.com/rust-lang/rust/issues/39016.

Given that this bug report has been opened since 2017, it seems unlikely
to be fixed anytime soon, and affects all (currently) released versions
of Rust.
2023-06-27 11:53:18 -07:00
Dylan Baker 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
Dylan Baker 5d16bd5308 modules/rust: Add a keyword argument to pass extra args to the rust compiler
This may be necessary to, for example, stop rustc complaining about
unused functions
2023-06-27 11:53:18 -07:00
Dylan Baker c5b16ab8b9 modules/rust: Add a machine file property for extra clang args with bindgen
It's currently impossible to inject extra clang arguments when using
bindgen, which is problematic when cross compiling since you may need
critical arguments like `--target=...`. Because such arguments must be
passed after the `--` it's impossible to inject them currently without
going to something like a wrapper script.

Fixes: #11805
2023-06-27 11:53:18 -07:00
Dylan Baker 43f24060f3 modules/rust: Add a `link_with` kwarg to the test method
This was requested by Mesa, where a bunch of `declare_dependency`
objects are being created as a workaround for the lack of this keyword
2023-06-27 11:53:18 -07:00
Jussi Pakkanen 78b8d447ee Fix pylint. 2023-06-27 14:51:28 -04:00
Nathan Goldbaum f92bc05c18 interpreter: use os.listdir instead of os.scandir to avoid ResourceWarning 2023-06-27 20:26:48 +03:00
Dan Hawson 8e879911ec Added a little more useful info to 'link_whole' documentation, describing the use of /LINKWHOLE with MSVC and the behaviour of re-exporting symbols of individual objects in a static library. 2023-06-27 20:22:11 +03:00
Daniele Nicolodi c900e6b0b3 mintro: record subproject in install_plan 2023-06-26 23:06:29 -04:00
Eli Schwartz a71846d749
Revert "modules: move gnome targets into gnome module"
This reverts commit a2def550c5.

This results in a 2k line file being unconditionally imported at
startup, and transitively loading two more (for a total cost of 2759
lines of code), and it's not clear it was ever needed to begin with...
2023-06-26 13:10:33 -04:00
Eli Schwartz 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
Eli Schwartz 6fad02db04
fix regression in handling output overwriting for ar-like linkers
Linkers that aren't actually ar, were refactored into a base class in
commit 253ff71e6b, which however didn't
take into account that we were doing checks for this.
2023-06-26 13:10:33 -04:00
Eli Schwartz 3c5d46267f
WIP: cmake: do not re-export unused top-level objects
We should try to figure out what is a cross-submodule object and what
isn't.
2023-06-26 13:10:33 -04:00
Eli Schwartz 5849979afa
stop importing cmake when it isn't used
We don't need a CMakeInterpreter until and unless we actually attempt to
use a cmake subproject via the cmake module.

Minus 10 files and 3679 lines of code imported at startup.
2023-06-26 13:10:33 -04:00
Eli Schwartz b8b2d87567
dependencies: switch the delayed-import mechanism for custom dependencies
Simply store the module it is expected to be found in. That module then
appends to the packages dict, which guarantees mypy can verify that
it's got the right type -- there is no casting needed.
2023-06-26 13:10:33 -04:00
Eli Schwartz b1ddfabf8f
dependencies: defer importing a custom dependency until it is used
This lessens the amount of code imported at Meson startup by mapping
each dependency to a dictionary entry and using a programmable import to
dynamically return it.

Minus 16 files and 6399 lines of code imported at startup.
2023-06-26 13:10:33 -04:00
Eli Schwartz c82305db0c
dependencies: delay often-unused imports
We expose detect.py as the mesonbuild.dependencies entrypoint and import
it upfront everywhere. But unless the `dependency()` function is
actually invoked, we don't need *any* of the private implementations for
this.

Avoid doing so until, as part of actual dependency lookup, we attempt
that specific dependency method. This avoids importing big modules if
`method:` is specified, and in most cases hopefully pkg-config works and
we can avoid importing the cmake implementation particularly.

Actually avoiding most of these imports requires more refactoring. But
even so, the garden path no longer needs to import the dub dependency
impl.
2023-06-26 13:10:32 -04:00
Eli Schwartz c780d240e2
dependencies: Don't Repeat Yourself when it comes to lookup methods
We need to extend the candidates the same way per method, but we handle
each method twice: once in explicit method checks, and once for auto. We
can just handle auto as a special list of methods, though.
2023-06-26 13:10:32 -04:00
Eli Schwartz 216f7476de
dependencies: move dub to a hidden package internal detail
Do not import it and expose it at the package scope, it's never used
elsewhere except inside the dub module.
2023-06-26 13:10:32 -04:00
Eli Schwartz e715400d1b
tree-wide: reduce unneeded imports on specific Dependency impls
We can check something's subtype using properties, without importing the
module up front and doing isinstance checks on specific subclasses of
the interface -- or worse, solving cyclic imports by doing the import
inside the function. ;)
2023-06-26 13:10:32 -04:00
Eli Schwartz 418063cc47
pkgconfig: move uninstalled devenv handling from setup to the module hook
msetup.py doesn't need to know the gory details of PkgConfigDependency,
or directly import it at program startup. It's also slightly wasteful to
generate a devenv for the -uninstalled directory when a project doesn't
even, in the end, use the pkgconfig module anyway.
2023-06-26 13:10:25 -04:00
Eli Schwartz 620bdf5895
add profiling startup import check and testcase to count it 2023-06-26 13:08:57 -04:00
Eli Schwartz 25f5f3554d
tests: move script loaded modules test to platform-agnostic
We have the same platform startup logic here for all platforms and I do
not believe it's important to test this on the slow CI machines.
2023-06-25 15:38:31 -04:00
Eli Schwartz cd6c3ca55e
msetup: place profiling logs in the log directory 2023-06-25 12:12:11 -04:00
Eli Schwartz a53c6687b6
fully type mconf.py 2023-06-25 10:08:15 -04:00
Eli Schwartz b411be5edc
fully type mdist.py 2023-06-25 10:08:15 -04:00
Eli Schwartz b05764b73e
mdist: consolidate facts about the current dist using a dataclass
And avoid passing variables around several functions just to finally get
where they need to be. These function signatures were kind of ugly...

Also the use of dataclasses makes a big chunk of this file now typed
properly.
2023-06-25 10:08:15 -04:00
Eli Schwartz a146ee6946
mdist: refactor lots of code into VCS-specific classes
Most of the dist handling is either git-specific or hg-specific.
Tangling it all together makes it much harder to analyze what is going
on.
2023-06-25 10:08:14 -04:00
Jussi Pakkanen 9e1dc30f1f Add CppNorth talk. 2023-06-25 16:27:42 +03:00
Xavier Claessens 543610468d coredata: Also clear compiler and run caches 2023-06-23 13:53:35 -04:00
Xavier Claessens 1d600b48cb mconf: Allow changing options and clearing cache at the same time
Setting options or clearing cache is also an error without a valid build
directory.
2023-06-23 13:53:35 -04:00
Xavier Claessens c16dd8d711 coredata: Malformed machine file is not a Meson bug
Fixes: #11899
2023-06-23 06:03:20 -04:00
Alyssa Ross ab17bd2393 rust: fix -C prefer-dynamic behavior
I noticed when building a project that uses a proc macro that Meson
passed -C prefer-dynamic for the executable, and not the proc macro,
while cargo passed -C prefer-dynamic for the proc macro, but not for
the executable.  Meson's behavior broke setting -C panic=abort on the
executable.

As far as we can tell, because we explicitly pass each library path to
rustc, the only thing -C prefer-dynamic affects in Meson is how the
standard libraries are linked.  Generally, one does not want the
standard libraries to be dynamically linked, because if the Rust
compiler is ever updated, anything linked against the old standard
libraries will likely break, due to the lack of a stable Rust ABI.
Therefore, I've reorganised Meson's behavior around the principle that
the standard libraries should only be dynamically linked when Rust
dynamic linking has already been opted into in some other way.  The
details of how this manifests are now explained in the documentation.
2023-06-21 18:05:16 -04:00
Paolo Borelli 548dd25c67 Clarify `environment` docs.
The object is not used only for tests, but also for `custom_target` etc.
2023-06-21 08:45:47 -04:00
Xavier Claessens 4c85a7af92 doc: Dictionaries are ordered since Meson 0.62.0
This is a side effect of requiring Python >= 3.7 which itself guarantees
dictionary order. This is now a Meson language guarantee as well which
is required for passing default_options as dict and is generally
expected by users.
2023-06-20 16:10:20 -07:00
Xavier Claessens 6f2956e76c interpreter: Accept more types in default_options dict values 2023-06-20 16:10:20 -07:00
Dylan Baker be20e0809f interpreter: allow default_options and override_options as a dict 2023-06-20 16:10:20 -07:00
Eli Schwartz d0cbda99a3
backends/vs: add sundry type annotations
We went from 192 mypy errors down to 144.
2023-06-20 16:24:46 -04:00
Eli Schwartz f38c653a75
backends/xcode: simplify an obviously too-complicated function
This function has a pretty unique name, and a simple grep shows that it
is only ever called as:
```
add_comment(PbxComment('...........'))
```

It doesn't need to include logic such as handling str. Moreover it looks
like that handling was broken anyway... it handled the case where
comment is type str, by constructing a new PbxComment(str) instead of
PbxComment(comment), a condition that cannot ever be valid (and crashed
due to other assertions).

Fixes:

mesonbuild/backend/xcodebackend.py:148:42: error: Argument 1 to "PbxComment" has incompatible type "type[str]"; expected "str"  [arg-type]
2023-06-20 16:24:45 -04:00