## Summary Compilers stop being a *node attribute*, and become a *build-only* dependency. Packages may declare a dependency on the `c`, `cxx`, or `fortran` languages, which are now treated as virtuals, and compilers would be *providers* for one or more of those languages. Compilers can also inject runtime dependency, on the node being compiled. An example graph for something as simple as `zlib-ng` is the following: <p align="center"> <img src="https://github.com/user-attachments/assets/ee6471cb-09fd-4127-9f16-b9fe6d1338ac" alt="zlib-ng DAG" width="80%" height="auto"> </p> Here `gcc` is used for both the `c`, and `cxx` languages. Edges are annotated with the virtuals they satisfy (`c`, `cxx`, `libc`). `gcc` injects `gcc-runtime` on the nodes being compiled. `glibc` is also injected for packages that require `c`. The `compiler-wrapper` is explicitly represented as a node in the DAG, and is included in the hash. This change in the model has implications on the semantics of the `%` sigil, as discussed in #44379, and requires a version bump for our `Specfile`, `Database`, and `Lockfile` formats. ## Breaking changes Breaking changes below may impact users of this branch. ### 1. Custom, non-numeric version of compilers are not supported Currently, users can assign to compilers any custom version they want, and Spack will try to recover the "real version" whenever the custom version fails some operation. To deduce the "real version" Spack must run the compiler, which can add needless overhead to common operations. Since any information that a version like `gcc@foo` might give to the user, can also be suffixed while retaining the correct numeric version, e.g. `gcc@10.5.0-foo`, Spack will **not try** anymore to deduce real versions for compilers. Said otherwise, users should have no expectation that `gcc@foo` behaves as `gcc@X.Y.Z` internally. ### 2. The `%` sigil in the spec syntax means "direct build dependency" The `%` sigil in the spec syntax means *"direct build dependency"*, and is not a node attribute anymore. This means that: ```python node.satisfies("%gcc") ``` is true only if `gcc` is a direct build dependency of the node. *Nodes without a compiler dependency are allowed.* ### `parent["child"]`, and `node in spec`, will now only inspect the link/run sub-DAG and direct build dependencies The subscript notation for `Spec`: ```python parent["child"] ``` will look for a `child` node only in the link/run transitive graph of `parent`, and in its direct build dependencies. This means that to reach a transitive build dependency, we must first pass through the node it is associated with. Assuming `parent` does not depend on `cmake`, but depends on a `CMakePackage`, e.g. `hdf5`, then we have the following situation: ```python # This one raises an Exception, since "parent" does not depend on cmake parent["cmake"] # This one is ok cmake = parent["hdf5"]["cmake"] ``` ### 3. Externals differing by just the compiler attribute Externals are nodes where dependencies are trimmed, and that _is not planned to change_ in this branch. Currently, on `develop` it is ok to write: ```yaml packages: hdf5: externals: - spec: hdf5@1.12 %gcc prefix: /prefix/gcc - spec: hdf5@1.12 %clang prefix: /prefix/clang ``` and Spack will account for the compiler node attribute when computing the optimal spec. In this branch, using externals with a compiler specified is allowed only if any compiler in the dag matches the constraints specified on the external. _The external will be still represented as a single node without dependencies_. ### 4. Spec matrices enforcing a compiler Currently we can have matrices of the form: ```yaml matrix: - [x, y, z] - [%gcc, %clang] ``` to get the cross-product of specs and compilers. We can disregard the nature of the packages in the first row, since the compiler is a node attribute required on each node. In this branch, instead, we require a spec to depend on `c`, `cxx`, or `fortran` for the `%` to have any meaning. If any of the specs in the first row doesn't depend on these languages, there will be a concretization error. ## Deprecations * The entire `compilers` section in the configuration (i.e., `compilers.yaml`) has been deprecated, and current entries will be removed in v1.2.0. For the time being, if Spack finds any `compilers` configuration, it will try to convert it automatically to a set of external packages. * The `packages:compiler` soft-preference has been deprecated. It will be removed in v1.1.0. ## Other notable changes * The tokens `{compiler}`, `{compiler.version}`, and `{compiler.name}` in `Spec.format` expand to `"none"` if a Spec does not depend on C, C++, or Fortran. * The default install tree layout is now `"{architecture.platform}-{architecture.target}/{name}-{version}-{hash}"` ## Known limitations The major known limitations of this branch that we intend to fix before v1.0 is that compilers cannot be bootstrapped directly. In this branch we can build a new compiler using an existing external compiler, for instance: ``` $ spack install gcc@14 %gcc@10.5.0 ``` where `gcc@10.5.0` is external, and `gcc@14` is to be built. What we can't do at the moment is use a yet to be built compiler, and expect it will be bootstrapped, e.g. : ``` spack install hdf5 %gcc@14 ``` We plan to tackle this issue in a following PR. --------- Signed-off-by: Massimiliano Culpo <massimiliano.culpo@gmail.com> Signed-off-by: Todd Gamblin <tgamblin@llnl.gov> Signed-off-by: Harmen Stoppels <me@harmenstoppels.nl> Co-authored-by: Harmen Stoppels <me@harmenstoppels.nl> Co-authored-by: Todd Gamblin <tgamblin@llnl.gov>
124 lines
5.2 KiB
Python
124 lines
5.2 KiB
Python
# Copyright Spack Project Developers. See COPYRIGHT file for details.
|
|
#
|
|
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
|
from typing import List # novm
|
|
|
|
import llnl.util.filesystem as fs
|
|
|
|
import spack.builder
|
|
import spack.package_base
|
|
import spack.spec
|
|
import spack.util.prefix
|
|
from spack.directives import build_system, conflicts
|
|
|
|
from ._checks import BuilderWithDefaults
|
|
|
|
|
|
class MSBuildPackage(spack.package_base.PackageBase):
|
|
"""Specialized class for packages built using Visual Studio project files or solutions."""
|
|
|
|
#: This attribute is used in UI queries that need to know the build
|
|
#: system base class
|
|
build_system_class = "MSBuildPackage"
|
|
|
|
build_system("msbuild")
|
|
conflicts("platform=linux", when="build_system=msbuild")
|
|
conflicts("platform=darwin", when="build_system=msbuild")
|
|
|
|
|
|
@spack.builder.builder("msbuild")
|
|
class MSBuildBuilder(BuilderWithDefaults):
|
|
"""The MSBuild builder encodes the most common way of building software with
|
|
Mircosoft's MSBuild tool. It has two phases that can be overridden, if need be:
|
|
|
|
1. :py:meth:`~.MSBuildBuilder.build`
|
|
2. :py:meth:`~.MSBuildBuilder.install`
|
|
|
|
It is usually necessary to override the :py:meth:`~.MSBuildBuilder.install`
|
|
phase as many packages with MSBuild systems neglect to provide an install
|
|
target. The default install phase will attempt to invoke an install target
|
|
from MSBuild. If none exists, this will result in a build failure
|
|
|
|
For a finer tuning you may override:
|
|
|
|
+-----------------------------------------------+---------------------+
|
|
| **Method** | **Purpose** |
|
|
+===============================================+=====================+
|
|
| :py:attr:`~.MSBuildBuilder.build_targets` | Specify ``msbuild`` |
|
|
| | targets for the |
|
|
| | build phase |
|
|
+-----------------------------------------------+---------------------+
|
|
| :py:attr:`~.MSBuildBuilder.install_targets` | Specify ``msbuild`` |
|
|
| | targets for the |
|
|
| | install phase |
|
|
+-----------------------------------------------+---------------------+
|
|
| :py:meth:`~.MSBuildBuilder.build_directory` | Directory where the |
|
|
| | project sln/vcxproj |
|
|
| | is located |
|
|
+-----------------------------------------------+---------------------+
|
|
"""
|
|
|
|
phases = ("build", "install")
|
|
|
|
#: Targets for ``make`` during the :py:meth:`~.MSBuildBuilder.build` phase
|
|
build_targets: List[str] = []
|
|
#: Targets for ``msbuild`` during the :py:meth:`~.MSBuildBuilder.install` phase
|
|
install_targets: List[str] = ["INSTALL"]
|
|
|
|
@property
|
|
def build_directory(self):
|
|
"""Return the directory containing the MSBuild solution or vcxproj."""
|
|
return fs.windows_sfn(self.pkg.stage.source_path)
|
|
|
|
@property
|
|
def toolchain_version(self):
|
|
"""Return currently targeted version of MSVC toolchain
|
|
Override this method to select a specific version of the toolchain or change
|
|
selection heuristics.
|
|
Default is whatever version of msvc has been selected by concretization"""
|
|
return "v" + self.spec["msvc"].package.platform_toolset_ver
|
|
|
|
@property
|
|
def std_msbuild_args(self):
|
|
"""Return common msbuild cl arguments, for now just toolchain"""
|
|
return [self.define("PlatformToolset", self.toolchain_version)]
|
|
|
|
def define_targets(self, *targets):
|
|
return "/target:" + ";".join(targets) if targets else ""
|
|
|
|
def define(self, msbuild_arg, value):
|
|
return "/p:{}={}".format(msbuild_arg, value)
|
|
|
|
def msbuild_args(self):
|
|
"""Define build arguments to MSbuild. This is an empty list by default.
|
|
Individual packages should override to specify MSBuild args to command line
|
|
PlatformToolset is already defined an can be controlled via the `toolchain_version`
|
|
property"""
|
|
return []
|
|
|
|
def msbuild_install_args(self):
|
|
"""Define install arguments to MSBuild outside of the INSTALL target. This is the same
|
|
as `msbuild_args` by default."""
|
|
return self.msbuild_args()
|
|
|
|
def build(
|
|
self, pkg: MSBuildPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix
|
|
) -> None:
|
|
"""Run "msbuild" on the build targets specified by the builder."""
|
|
with fs.working_dir(self.build_directory):
|
|
pkg.module.msbuild(
|
|
*self.std_msbuild_args,
|
|
*self.msbuild_args(),
|
|
self.define_targets(*self.build_targets),
|
|
)
|
|
|
|
def install(
|
|
self, pkg: MSBuildPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix
|
|
) -> None:
|
|
"""Run "msbuild" on the install targets specified by the builder.
|
|
This is INSTALL by default"""
|
|
with fs.working_dir(self.build_directory):
|
|
pkg.module.msbuild(
|
|
*self.msbuild_install_args(), self.define_targets(*self.install_targets)
|
|
)
|