Skip to content

Commit 284ddf6

Browse files
committed
Append cargo vendor config to existing cargo config file
1 parent 56aac35 commit 284ddf6

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

setuptools_rust/setuptools_ext.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def initialize_options(self):
4040
self.vendor_crates = 0
4141

4242
def get_file_list(self):
43+
super().get_file_list()
4344
if self.vendor_crates:
4445
manifest_paths = []
4546
for ext in self.distribution.rust_extensions:
@@ -68,11 +69,23 @@ def get_file_list(self):
6869
cargo_config = cargo_config.replace(base_dir_bytes + os.sep.encode(), b'')
6970
if os.altsep:
7071
cargo_config = cargo_config.replace(base_dir_bytes + os.altsep.encode(), b'')
72+
73+
# Check whether `.cargo/config`/`.cargo/config.toml` already exists
74+
existing_cargo_config = None
75+
for filename in (".cargo/config", ".cargo/config.toml"):
76+
if filename in self.filelist.allfiles:
77+
existing_cargo_config = filename
78+
break
79+
if existing_cargo_config:
80+
cargo_config_path = os.path.join(base_dir, existing_cargo_config)
81+
# Append vendor config to original cargo config
82+
with open(existing_cargo_config, "rb") as f:
83+
cargo_config = f.read() + b'\n' + cargo_config
84+
7185
with open(cargo_config_path, "wb") as f:
7286
f.write(cargo_config)
7387
self.filelist.append(vendor_path)
7488
self.filelist.append(cargo_config_path)
75-
super().get_file_list()
7689
dist.cmdclass["sdist"] = sdist_rust_extension
7790

7891
build_ext_base_class = dist.cmdclass.get('build_ext', build_ext)

0 commit comments

Comments
 (0)