Skip to content

Commit 56aac35

Browse files
messensetiran
andcommitted
Properly handle Cargo manifest path
Co-authored-by: Christian Heimes <[email protected]>
1 parent 4b969ea commit 56aac35

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

setuptools_rust/setuptools_ext.py

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from setuptools.command.build_ext import build_ext
77
from setuptools.command.install import install
88
from distutils.command.sdist import sdist
9+
import sys
910
import subprocess
1011

1112
try:
@@ -40,17 +41,37 @@ def initialize_options(self):
4041

4142
def get_file_list(self):
4243
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)
5475
super().get_file_list()
5576
dist.cmdclass["sdist"] = sdist_rust_extension
5677

0 commit comments

Comments
 (0)