1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302
//! Config types (for workspace.metadata.dist)
use std::collections::{BTreeMap, HashMap};
use axoasset::{toml_edit, SourceFile};
use axoproject::{WorkspaceKind, WorkspaceSearch};
use camino::{Utf8Path, Utf8PathBuf};
use miette::Report;
use semver::Version;
use serde::{Deserialize, Serialize};
use tracing::log::warn;
use crate::errors::Result;
use crate::{
errors::{DistError, DistResult},
TargetTriple, METADATA_DIST,
};
/// A container to assist deserializing metadata from generic, non-Cargo projects
#[derive(Debug, Deserialize)]
struct GenericConfig {
/// The dist field within dist.toml
dist: DistMetadata,
}
/// Contents of METADATA_DIST in Cargo.toml files
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
#[serde(rename_all = "kebab-case")]
pub struct DistMetadata {
/// The intended version of cargo-dist to build with. (normal Cargo SemVer syntax)
///
/// When generating full tasks graphs (such as CI scripts) we will pick this version.
///
/// FIXME: Should we produce a warning if running locally with a different version? In theory
/// it shouldn't be a problem and newer versions should just be Better... probably you
/// Really want to have the exact version when running generate to avoid generating
/// things other cargo-dist versions can't handle!
#[serde(skip_serializing_if = "Option::is_none")]
pub cargo_dist_version: Option<Version>,
/// (deprecated) The intended version of Rust/Cargo to build with (rustup toolchain syntax)
///
/// When generating full tasks graphs (such as CI scripts) we will pick this version.
#[serde(skip_serializing_if = "Option::is_none")]
pub rust_toolchain_version: Option<String>,
/// Whether the package should be distributed/built by cargo-dist
///
/// This mainly exists to be set to `false` to make cargo-dist ignore the existence of this
/// package. Note that we may still build the package as a side-effect of building the
/// workspace -- we just won't bundle it up and report it.
///
/// FIXME: maybe you should also be allowed to make this a list of binary names..?
#[serde(skip_serializing_if = "Option::is_none")]
pub dist: Option<bool>,
/// CI environments you wish to target.
///
/// Currently only accepts "github".
///
/// When running `generate` this list will be used if it's Some, otherwise all known
/// CI backends will be used.
#[serde(skip_serializing_if = "Option::is_none")]
pub ci: Option<Vec<CiStyle>>,
/// Which actions to run on pull requests.
///
/// "upload" will build and upload release artifacts, while "plan" will
/// only plan out the release without running builds and "skip" will disable
/// pull request runs entirely.
#[serde(skip_serializing_if = "Option::is_none")]
pub pr_run_mode: Option<cargo_dist_schema::PrRunMode>,
/// Generate targets whose cargo-dist should avoid checking for up-to-dateness.
#[serde(skip_serializing_if = "Option::is_none")]
pub allow_dirty: Option<Vec<GenerateMode>>,
/// The full set of installers you would like to produce
///
/// When generating full task graphs (such as CI scripts) we will try to generate these.
///
/// Some installers can be generated on any platform (like shell scripts) while others
/// may (currently) require platform-specific toolchains (like .msi installers). Some
/// installers may also be "per release" while others are "per build". Again, shell script
/// vs msi is a good comparison here -- you want a universal shell script that figures
/// out which binary to install, but you might end up with an msi for each supported arch!
///
/// Currently accepted values:
///
/// * shell
/// * powershell
#[serde(skip_serializing_if = "Option::is_none")]
pub installers: Option<Vec<InstallerStyle>>,
/// A Homebrew tap to push the Homebrew formula to, if built
pub tap: Option<String>,
/// A set of packages to install before building
#[serde(rename = "dependencies")]
#[serde(skip_serializing_if = "Option::is_none")]
pub system_dependencies: Option<SystemDependencies>,
/// The full set of target triples to build for.
///
/// When generating full task graphs (such as CI scripts) we will to try to generate these.
///
/// The inputs should be valid rustc target triples (see `rustc --print target-list`) such
/// as `x86_64-pc-windows-msvc`, `aarch64-apple-darwin`, or `x86_64-unknown-linux-gnu`.
///
/// FIXME: We should also accept one magic target: `universal2-apple-darwin`. This will induce
/// us to build `x86_64-apple-darwin` and `aarch64-apple-darwin` (arm64) and then combine
/// them into a "universal" binary that can run on either arch (using apple's `lipo` tool).
///
/// FIXME: Allow higher level requests like "[macos, windows, linux] x [x86_64, aarch64]"?
#[serde(skip_serializing_if = "Option::is_none")]
pub targets: Option<Vec<String>>,
/// Include the following static files in bundles like archives.
///
/// Paths are relative to the Cargo.toml this is defined in.
///
/// Files like `README*`, `(UN)LICENSE*`, `RELEASES*`, and `CHANGELOG*` are already
/// automatically detected and included (use [`DistMetadata::auto_includes`][] to prevent this).
#[serde(skip_serializing_if = "Option::is_none")]
pub include: Option<Vec<Utf8PathBuf>>,
/// Whether to auto-include files like `README*`, `(UN)LICENSE*`, `RELEASES*`, and `CHANGELOG*`
///
/// Defaults to true.
#[serde(skip_serializing_if = "Option::is_none")]
pub auto_includes: Option<bool>,
/// Whether msvc targets should statically link the crt
///
/// Defaults to true.
#[serde(skip_serializing_if = "Option::is_none")]
pub msvc_crt_static: Option<bool>,
/// The archive format to use for windows builds (defaults .zip)
#[serde(skip_serializing_if = "Option::is_none")]
pub windows_archive: Option<ZipStyle>,
/// The archive format to use for non-windows builds (defaults .tar.xz)
#[serde(skip_serializing_if = "Option::is_none")]
pub unix_archive: Option<ZipStyle>,
/// A scope to prefix npm packages with (@ should be included).
///
/// This is required if you're using an npm installer.
#[serde(skip_serializing_if = "Option::is_none")]
pub npm_scope: Option<String>,
/// A scope to prefix npm packages with (@ should be included).
///
/// This is required if you're using an npm installer.
#[serde(skip_serializing_if = "Option::is_none")]
pub checksum: Option<ChecksumStyle>,
/// Build only the required packages, and individually (since 0.1.0) (default: false)
///
/// By default when we need to build anything in your workspace, we build your entire workspace
/// with --workspace. This setting tells cargo-dist to instead build each app individually.
///
/// On balance, the Rust experts we've consulted with find building with --workspace to
/// be a safer/better default, as it provides some of the benefits of a more manual
/// [workspace-hack][], without the user needing to be aware that this is a thing.
///
/// TL;DR: cargo prefers building one copy of each dependency in a build, so if two apps in
/// your workspace depend on e.g. serde with different features, building with --workspace,
/// will build serde once with the features unioned together. However if you build each
/// package individually it will more precisely build two copies of serde with different
/// feature sets.
///
/// The downside of using --workspace is that if your workspace has lots of example/test
/// crates, or if you release only parts of your workspace at a time, we build a lot of
/// gunk that's not needed, and potentially bloat up your app with unnecessary features.
///
/// If that downside is big enough for you, this setting is a good idea.
///
/// [workspace-hack]: https://docs.rs/cargo-hakari/latest/cargo_hakari/about/index.html
#[serde(skip_serializing_if = "Option::is_none")]
pub precise_builds: Option<bool>,
/// Whether we should try to merge otherwise-parallelizable tasks onto the same machine,
/// sacrificing latency and fault-isolation for more the sake of minor effeciency gains.
///
/// (defaults to false)
///
/// For example, if you build for x64 macos and arm64 macos, by default we will generate ci
/// which builds those independently on separate logical machines. With this enabled we will
/// build both of those platforms together on the same machine, making it take twice as long
/// as any other build and making it impossible for only one of them to succeed.
#[serde(skip_serializing_if = "Option::is_none")]
pub merge_tasks: Option<bool>,
/// Whether failing tasks should make us give up on all other tasks
///
/// (defaults to false)
///
/// When building a release you might discover that an obscure platform's build is broken.
/// When this happens you have two options: give up on the release entirely (`fail-fast = true`),
/// or keep trying to build all the other platforms anyway (`fail-fast = false`).
///
/// cargo-dist was designed around the "keep trying" approach, as we create a draft Release
/// and upload results to it over time, undrafting the release only if all tasks succeeded.
/// The idea is that even if a platform fails to build, you can decide that's acceptable
/// and manually undraft the release with some missing platforms.
///
/// (Note that the dist-manifest.json is produced before anything else, and so it will assume
/// that all tasks succeeded when listing out supported platforms/artifacts. This may make
/// you sad if you do this kind of undrafting and also trust the dist-manifest to be correct.)
///
/// Prior to 0.1.0 we didn't set the correct flags in our CI scripts to do this, but now we do.
/// This flag was introduced to allow you to restore the old behaviour if you prefer.
#[serde(skip_serializing_if = "Option::is_none")]
pub fail_fast: Option<bool>,
/// Whether CI should include logic to build local artifacts (default true)
///
/// If false, it will be assumed that the local_artifacts_jobs will include custom
/// jobs to build them.
#[serde(skip_serializing_if = "Option::is_none")]
pub build_local_artifacts: Option<bool>,
/// Whether CI should trigger releases by dispatch instead of tag push (default false)
#[serde(skip_serializing_if = "Option::is_none")]
pub dispatch_releases: Option<bool>,
/// The strategy to use for selecting a path to install things at:
///
/// * `CARGO_HOME`: (default) install as if cargo did
/// (try `$CARGO_HOME/bin/`, but if `$CARGO_HOME` isn't set use `$HOME/.cargo/bin/`)
/// * `~/some/subdir/`: install to the given subdir of the user's `$HOME`
/// * `$SOME_VAR/some/subdir`: install to the given subdir of the dir defined by `$SOME_VAR`
///
/// All of these error out if the required env-vars aren't set. In the future this may
/// allow for the input to be an array of options to try in sequence.
#[serde(skip_serializing_if = "Option::is_none")]
pub install_path: Option<InstallPathStrategy>,
/// A list of features to enable when building a package with cargo-dist
///
/// (defaults to none)
#[serde(skip_serializing_if = "Option::is_none")]
pub features: Option<Vec<String>>,
/// Whether to enable when building a package with cargo-dist
///
/// (defaults to true)
#[serde(skip_serializing_if = "Option::is_none")]
pub default_features: Option<bool>,
/// Whether to enable all features building a package with cargo-dist
///
/// (defaults to false)
#[serde(skip_serializing_if = "Option::is_none")]
pub all_features: Option<bool>,
/// Plan jobs to run in CI
///
/// The core plan job is always run, but this allows additional hooks
/// to be added to the process to run concurrently with plan.
#[serde(skip_serializing_if = "Option::is_none")]
pub plan_jobs: Option<Vec<JobStyle>>,
/// Local artifacts jobs to run in CI
///
/// The core build job is always run, but this allows additional hooks
/// to be added to the process to run concurrently with "upload local artifacts".
#[serde(skip_serializing_if = "Option::is_none")]
pub local_artifacts_jobs: Option<Vec<JobStyle>>,
/// Global artifacts jobs to run in CI
///
/// The core build job is always run, but this allows additional hooks
/// to be added to the process to run concurrently with "upload global artifacts".
#[serde(skip_serializing_if = "Option::is_none")]
pub global_artifacts_jobs: Option<Vec<JobStyle>>,
/// Host jobs to run in CI
///
/// The core build job is always run, but this allows additional hooks
/// to be added to the process to run concurrently with host.
#[serde(skip_serializing_if = "Option::is_none")]
pub host_jobs: Option<Vec<JobStyle>>,
/// Publish jobs to run in CI
///
/// (defaults to none)
#[serde(skip_serializing_if = "Option::is_none")]
pub publish_jobs: Option<Vec<PublishStyle>>,
/// Post-announce jobs to run in CI
///
/// This allows custom jobs to be configured to run after the announce job
// runs in its entirety.
#[serde(skip_serializing_if = "Option::is_none")]
pub post_announce_jobs: Option<Vec<JobStyle>>,
/// Whether to publish prereleases to package managers
///
/// (defaults to false)
#[serde(skip_serializing_if = "Option::is_none")]
pub publish_prereleases: Option<bool>,
/// Whether we should create the Github Release for you when you push a tag.
///
/// If true (default), cargo-dist will create a new Github Release and generate
/// a title/body for it based on your changelog.
///
/// If false, cargo-dist will assume a draft Github Release already exists
/// with the title/body you want. At the end of a successful publish it will
/// undraft the Github Release.
#[serde(skip_serializing_if = "Option::is_none")]
pub create_release: Option<bool>,
/// \[unstable\] Whether we should sign windows binaries with ssl.com
#[serde(skip_serializing_if = "Option::is_none")]
pub ssldotcom_windows_sign: Option<ProductionMode>,
/// Hosting provider
#[serde(skip_serializing_if = "Option::is_none")]
pub hosting: Option<Vec<HostingStyle>>,
/// Any extra artifacts and their buildscripts
#[serde(skip_serializing_if = "Option::is_none")]
pub extra_artifacts: Option<Vec<ExtraArtifact>>,
/// Custom GitHub runners, mapped by triple target
#[serde(skip_serializing_if = "Option::is_none")]
pub github_custom_runners: Option<HashMap<String, String>>,
}
impl DistMetadata {
/// Apply the base path to any relative paths contained in this DistMetadata
pub fn make_relative_to(&mut self, base_path: &Utf8Path) {
// This is intentionally written awkwardly to make you update it
let DistMetadata {
cargo_dist_version: _,
rust_toolchain_version: _,
dist: _,
ci: _,
installers: _,
tap: _,
system_dependencies: _,
targets: _,
include,
auto_includes: _,
windows_archive: _,
unix_archive: _,
npm_scope: _,
checksum: _,
precise_builds: _,
fail_fast: _,
merge_tasks: _,
build_local_artifacts: _,
dispatch_releases: _,
install_path: _,
features: _,
default_features: _,
all_features: _,
plan_jobs: _,
local_artifacts_jobs: _,
global_artifacts_jobs: _,
host_jobs: _,
publish_jobs: _,
post_announce_jobs: _,
publish_prereleases: _,
create_release: _,
pr_run_mode: _,
allow_dirty: _,
ssldotcom_windows_sign: _,
msvc_crt_static: _,
hosting: _,
extra_artifacts: _,
github_custom_runners: _,
} = self;
if let Some(include) = include {
for include in include {
*include = base_path.join(&*include);
}
}
}
/// Merge a workspace config into a package config (self)
pub fn merge_workspace_config(
&mut self,
workspace_config: &Self,
package_manifest_path: &Utf8Path,
) {
// This is intentionally written awkwardly to make you update it
let DistMetadata {
cargo_dist_version,
rust_toolchain_version,
dist,
ci,
installers,
tap,
system_dependencies,
targets,
include,
auto_includes,
windows_archive,
unix_archive,
npm_scope,
checksum,
precise_builds,
merge_tasks,
fail_fast,
build_local_artifacts,
dispatch_releases,
install_path,
features,
default_features,
all_features,
plan_jobs,
local_artifacts_jobs,
global_artifacts_jobs,
host_jobs,
publish_jobs,
post_announce_jobs,
publish_prereleases,
create_release,
pr_run_mode,
allow_dirty,
ssldotcom_windows_sign,
msvc_crt_static,
hosting,
extra_artifacts,
github_custom_runners,
} = self;
// Check for global settings on local packages
if cargo_dist_version.is_some() {
warn!("package.metadata.dist.cargo-dist-version is set, but this is only accepted in workspace.metadata (value is being ignored): {}", package_manifest_path);
}
if rust_toolchain_version.is_some() {
warn!("package.metadata.dist.rust-toolchain-version is set, but this is only accepted in workspace.metadata (value is being ignored): {}", package_manifest_path);
}
if ci.is_some() {
warn!("package.metadata.dist.ci is set, but this is only accepted in workspace.metadata (value is being ignored): {}", package_manifest_path);
}
if precise_builds.is_some() {
warn!("package.metadata.dist.precise-builds is set, but this is only accepted in workspace.metadata (value is being ignored): {}", package_manifest_path);
}
if merge_tasks.is_some() {
warn!("package.metadata.dist.merge-tasks is set, but this is only accepted in workspace.metadata (value is being ignored): {}", package_manifest_path);
}
if fail_fast.is_some() {
warn!("package.metadata.dist.fail-fast is set, but this is only accepted in workspace.metadata (value is being ignored): {}", package_manifest_path);
}
if build_local_artifacts.is_some() {
warn!("package.metadata.dist.build-local-artifacts is set, but this is only accepted in workspace.metadata (value is being ignored): {}", package_manifest_path);
}
if dispatch_releases.is_some() {
warn!("package.metadata.dist.dispatch-releases is set, but this is only accepted in workspace.metadata (value is being ignored): {}", package_manifest_path);
}
if create_release.is_some() {
warn!("package.metadata.dist.create-release is set, but this is only accepted in workspace.metadata (value is being ignored): {}", package_manifest_path);
}
// Arguably should be package-local for things like msi installers, but doesn't make sense for CI,
// so let's not support that yet for its complexity!
if allow_dirty.is_some() {
warn!("package.metadata.dist.allow-dirty is set, but this is only accepted in workspace.metadata (value is being ignored): {}", package_manifest_path);
}
if publish_prereleases.is_some() {
warn!("package.metadata.dist.publish-prereleases is set, but this is only accepted in workspace.metadata (value is being ignored): {}", package_manifest_path);
}
if pr_run_mode.is_some() {
warn!("package.metadata.dist.pr-run-mode is set, but this is only accepted in workspace.metadata (value is being ignored): {}", package_manifest_path);
}
if ssldotcom_windows_sign.is_some() {
warn!("package.metadata.dist.ssldotcom-windows-sign is set, but this is only accepted in workspace.metadata (value is being ignored): {}", package_manifest_path);
}
if msvc_crt_static.is_some() {
warn!("package.metadata.dist.msvc-crt-static is set, but this is only accepted in workspace.metadata (value is being ignored): {}", package_manifest_path);
}
if hosting.is_some() {
warn!("package.metadata.dist.hosting is set, but this is only accepted in workspace.metadata (value is being ignored): {}", package_manifest_path);
}
if plan_jobs.is_some() {
warn!("package.metadata.dist.plan-jobs is set, but this is only accepted in workspace.metadata (value is being ignored): {}", package_manifest_path);
}
if local_artifacts_jobs.is_some() {
warn!("package.metadata.dist.local-artifacts-jobs is set, but this is only accepted in workspace.metadata (value is being ignored): {}", package_manifest_path);
}
if global_artifacts_jobs.is_some() {
warn!("package.metadata.dist.global-artifacts-jobs is set, but this is only accepted in workspace.metadata (value is being ignored): {}", package_manifest_path);
}
if host_jobs.is_some() {
warn!("package.metadata.dist.host-jobs is set, but this is only accepted in workspace.metadata (value is being ignored): {}", package_manifest_path);
}
if publish_jobs.is_some() {
warn!("package.metadata.dist.publish-jobs is set, but this is only accepted in workspace.metadata (value is being ignored): {}", package_manifest_path);
}
if post_announce_jobs.is_some() {
warn!("package.metadata.dist.post-announce-jobs is set, but this is only accepted in workspace.metadata (value is being ignored): {}", package_manifest_path);
}
// Merge non-global settings
if installers.is_none() {
*installers = workspace_config.installers.clone();
}
if targets.is_none() {
*targets = workspace_config.targets.clone();
}
if dist.is_none() {
*dist = workspace_config.dist;
}
if auto_includes.is_none() {
*auto_includes = workspace_config.auto_includes;
}
if windows_archive.is_none() {
*windows_archive = workspace_config.windows_archive;
}
if unix_archive.is_none() {
*unix_archive = workspace_config.unix_archive;
}
if npm_scope.is_none() {
*npm_scope = workspace_config.npm_scope.clone();
}
if checksum.is_none() {
*checksum = workspace_config.checksum;
}
if install_path.is_none() {
*install_path = workspace_config.install_path.clone();
}
if features.is_none() {
*features = workspace_config.features.clone();
}
if default_features.is_none() {
*default_features = workspace_config.default_features;
}
if all_features.is_none() {
*all_features = workspace_config.all_features;
}
if tap.is_none() {
*tap = workspace_config.tap.clone();
}
if system_dependencies.is_none() {
*system_dependencies = workspace_config.system_dependencies.clone();
}
if extra_artifacts.is_none() {
*extra_artifacts = workspace_config.extra_artifacts.clone();
}
if github_custom_runners.is_none() {
*github_custom_runners = workspace_config.github_custom_runners.clone();
}
// This was historically implemented as extend, but I'm not convinced the
// inconsistency is worth the inconvenience...
if let Some(include) = include {
if let Some(workspace_include) = &workspace_config.include {
include.extend(workspace_include.iter().cloned());
}
} else {
*include = workspace_config.include.clone();
}
}
}
/// Global config for commands
#[derive(Debug, Clone)]
pub struct Config {
/// Whether we need to compute an announcement tag or if we can fudge it
///
/// Commands like generate and init don't need announcements, but want to run gather_work
pub needs_coherent_announcement_tag: bool,
/// Whether to actually try to side-effectfully create a hosting directory on a server
///
/// this is used for compute_hosting
pub create_hosting: bool,
/// The subset of artifacts we want to build
pub artifact_mode: ArtifactMode,
/// Whether local paths to files should be in the final dist json output
pub no_local_paths: bool,
/// If true, override allow-dirty in the config and ignore all dirtyness
pub allow_all_dirty: bool,
/// Target triples we want to build for
pub targets: Vec<TargetTriple>,
/// CI kinds we want to support
pub ci: Vec<CiStyle>,
/// Installers we want to generate
pub installers: Vec<InstallerStyle>,
/// The (git) tag to use for this Announcement.
pub announcement_tag: Option<String>,
}
/// How we should select the artifacts to build
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ArtifactMode {
/// Build target-specific artifacts like archives, symbols, msi installers
Local,
/// Build globally unique artifacts like curl-sh installers, npm packages, metadata...
Global,
/// Fuzzily build "as much as possible" for the host system
Host,
/// Build all the artifacts; only really appropriate for `cargo-dist manifest`
All,
/// Fake all the artifacts; useful for testing/mocking/staging
Lies,
}
/// The style of CI we should generate
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
#[serde(rename_all = "kebab-case")]
pub enum CiStyle {
/// Generate Github CI
Github,
}
impl CiStyle {
/// If the CI provider provides a native release hosting system, get it
pub(crate) fn native_hosting(&self) -> Option<HostingStyle> {
match self {
CiStyle::Github => Some(HostingStyle::Github),
}
}
}
impl std::fmt::Display for CiStyle {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let string = match self {
CiStyle::Github => "github",
};
string.fmt(f)
}
}
/// The style of Installer we should generate
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
pub enum InstallerStyle {
/// Generate a shell script that fetches from [`cargo_dist_schema::Release::artifact_download_url`][]
Shell,
/// Generate a powershell script that fetches from [`cargo_dist_schema::Release::artifact_download_url`][]
Powershell,
/// Generate an npm project that fetches from [`cargo_dist_schema::Release::artifact_download_url`][]
Npm,
/// Generate a Homebrew formula that fetches from [`cargo_dist_schema::Release::artifact_download_url`][]
Homebrew,
/// Generate an msi installer that embeds the binary
Msi,
}
impl std::fmt::Display for InstallerStyle {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let string = match self {
InstallerStyle::Shell => "shell",
InstallerStyle::Powershell => "powershell",
InstallerStyle::Npm => "npm",
InstallerStyle::Homebrew => "homebrew",
InstallerStyle::Msi => "msi",
};
string.fmt(f)
}
}
/// The style of hosting we should use for artifacts
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
pub enum HostingStyle {
/// Host on Github Releases
Github,
/// Host on Axo Releases ("Abyss")
Axodotdev,
}
impl std::fmt::Display for HostingStyle {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let string = match self {
HostingStyle::Github => "github",
HostingStyle::Axodotdev => "axodotdev",
};
string.fmt(f)
}
}
/// The publish jobs we should run
#[derive(Clone, Debug, Serialize, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
pub enum PublishStyle {
/// Publish a Homebrew formula to a tap repository
Homebrew,
/// User-supplied value
User(String),
}
impl std::str::FromStr for PublishStyle {
type Err = DistError;
fn from_str(s: &str) -> DistResult<Self> {
if let Some(slug) = s.strip_prefix("./") {
Ok(Self::User(slug.to_owned()))
} else if s == "homebrew" {
Ok(Self::Homebrew)
} else {
Err(DistError::UnrecognizedStyle {
style: s.to_owned(),
})
}
}
}
impl<'de> serde::Deserialize<'de> for PublishStyle {
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
use serde::de::Error;
let path = String::deserialize(deserializer)?;
path.parse().map_err(|e| D::Error::custom(format!("{e}")))
}
}
impl std::fmt::Display for PublishStyle {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
PublishStyle::Homebrew => write!(f, "homebrew"),
PublishStyle::User(s) => write!(f, "./{s}"),
}
}
}
/// Extra CI jobs we should run
#[derive(Clone, Debug, Serialize, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
pub enum JobStyle {
/// User-supplied value
User(String),
}
impl std::str::FromStr for JobStyle {
type Err = DistError;
fn from_str(s: &str) -> DistResult<Self> {
if let Some(slug) = s.strip_prefix("./") {
Ok(Self::User(slug.to_owned()))
} else {
Err(DistError::UnrecognizedStyle {
style: s.to_owned(),
})
}
}
}
impl<'de> serde::Deserialize<'de> for JobStyle {
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
use serde::de::Error;
let path = String::deserialize(deserializer)?;
path.parse().map_err(|e| D::Error::custom(format!("{e}")))
}
}
impl std::fmt::Display for JobStyle {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
JobStyle::User(s) => write!(f, "./{s}"),
}
}
}
/// The style of zip/tarball to make
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ZipStyle {
/// `.zip`
Zip,
/// `.tar.<compression>`
Tar(CompressionImpl),
/// Don't bundle/compress this, it's just a temp dir
TempDir,
}
/// Compression impls (used by [`ZipStyle::Tar`][])
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum CompressionImpl {
/// `.gz`
Gzip,
/// `.xz`
Xzip,
/// `.zstd`
Zstd,
}
impl ZipStyle {
/// Get the extension used for this kind of zip
pub fn ext(&self) -> &'static str {
match self {
ZipStyle::TempDir => "",
ZipStyle::Zip => ".zip",
ZipStyle::Tar(compression) => match compression {
CompressionImpl::Gzip => ".tar.gz",
CompressionImpl::Xzip => ".tar.xz",
CompressionImpl::Zstd => ".tar.zstd",
},
}
}
}
impl Serialize for ZipStyle {
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.ext())
}
}
impl<'de> Deserialize<'de> for ZipStyle {
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
use serde::de::Error;
let ext = String::deserialize(deserializer)?;
match &*ext {
".zip" => Ok(ZipStyle::Zip),
".tar.gz" => Ok(ZipStyle::Tar(CompressionImpl::Gzip)),
".tar.xz" => Ok(ZipStyle::Tar(CompressionImpl::Xzip)),
".tar.zstd" => Ok(ZipStyle::Tar(CompressionImpl::Zstd)),
_ => Err(D::Error::custom(format!(
"unknown archive format {ext}, expected one of: .zip, .tar.gz, .tar.xz, .tar.zstd"
))),
}
}
}
/// key for the install-path config that selects [`InstallPathStrategyCargoHome`][]
const CARGO_HOME_INSTALL_PATH: &str = "CARGO_HOME";
/// Strategy for install binaries
#[derive(Debug, Clone)]
pub enum InstallPathStrategy {
/// install to $CARGO_HOME, falling back to ~/.cargo/
CargoHome,
/// install to this subdir of the user's home
///
/// syntax: `~/subdir`
HomeSubdir {
/// The subdir of home to install to
subdir: String,
},
/// install to this subdir of this env var
///
/// syntax: `$ENV_VAR/subdir`
EnvSubdir {
/// The env var to get the base of the path from
env_key: String,
/// The subdir to install to
subdir: String,
},
}
impl std::str::FromStr for InstallPathStrategy {
type Err = DistError;
fn from_str(path: &str) -> DistResult<Self> {
if path == CARGO_HOME_INSTALL_PATH {
Ok(InstallPathStrategy::CargoHome)
} else if let Some(subdir) = path.strip_prefix("~/") {
if subdir.is_empty() {
Err(DistError::InstallPathHomeSubdir {
path: path.to_owned(),
})
} else {
Ok(InstallPathStrategy::HomeSubdir {
// If there's a trailing slash, strip it to be uniform
subdir: subdir.strip_suffix('/').unwrap_or(subdir).to_owned(),
})
}
} else if let Some(val) = path.strip_prefix('$') {
if let Some((env_key, subdir)) = val.split_once('/') {
Ok(InstallPathStrategy::EnvSubdir {
env_key: env_key.to_owned(),
// If there's a trailing slash, strip it to be uniform
subdir: subdir.strip_suffix('/').unwrap_or(subdir).to_owned(),
})
} else {
Err(DistError::InstallPathEnvSlash {
path: path.to_owned(),
})
}
} else {
Err(DistError::InstallPathInvalid {
path: path.to_owned(),
})
}
}
}
impl std::fmt::Display for InstallPathStrategy {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
InstallPathStrategy::CargoHome => write!(f, "{}", CARGO_HOME_INSTALL_PATH),
InstallPathStrategy::HomeSubdir { subdir } => write!(f, "~/{subdir}"),
InstallPathStrategy::EnvSubdir { env_key, subdir } => write!(f, "${env_key}/{subdir}"),
}
}
}
impl serde::Serialize for InstallPathStrategy {
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(&self.to_string())
}
}
impl<'de> serde::Deserialize<'de> for InstallPathStrategy {
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
use serde::de::Error;
let path = String::deserialize(deserializer)?;
path.parse().map_err(|e| D::Error::custom(format!("{e}")))
}
}
/// Strategy for install binaries (replica to have different Serialize for jinja)
///
/// The serialize/deserialize impls are already required for loading/saving the config
/// from toml/json, and that serialize impl just creates a plain string again. To allow
/// jinja templates to have richer context we have use duplicate type with a more
/// conventional derived serialize.
#[derive(Debug, Clone, Serialize)]
#[serde(tag = "kind")]
pub enum JinjaInstallPathStrategy {
/// install to $CARGO_HOME, falling back to ~/.cargo/
CargoHome,
/// install to this subdir of the user's home
///
/// syntax: `~/subdir`
HomeSubdir {
/// The subdir of home to install to
subdir: String,
},
/// install to this subdir of this env var
///
/// syntax: `$ENV_VAR/subdir`
EnvSubdir {
/// The env var to get the base of the path from
env_key: String,
/// The subdir to install to
subdir: String,
},
}
impl InstallPathStrategy {
/// Convert this into a jinja-friendly form
pub fn into_jinja(self) -> JinjaInstallPathStrategy {
match self {
InstallPathStrategy::CargoHome => JinjaInstallPathStrategy::CargoHome,
InstallPathStrategy::HomeSubdir { subdir } => {
JinjaInstallPathStrategy::HomeSubdir { subdir }
}
InstallPathStrategy::EnvSubdir { env_key, subdir } => {
JinjaInstallPathStrategy::EnvSubdir { env_key, subdir }
}
}
}
}
/// A checksumming algorithm
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum ChecksumStyle {
/// sha256sum (using the sha2 crate)
Sha256,
/// sha512sum (using the sha2 crate)
Sha512,
/// Do not checksum
False,
}
impl ChecksumStyle {
/// Get the extension of a checksum
pub fn ext(self) -> &'static str {
match self {
ChecksumStyle::Sha256 => "sha256",
ChecksumStyle::Sha512 => "sha512",
ChecksumStyle::False => "false",
}
}
}
/// Which style(s) of configuration to generate
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum GenerateMode {
/// Generate CI scripts for orchestrating cargo-dist
#[serde(rename = "ci")]
Ci,
/// Generate wsx (WiX) templates for msi installers
#[serde(rename = "msi")]
Msi,
}
impl std::fmt::Display for GenerateMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
GenerateMode::Ci => "ci".fmt(f),
GenerateMode::Msi => "msi".fmt(f),
}
}
}
/// Arguments to `cargo dist host`
#[derive(Clone, Debug)]
pub struct HostArgs {
/// Which hosting steps to run
pub steps: Vec<HostStyle>,
}
/// What parts of hosting to perform
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum HostStyle {
/// Check that hosting API keys are working
Check,
/// Create a location to host artifacts
Create,
/// Upload artifacts
Upload,
/// Release artifacts
Release,
/// Announce artifacts
Announce,
}
/// Packages to install before build from the system package manager
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct SystemDependencies {
/// Packages to install in Homebrew
#[serde(default)]
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
// #[serde(with = "sysdep_derive")]
pub homebrew: BTreeMap<String, SystemDependency>,
/// Packages to install in apt
#[serde(default)]
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
pub apt: BTreeMap<String, SystemDependency>,
/// Package to install in Chocolatey
#[serde(default)]
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
pub chocolatey: BTreeMap<String, SystemDependency>,
}
impl SystemDependencies {
/// Extends `self` with the elements of `other`.
pub fn append(&mut self, other: &mut Self) {
self.homebrew.append(&mut other.homebrew);
self.apt.append(&mut other.apt);
self.chocolatey.append(&mut other.chocolatey);
}
}
/// Represents a package from a system package manager
// newtype wrapper to hang a manual derive impl off of
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize)]
pub struct SystemDependency(pub SystemDependencyComplex);
/// Backing type for SystemDependency
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)]
pub struct SystemDependencyComplex {
/// The version to install, as expected by the underlying package manager
pub version: Option<String>,
/// Stages at which the dependency is required
#[serde(default)]
pub stage: Vec<DependencyKind>,
/// One or more targets this package should be installed on; defaults to all targets if not specified
#[serde(default)]
pub targets: Vec<String>,
}
impl SystemDependencyComplex {
/// Checks if this dependency should be installed on the specified target.
pub fn wanted_for_target(&self, target: &String) -> bool {
if self.targets.is_empty() {
true
} else {
self.targets.contains(target)
}
}
/// Checks if this dependency should used in the specified stage.
pub fn stage_wanted(&self, stage: &DependencyKind) -> bool {
if self.stage.is_empty() {
match stage {
DependencyKind::Build => true,
DependencyKind::Run => false,
}
} else {
self.stage.contains(stage)
}
}
}
/// Definition for a single package
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SystemDependencyKind {
/// Simple specification format, parsed as cmake = 'version'
/// The special string "*" is parsed as a None version
Untagged(String),
/// Complex specification format
Tagged(SystemDependencyComplex),
}
/// Provides detail on when a specific dependency is required
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum DependencyKind {
/// A dependency that must be present when the software is being built
Build,
/// A dependency that must be present when the software is being used
Run,
}
impl std::fmt::Display for DependencyKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
DependencyKind::Build => "build".fmt(f),
DependencyKind::Run => "run".fmt(f),
}
}
}
impl<'de> Deserialize<'de> for SystemDependency {
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let kind: SystemDependencyKind = SystemDependencyKind::deserialize(deserializer)?;
let res = match kind {
SystemDependencyKind::Untagged(version) => {
let v = if version == "*" { None } else { Some(version) };
SystemDependencyComplex {
version: v,
stage: vec![],
targets: vec![],
}
}
SystemDependencyKind::Tagged(dep) => dep,
};
Ok(SystemDependency(res))
}
}
/// Settings for which Generate targets can be dirty
#[derive(Debug, Clone)]
pub enum DirtyMode {
/// Allow only these targets
AllowList(Vec<GenerateMode>),
/// Allow all targets
AllowAll,
}
impl DirtyMode {
/// Do we need to run this Generate Mode
pub fn should_run(&self, mode: GenerateMode) -> bool {
match self {
DirtyMode::AllowAll => false,
DirtyMode::AllowList(list) => !list.contains(&mode),
}
}
}
/// For features that can be generated in "test" or "production" mode
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum ProductionMode {
/// test mode
Test,
/// production mode
Prod,
}
/// An extra artifact to upload alongside the release tarballs,
/// and the build command which produces it.
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ExtraArtifact {
/// The build command to invoke
pub build: Vec<String>,
/// The artifact(s) produced via this build script
pub artifacts: Vec<String>,
}
impl std::fmt::Display for ProductionMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ProductionMode::Test => "test".fmt(f),
ProductionMode::Prod => "prod".fmt(f),
}
}
}
pub(crate) fn parse_metadata_table_or_manifest(
workspace_type: WorkspaceKind,
manifest_path: &Utf8Path,
metadata_table: Option<&serde_json::Value>,
) -> DistResult<DistMetadata> {
match workspace_type {
// Pre-parsed Rust metadata table
WorkspaceKind::Rust => parse_metadata_table(manifest_path, metadata_table),
// Generic dist.toml
WorkspaceKind::Generic => {
let config: GenericConfig =
SourceFile::load_local(manifest_path)?.deserialize_toml()?;
Ok(config.dist)
}
}
}
pub(crate) fn parse_metadata_table(
manifest_path: &Utf8Path,
metadata_table: Option<&serde_json::Value>,
) -> DistResult<DistMetadata> {
Ok(metadata_table
.and_then(|t| t.get(METADATA_DIST))
.map(DistMetadata::deserialize)
.transpose()
.map_err(|cause| DistError::CargoTomlParse {
manifest_path: manifest_path.to_owned(),
cause,
})?
.unwrap_or_default())
}
/// Get the general info about the project (via axo-project)
pub fn get_project() -> Result<axoproject::WorkspaceInfo> {
let start_dir = std::env::current_dir().expect("couldn't get current working dir!?");
let start_dir = Utf8PathBuf::from_path_buf(start_dir).expect("project path isn't utf8!?");
let workspaces = axoproject::get_workspaces(&start_dir, None);
let mut missing = vec![];
for ws in [workspaces.rust, workspaces.generic] {
match ws {
WorkspaceSearch::Found(mut workspace) => {
// This is a goofy as heck workaround for two facts:
// * the convenient Report approach requires us to provide an Error by-val
// * many error types (like std::io::Error) don't impl Clone, so we can't
// clone axoproject Errors.
//
// So we temporarily take ownership of the warnings and then pull them back
// out of the Report with runtime reflection to put them back in :)
let mut warnings = std::mem::take(&mut workspace.warnings);
for warning in warnings.drain(..) {
let report = Report::new(warning);
warn!("{:?}", report);
workspace.warnings.push(report.downcast().unwrap());
}
return Ok(workspace);
}
WorkspaceSearch::Broken {
manifest_path: _,
cause,
} => {
return Err(Report::new(cause)
.wrap_err("We encountered an issue trying to read your workspace"))
}
// Ignore the missing case; iterate through to the next project type
WorkspaceSearch::Missing(e) => missing.push(e),
}
}
Err(Report::new(DistError::ProjectMissing { sources: missing }))
}
/// Load a Cargo.toml into toml-edit form
pub fn load_cargo_toml(manifest_path: &Utf8Path) -> DistResult<toml_edit::Document> {
let src = axoasset::SourceFile::load_local(manifest_path)?;
let toml = src.deserialize_toml_edit()?;
Ok(toml)
}
/// Save a Cargo.toml from toml-edit form
pub fn save_cargo_toml(manifest_path: &Utf8Path, toml: toml_edit::Document) -> DistResult<()> {
let toml_text = toml.to_string();
axoasset::LocalAsset::write_new(&toml_text, manifest_path)?;
Ok(())
}
/// Get the `[workspace.metadata]` or `[package.metadata]` (based on `is_workspace`)
pub fn get_toml_metadata(
toml: &mut toml_edit::Document,
is_workspace: bool,
) -> &mut toml_edit::Item {
// Walk down/prepare the components...
let root_key = if is_workspace { "workspace" } else { "package" };
let workspace = toml[root_key].or_insert(toml_edit::table());
if let Some(t) = workspace.as_table_mut() {
t.set_implicit(true)
}
let metadata = workspace["metadata"].or_insert(toml_edit::table());
if let Some(t) = metadata.as_table_mut() {
t.set_implicit(true)
}
metadata
}