|
6 | 6 | from setuptools.command.build_ext import build_ext
|
7 | 7 | from setuptools.command.install import install
|
8 | 8 | from distutils.command.sdist import sdist
|
| 9 | +import sys |
9 | 10 | import subprocess
|
10 | 11 |
|
11 | 12 | try:
|
@@ -40,17 +41,37 @@ def initialize_options(self):
|
40 | 41 |
|
41 | 42 | def get_file_list(self):
|
42 | 43 | if self.vendor_crates:
|
43 |
| - base_dir = self.distribution.get_fullname() |
44 |
| - vendor_path = os.path.join(base_dir, "vendored-crates") |
45 |
| - cargo_config = subprocess.check_output(["cargo", "vendor", vendor_path]) |
46 |
| - cargo_config = cargo_config.replace(base_dir.encode() + b'/', b'') |
47 |
| - dot_cargo_path = os.path.join(base_dir, ".cargo") |
48 |
| - self.mkpath(dot_cargo_path) |
49 |
| - cargo_config_path = os.path.join(dot_cargo_path, "config.toml") |
50 |
| - with open(cargo_config_path, "wb") as f: |
51 |
| - f.write(cargo_config) |
52 |
| - self.filelist.append(vendor_path) |
53 |
| - self.filelist.append(cargo_config_path) |
| 44 | + manifest_paths = [] |
| 45 | + for ext in self.distribution.rust_extensions: |
| 46 | + manifest_paths.append(ext.path) |
| 47 | + if manifest_paths: |
| 48 | + base_dir = self.distribution.get_fullname() |
| 49 | + dot_cargo_path = os.path.join(base_dir, ".cargo") |
| 50 | + self.mkpath(dot_cargo_path) |
| 51 | + cargo_config_path = os.path.join(dot_cargo_path, "config.toml") |
| 52 | + vendor_path = os.path.join(dot_cargo_path, "vendor") |
| 53 | + command = [ |
| 54 | + "cargo", "vendor" |
| 55 | + ] |
| 56 | + # additional Cargo.toml for extension 1..n |
| 57 | + for extra_path in manifest_paths[1:]: |
| 58 | + command.append("--sync") |
| 59 | + command.append(extra_path) |
| 60 | + # `cargo vendor --sync` accepts multiple values, for example |
| 61 | + # `cargo vendor --sync a --sync b --sync c vendor_path` |
| 62 | + # but it would also consider vendor_path as --sync value |
| 63 | + # set --manifest-path before vendor_path and after --sync to workaround that |
| 64 | + # See https://docs.rs/clap/latest/clap/struct.Arg.html#method.multiple for detail |
| 65 | + command.extend(["--manifest-path", manifest_paths[0], vendor_path]) |
| 66 | + cargo_config = subprocess.check_output(command) |
| 67 | + base_dir_bytes = base_dir.encode(sys.getfilesystemencoding()) |
| 68 | + cargo_config = cargo_config.replace(base_dir_bytes + os.sep.encode(), b'') |
| 69 | + if os.altsep: |
| 70 | + cargo_config = cargo_config.replace(base_dir_bytes + os.altsep.encode(), b'') |
| 71 | + with open(cargo_config_path, "wb") as f: |
| 72 | + f.write(cargo_config) |
| 73 | + self.filelist.append(vendor_path) |
| 74 | + self.filelist.append(cargo_config_path) |
54 | 75 | super().get_file_list()
|
55 | 76 | dist.cmdclass["sdist"] = sdist_rust_extension
|
56 | 77 |
|
|
0 commit comments