diff --git a/easybuild/easyblocks/generic/cargo.py b/easybuild/easyblocks/generic/cargo.py index 2808408628..8ab09fc310 100755 --- a/easybuild/easyblocks/generic/cargo.py +++ b/easybuild/easyblocks/generic/cargo.py @@ -214,30 +214,38 @@ def __init__(self, *args, **kwargs): self.cargo_home = os.path.join(self.builddir, '.cargo') self.set_cargo_vars() - # Populate sources from "crates" list of tuples - sources = [] - for crate_info in self.crates: - if len(crate_info) == 2: - sources.append({ - 'download_filename': self.crate_download_filename(*crate_info), - 'filename': self.crate_src_filename(*crate_info), - 'source_urls': [CRATESIO_SOURCE], - 'alt_location': 'crates.io', - }) - else: - crate, version, repo, rev = crate_info - url, repo_name = repo.rsplit('/', maxsplit=1) - if repo_name.endswith('.git'): - repo_name = repo_name[:-4] - sources.append({ - 'git_config': {'url': url, 'repo_name': repo_name, 'commit': rev}, - 'filename': self.crate_src_filename(crate, version, rev=rev), - }) - # copy EasyConfig instance before we make changes to it self.cfg = self.cfg.copy() - self.cfg.update('sources', sources) + if self.is_extension: + self.cfg['crates'] = self.options.get('crates', []) # Don't inherit crates from parent + # The (regular) extract step for extensions is not run so our handling of crates as (multiple) sources + # cannot be used for extensions. + if self.crates: + raise EasyBuildError(f"Extension '{self.name}' cannot have crates. " + "You can add them to the top-level config parameters when using e.g." + "the Cargo or CargoPythonBundle easyblock.") + else: + # Populate sources from "crates" list of tuples + sources = [] + for crate_info in self.crates: + if len(crate_info) == 2: + sources.append({ + 'download_filename': self.crate_download_filename(*crate_info), + 'filename': self.crate_src_filename(*crate_info), + 'source_urls': [CRATESIO_SOURCE], + 'alt_location': 'crates.io', + }) + else: + crate, version, repo, rev = crate_info + url, repo_name = repo.rsplit('/', maxsplit=1) + if repo_name.endswith('.git'): + repo_name = repo_name[:-4] + sources.append({ + 'git_config': {'url': url, 'repo_name': repo_name, 'commit': rev}, + 'filename': self.crate_src_filename(crate, version, rev=rev), + }) + self.cfg.update('sources', sources) def set_cargo_vars(self): """Set environment variables for Rust compilation and Cargo""" diff --git a/easybuild/easyblocks/generic/cargopythonbundle.py b/easybuild/easyblocks/generic/cargopythonbundle.py index 137589400b..fb9878766d 100644 --- a/easybuild/easyblocks/generic/cargopythonbundle.py +++ b/easybuild/easyblocks/generic/cargopythonbundle.py @@ -45,6 +45,7 @@ def extra_options(extra_vars=None): """Define extra easyconfig parameters specific to Cargo""" extra_vars = PythonBundle.extra_options(extra_vars) extra_vars = Cargo.extra_options(extra_vars) # not all extra options here will used here + extra_vars['default_easyblock'][0] = 'CargoPythonPackage' return extra_vars @@ -52,6 +53,7 @@ def __init__(self, *args, **kwargs): """Constructor for CargoPythonBundle easyblock.""" self.check_for_sources = False # make Bundle allow sources (as crates are treated as sources) super().__init__(*args, **kwargs) + self.cfg['exts_defaultclass'] = 'CargoPythonPackage' # Cargo inherits from ExtensionEasyBlock, thus EB treats the software itself as an extension # Setting modulename to False to ensure that sanity checks are performed on the extensions only