Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: cargo: Support building multiple versions of the same crate #12363

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4e03af5
build: Warning message was not telling which target it links to.
xclaesse Nov 23, 2023
b30f6e3
compilers: Every compiler can run code
xclaesse Nov 3, 2023
e48ba1c
compilers: Do not dump File content in log for compiler checks.
xclaesse Nov 6, 2023
84e2002
compilers: Allow setting env and workdir for run checks
xclaesse Nov 6, 2023
f7c9b9a
modules: Add helper to add project/global arguments
xclaesse Nov 3, 2023
6ede467
cargo: Ensure Dependency.package always has a value
xclaesse Oct 11, 2023
fd1cd06
cargo: Add API version into dependency name
xclaesse Oct 11, 2023
2455524
cargo: Generate .wrap file from crates.io dependencies
xclaesse Oct 11, 2023
11d0f66
cargo: Add patch_directory into generated wrap if available
xclaesse Oct 11, 2023
4372383
cargo: Fix cfg() parsing
xclaesse Nov 1, 2023
8ffa42d
cargo: builder: Add elseblock support
xclaesse Nov 1, 2023
ffa0a19
cargo: Split function that adds a single dependency
xclaesse Nov 1, 2023
b22d37c
rust: Add get_target_triplet() method
xclaesse Nov 6, 2023
06ba9b7
rust: Add rust.cargo_cfg() module method
xclaesse Nov 1, 2023
65a079f
cargo: Fix error when defining options on build-dependencies
xclaesse Nov 22, 2023
2137f45
cargo: Only build one crate type at a time
xclaesse Nov 24, 2023
37df695
cargo: Set CARGO_PKG_* in env when building and running build.rs
xclaesse Nov 24, 2023
a6dd090
cargo: Warn if project has build-dependencies
xclaesse Feb 23, 2024
ad49e05
rust: recursively pull proc-macro dependencies as well
xclaesse Feb 27, 2024
600d1e6
cargo: Add support for `system-deps` dependencies
thiblahute Apr 22, 2023
18bd1ec
WIP: workspace support and fixes
xclaesse Mar 4, 2024
f7621ee
cargo: Override cargo provided dependencies with latest version
xclaesse Mar 4, 2024
cf0224b
cargo: A dependency is required if a feature with same name is enabled
xclaesse Mar 4, 2024
6a3f030
cargo: Fix crate name VS package name VS dependency name confusion
xclaesse Mar 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
cargo: Fix crate name VS package name VS dependency name confusion
If dependency name does not match the package name, we have to rename
the crate name to the dependency name. Yes, that makes 3 different names
for the same dependency, good job cargo! For example:
- package name: cairo-sys-rs
- crate name: cairo-sys
- dependency name: ffi
  • Loading branch information
xclaesse committed Mar 4, 2024
commit 6a3f030917a2a381ddbd74b36c2748c01cdeed4a
29 changes: 23 additions & 6 deletions mesonbuild/cargo/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import collections
import typing as T

from functools import lru_cache

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'lru_cache' is not used.
from pathlib import Path

from . import builder
Expand Down Expand Up @@ -646,6 +646,20 @@
build.method('get', build.identifier('features'), [build.string(name), build.bool(False)]),
)

# If dependency name does not match the package name, we have to rename the
# crate name to the dependency name. Yes, that makes 3 different names for
# the same dependency, good job cargo! For example:
# - package name: cairo-sys-rs
# - crate name: cairo-sys
# - dependency name: ffi
# rust_dependency_map += {xxx_dep.get_variable('crate-name'): 'name'}
rust_dependency_map_ast = []
if name != dep.package:
rust_dependency_map_ast.append(
build.plusassign(build.dict({
build.method('get_variable', build.identifier(_dependency_varname(dep.package)), [build.string('crate-name')]): build.string(name),
}), 'rust_dependency_map'))

# Lookup for this dependency with the features we want in default_options kwarg.
#
# However, this subproject could have been previously configured with a
Expand Down Expand Up @@ -712,13 +726,17 @@
])
]))
])),
*rust_dependency_map_ast,
])),
])

return ast


def _create_dependencies(cargo: Manifest, build: builder.Builder) -> T.List[mparser.BaseNode]:
ast: T.List[mparser.BaseNode] = []
ast: T.List[mparser.BaseNode] = [
build.assign(build.dict({}), 'rust_dependency_map'),
]
for condition, dependencies in cargo.target.items():
ifblock: T.List[mparser.BaseNode] = []
elseblock: T.List[mparser.BaseNode] = []
Expand Down Expand Up @@ -748,13 +766,10 @@

def _create_lib(cargo: Manifest, build: builder.Builder, crate_type: manifest.CRATE_TYPE) -> T.List[mparser.BaseNode]:
dependencies: T.List[mparser.BaseNode] = []
dependency_map: T.Dict[mparser.BaseNode, mparser.BaseNode] = {}
deps_i = [cargo.dependencies.items()]
deps_i += [deps.items() for deps in cargo.target.values()]
for name, dep in itertools.chain.from_iterable(deps_i):
dependencies.append(build.identifier(_dependency_varname(dep.package)))
if name != dep.package:
dependency_map[build.string(fixup_meson_varname(dep.package))] = build.string(name)
for name, dep in cargo.system_dependencies.items():
dependencies.append(build.identifier(f'{fixup_meson_varname(name)}_system_dep'))

Expand All @@ -765,14 +780,15 @@

dependencies.append(build.identifier(_extra_deps_varname()))

crate_name = cargo.lib.name or cargo.package.name
posargs: T.List[mparser.BaseNode] = [
build.string(fixup_meson_varname(cargo.package.name)),
build.string(fixup_meson_varname(crate_name)),
build.string(cargo.lib.path),
]

kwargs: T.Dict[str, mparser.BaseNode] = {
'dependencies': build.array(dependencies),
'rust_dependency_map': build.dict(dependency_map),
'rust_dependency_map': build.identifier('rust_dependency_map'),
'rust_args': build.array(rust_args),
}

Expand Down Expand Up @@ -816,6 +832,7 @@
'link_with': build.identifier('lib'),
'variables': build.dict({
build.string('features'): build.method('join', build.string(','), [build.method('keys', build.identifier('features'))]),
build.string('crate-name'): build.string(crate_name),
})
},
),
Expand Down
Loading