Commit Graph

34 Commits

Author SHA1 Message Date
Eli Schwartz e184ef71e5
cmake dependency: avoid setting property to None as a workaround
It's an improper object model, but was used to signal to a subclass that
self.traceparser did not exist. However, since it is always initialized
from self.cmakebin, we can just check that instead.
2024-02-12 18:52:43 -05:00
Eli Schwartz 07c051ed27
defer setting values until after we know it cannot be None 2024-02-12 18:52:43 -05:00
Sam James 99ea390af8
cmake: canonicalise -DSTATIC value
CMake really prefers ON/OFF and in some cases, depending on how the condition
is written, ON/OFF vs other "truthy" (as far as CMake's lang supports) values
work differently. Just be safe and use ON/OFF.

Signed-off-by: Sam James <sam@gentoo.org>
Signed-off-by: Eli Schwartz <eschwartz93@gmail.com>
2024-02-07 23:41:35 -05:00
Dylan Baker e991c4d454 Use SPDX-License-Identifier consistently
This replaces all of the Apache blurbs at the start of each file with an
`# SPDX-License-Identifier: Apache-2.0` string. It also fixes existing
uses to be consistent in capitalization, and to be placed above any
copyright notices.

This removes nearly 3000 lines of boilerplate from the project (only
python files), which no developer cares to look at.

SPDX is in common use, particularly in the Linux kernel, and is the
recommended format for Meson's own `project(license: )` field
2023-12-13 15:19:21 -05:00
Xiang Gao 6402f53a13 Allow share/cmake/ as cmake_prefix_path
This is to allow passing the path share/cmake/ as cmake_prefix_path.
This is a case supported by cmake and is relied on by PyTorch.

The cmake prefix of PyTorch can be found by running:
python -c 'import torch.utils; print(torch.utils.cmake_prefix_path)'

you will see something like below from the above command:
/home/gaoxiang/.virtualenvs/nvfuser/lib/python3.11/site-packages/torch/share/cmake
Inspecting this directory:

❯ tree /home/gaoxiang/.virtualenvs/nvfuser/lib/python3.11/site-packages/torch/share/cmake
/home/gaoxiang/.virtualenvs/nvfuser/lib/python3.11/site-packages/torch/share/cmake
├── ATen
│   └── ATenConfig.cmake
├── Caffe2
│   ├── Caffe2Config.cmake
│   ├── Caffe2Targets.cmake
│   ├── Caffe2Targets-release.cmake
│   ├── FindCUDAToolkit.cmake
│   ├── FindCUSPARSELT.cmake
│   ├── Modules_CUDA_fix
│   │   ├── FindCUDA.cmake
│   │   ├── FindCUDNN.cmake
│   │   └── upstream
│   │       ├── CMakeInitializeConfigs.cmake
│   │       ├── FindCUDA
│   │       │   ├── make2cmake.cmake
│   │       │   ├── parse_cubin.cmake
│   │       │   ├── run_nvcc.cmake
│   │       │   └── select_compute_arch.cmake
│   │       ├── FindCUDA.cmake
│   │       ├── FindPackageHandleStandardArgs.cmake
│   │       └── FindPackageMessage.cmake
│   └── public
│       ├── cuda.cmake
│       ├── gflags.cmake
│       ├── glog.cmake
│       ├── LoadHIP.cmake
│       ├── mkl.cmake
│       ├── mkldnn.cmake
│       ├── protobuf.cmake
│       └── utils.cmake
├── Tensorpipe
│   ├── TensorpipeTargets.cmake
│   └── TensorpipeTargets-release.cmake
└── Torch
    ├── TorchConfig.cmake
    └── TorchConfigVersion.cmake

9 directories, 28 files

However, meson currently filters this directory out by `_preliminary_find_check`. As a result, doing
torch_dep = dependency('Torch')
will fail, even if you set `cmake_prefix_path` with the value returned by PyTorch.

Possibly related issues:
https://stackoverflow.com/questions/68884434/libtorch-c-meson-dependency
https://github.com/mesonbuild/meson/issues/9740
https://discuss.pytorch.org/t/libtorch-meson-build/139648
2023-09-29 16:31:05 -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
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
Eli Schwartz 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
Volker Weißmann a8b144b71b Make `dependency('foo', static: true, method: 'cmake') link statically
Fixes #1709
2023-05-13 11:18:11 +03:00
Josh Soref cf9fd56bc9 fix various spelling issues
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-11 19:21:05 -04:00
Dylan Baker d5e899c768
pylint: enable the bad_builtin checker
This finds uses of deny-listed functions, which defaults to map and
filter. These functions should be replaced by comprehensions in
idiomatic python because:
    1. comprehensions are more heavily optimized and are often faster
    2. They avoid the need for lambdas in some cases, which make them
       faster
    3. you can do the equivalent in one statement rather than two, which
       is faster
    4. They're easier to read
    5. if you need a concrete instance (ie, a list) then you don't have
       to convert the iterator to a list afterwards
2022-11-29 23:26:05 -05:00
Dylan Baker a72840cd2e
pylint: enable use-a-generator
This catches some optimization problems, mostly in the use of `all()`
and `any()`. Basically writing `any([x == 5 for x in f])` vs `any(x == 5
for x in f)` reduces the performance because the entire concrete list
must first be created, then iterated over, while in the second f is
iterated and checked element by element.
2022-10-04 00:33:04 -04:00
Eli Schwartz 7972c49bda
dependencies: simplify log_tried into a staticmethod
It doesn't really need class instantiation to just know what type it is,
and this way we can get the information early if a dependency fails to
init.
2022-09-12 19:16:59 -04:00
Alf Henrik Sauge 9ad5d0df4a Remove redundant backslash and fix white space issue 2022-08-26 17:12:40 -04:00
Alf Henrik Sauge 06bf9a5cda Fix purely white space issues reported by flake8 2022-08-26 17:12:40 -04:00
Eli Schwartz a49cd00d64 treewide: various cleanups to move imports for mypy into typechecking blocks
Along the way, add __future__ annotations where lacking.
2022-06-10 09:15:48 -04:00
Eli Schwartz b55349c2e9
dependencies: tighten type checking and fix cmake API violation for get_variable
dep.get_variable() only supports string values for pkg-config and
config-tool, because those interfaces use text communication, and
internal variables (from declare_dependency) operate the same way.

CMake had an oddity, where get_variable doesn't document that it allows
list values but apparently it miiiiiight work? Actually getting that
kind of result would be dangerously inconsistent though. Also, CMake
does not support lists so it's a lie. Strings that are *treated* as
lists with `;` splitting don't count...

We could do two things here:

- raise an error
- treat it as a string and return a string

It's not clear what the use case of get_variable() on a maybe-list is,
and should probably be a hard error. But that's controversial, so
instead we just return the original `;`-delimited string. It is probably
the wrong thing, but users are welcome to cope with that somehow on
their own.
2022-04-13 17:27:09 -04:00
Daniel Mensinger 589600cb51 cmake: Always use all compilers for LLVM (fixes #10249) 2022-04-12 18:25:38 -04:00
Jussi Pakkanen 219f40c1e4
Merge pull request #9743 from mensinda/cmakeGeneratorFixed
cmake: Add TARGET_ generator expression support (fixes #9305)
2022-03-07 16:12:19 +02:00
Eli Schwartz 07d9c72e17
flake8: fix wrong numbers of blank line separators 2022-02-16 18:19:13 -05:00
Eli Schwartz baecebda0e
flake8: fix typoed whitespace surrounding tokens 2022-02-16 18:19:13 -05:00
Eli Schwartz cf3a1d31f8 fix some flake8 violations for unused imports
And one undefined T.cast name in a file that isn't yet mypy-ready
anyway.
2022-01-27 10:48:01 -08:00
Daniel Mensinger 42843c4cf6
cmake: Add TARGET_ generator expression support (fixes #9305) 2022-01-23 13:22:59 +01:00
Eli Schwartz 140097faf0
port from embedded data to importlib.resources 2022-01-10 18:36:57 -05:00
Daniel Mensinger 45c5300496 cmake: Fix old style dependency lookup with imported targets
This also includes some refactoring, since the alternaticve would
have been to duplicate the huge traceparser target code block again.

fixes #9581
2021-12-01 21:03:36 +02:00
Jon Turney 61ca56422b cmake: Use find_library() on bare library names in cmake dependencies
Convert bare library names to a dependency linker argument using
find_library(), rather than hardcoding the MSVC transformation.
2021-11-20 08:29:50 -08:00
Daniel Mensinger ffc8721465 cmake: Add support for the Linux CMake registry (fixes #9418) 2021-10-24 09:57:06 -04:00
Daniel Mensinger 29c2b44a29 cmake: Implement support for interpreting link "keywords"
CMakes `target_link_libraries()` supports certain keywords to
only enable specific libraries for specific CMake configurations.
We now try our best to replicate this for Meson dependencies.

Fixes #9197
2021-10-06 16:43:59 +02:00
Daniel Mensinger f1614a6071 cmake: Warn if we could use IMPORTED CMake targets 2021-10-06 16:43:59 +02:00
Dylan Baker dd97ec607d dependencies: drop Dependency.methods and Dependency.get_methods()
Both of these are artifacts of the time before Dependency Factories,
when a dependency that could be discovered multiple ways did ugly stuff
like finding a specific dependency, then replacing it's own attributes
with that dependency's attributes. We don't have cases of that left in
the tree, so let's get rid of this code too
2021-07-13 16:43:14 -07:00
Daniel Mensinger 3e396b3782
fix: Always explicitly set encoding for text files (fixes #8263) 2021-06-29 11:28:08 +02:00
Dylan Baker 0412bdd753 dependencies: Use a typing.NewType for Dependency.type_name
This allow mypy to catch cases where we accidently assign the dependency
name to the type_name, as it sees them as having different types (though
at runtime they're all strings).
2021-06-14 09:09:32 -07:00
Daniel Mensinger 71906c4bf8 typing: Fully annotate dependencies.cmake 2021-06-06 20:02:48 +03:00
Daniel Mensinger 95b70bcb97 deps: Split dependencies.base
Split the Factory and dependency classes out
of the base.py script to improve maintainability.
2021-06-03 10:23:27 -07:00