Skip to content

Commit

Permalink
rustPlatform.fetchCargoVendor: Support 'cargo-vendor --no-merge-sourc…
Browse files Browse the repository at this point in the history
…es' feature
  • Loading branch information
junjihashimoto committed Jan 27, 2025
1 parent 356c02d commit 60fe186
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkgs/build-support/rust/fetch-cargo-vendor-util.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,15 @@ def extract_crate_tarball_contents(tarball_path: Path, crate_out_dir: Path) -> N
def create_vendor(vendor_staging_dir: Path, out_dir: Path) -> None:
lockfile_path = vendor_staging_dir / "Cargo.lock"
out_dir.mkdir(exist_ok=True)
(out_dir / "registry").mkdir(exist_ok=True)
shutil.copy(lockfile_path, out_dir / "Cargo.lock")

cargo_lock_toml = load_toml(lockfile_path)
lockfile_version = get_lockfile_version(cargo_lock_toml)

config_lines = [
'[source.vendored-sources]',
'directory = "@vendor@"',
'directory = "@vendor@/registry"',
'[source.crates-io]',
'replace-with = "vendored-sources"',
]
Expand All @@ -246,14 +247,15 @@ def create_vendor(vendor_staging_dir: Path, out_dir: Path) -> None:
source: str = pkg["source"]

dir_name = f"{pkg["name"]}-{pkg["version"]}"
crate_out_dir = out_dir / dir_name

if source.startswith("git+"):

source_info = parse_git_source(pkg["source"], lockfile_version)

git_sha_rev = source_info["git_sha_rev"]
git_tree = vendor_staging_dir / "git" / git_sha_rev
(out_dir / f"git-{git_sha_rev}").mkdir(exist_ok=True)
crate_out_dir = out_dir / f"git-{git_sha_rev}" / dir_name

copy_and_patch_git_crate_subtree(git_tree, pkg["name"], crate_out_dir)

Expand All @@ -272,10 +274,13 @@ def create_vendor(vendor_staging_dir: Path, out_dir: Path) -> None:
config_lines.append(f'git = "{source_info["url"]}"')
if source_info["type"] is not None:
config_lines.append(f'{source_info["type"]} = "{source_info["value"]}"')
config_lines.append('replace-with = "vendored-sources"')
config_lines.append(f'replace-with = "vendored-sources-git-{git_sha_rev}"')
config_lines.append(f'[source.vendored-sources-git-{git_sha_rev}]')
config_lines.append(f'directory = "@vendor@/git-{git_sha_rev}"')

elif source.startswith("registry+"):

crate_out_dir = out_dir / "registry" / dir_name
filename = f"{pkg["name"]}-{pkg["version"]}.tar.gz"
tarball_path = vendor_staging_dir / "tarballs" / filename

Expand Down

0 comments on commit 60fe186

Please sign in to comment.