Update .rustfmt.toml

This commit is contained in:
Taiki Endo
2023-09-27 21:35:58 +09:00
parent 0831efaca4
commit d90c734ca8
2 changed files with 71 additions and 72 deletions

View File

@@ -1 +1,32 @@
edition = "2021" # Rustfmt configuration
# https://github.com/rust-lang/rustfmt/blob/HEAD/Configurations.md
# Rustfmt cannot format long lines inside macros, but this option detects this.
# This is unstable (tracking issue: https://github.com/rust-lang/rustfmt/issues/3391)
error_on_line_overflow = true
# Override the default formatting style.
# See https://internals.rust-lang.org/t/running-rustfmt-on-rust-lang-rust-and-other-rust-lang-repositories/8732/81.
use_small_heuristics = "Max"
# See https://github.com/rust-dev-tools/fmt-rfcs/issues/149.
# This is unstable (tracking issue: https://github.com/rust-lang/rustfmt/issues/3370)
overflow_delimited_expr = true
# This is unstable (tracking issue: none).
imports_granularity = "Crate"
# This is unstable (tracking issue: none).
group_imports = "StdExternalCrate"
# Apply rustfmt to more places.
# This is unstable (tracking issue: https://github.com/rust-lang/rustfmt/issues/3348).
format_code_in_doc_comments = true
# Automatically fix deprecated style.
use_field_init_shorthand = true
use_try_shorthand = true
# Set the default settings again to always apply the proper formatting without
# being affected by the editor settings.
edition = "2018"
hard_tabs = false
newline_style = "Unix"
tab_spaces = 4

View File

@@ -1,9 +1,5 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT // SPDX-License-Identifier: Apache-2.0 OR MIT
use anyhow::{bail, Context as _, Result};
use fs_err as fs;
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use std::{ use std::{
cmp::Reverse, cmp::Reverse,
collections::{BTreeMap, BTreeSet}, collections::{BTreeMap, BTreeSet},
@@ -15,6 +11,11 @@ use std::{
time::Duration, time::Duration,
}; };
use anyhow::{bail, Context as _, Result};
use fs_err as fs;
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
fn main() -> Result<()> { fn main() -> Result<()> {
let args: Vec<_> = env::args().skip(1).collect(); let args: Vec<_> = env::args().skip(1).collect();
if args.is_empty() || args.iter().any(|arg| arg.starts_with('-')) { if args.is_empty() || args.iter().any(|arg| arg.starts_with('-')) {
@@ -26,17 +27,13 @@ fn main() -> Result<()> {
let package = &args[0]; let package = &args[0];
let workspace_root = &workspace_root(); let workspace_root = &workspace_root();
let manifest_path = &workspace_root let manifest_path = &workspace_root.join("manifests").join(format!("{package}.json"));
.join("manifests")
.join(format!("{package}.json"));
let download_cache_dir = &workspace_root.join("tools/codegen/tmp/cache").join(package); let download_cache_dir = &workspace_root.join("tools/codegen/tmp/cache").join(package);
fs::create_dir_all(manifest_path.parent().unwrap())?; fs::create_dir_all(manifest_path.parent().unwrap())?;
fs::create_dir_all(download_cache_dir)?; fs::create_dir_all(download_cache_dir)?;
let mut base_info: BaseManifest = serde_json::from_slice(&fs::read( let mut base_info: BaseManifest = serde_json::from_slice(&fs::read(
workspace_root workspace_root.join("tools/codegen/base").join(format!("{package}.json")),
.join("tools/codegen/base")
.join(format!("{package}.json")),
)?)?; )?)?;
let repo = base_info let repo = base_info
.repository .repository
@@ -77,11 +74,8 @@ fn main() -> Result<()> {
.collect(); .collect();
let mut crates_io_info = None; let mut crates_io_info = None;
base_info.rust_crate = base_info base_info.rust_crate =
.rust_crate base_info.rust_crate.as_ref().map(|s| replace_vars(s, package, None, None)).transpose()?;
.as_ref()
.map(|s| replace_vars(s, package, None, None))
.transpose()?;
if let Some(crate_name) = &base_info.rust_crate { if let Some(crate_name) = &base_info.rust_crate {
eprintln!("downloading crate info from https://crates.io/api/v1/crates/{crate_name}"); eprintln!("downloading crate info from https://crates.io/api/v1/crates/{crate_name}");
crates_io_info = Some( crates_io_info = Some(
@@ -113,10 +107,7 @@ fn main() -> Result<()> {
for (platform, d) in &mut manifest.download_info { for (platform, d) in &mut manifest.download_info {
let template = &template.download_info[platform]; let template = &template.download_info[platform];
d.url = Some(template.url.replace("${version}", version)); d.url = Some(template.url.replace("${version}", version));
d.bin = template d.bin = template.bin.as_ref().map(|s| s.replace("${version}", version));
.bin
.as_ref()
.map(|s| s.replace("${version}", version));
} }
} }
} }
@@ -231,19 +222,16 @@ fn main() -> Result<()> {
let hash = format!("{hash:x}"); let hash = format!("{hash:x}");
eprintln!("{hash} *{asset_name}"); eprintln!("{hash} *{asset_name}");
download_info.insert( download_info.insert(platform, ManifestDownloadInfo {
platform, url: Some(url),
ManifestDownloadInfo { checksum: hash,
url: Some(url), bin: base_download_info
checksum: hash, .bin
bin: base_download_info .as_ref()
.bin .or(base_info.bin.as_ref())
.as_ref() .map(|s| replace_vars(s, package, Some(version), Some(platform)))
.or(base_info.bin.as_ref()) .transpose()?,
.map(|s| replace_vars(s, package, Some(version), Some(platform))) });
.transpose()?,
},
);
buf.clear(); buf.clear();
} }
if download_info.is_empty() { if download_info.is_empty() {
@@ -295,39 +283,30 @@ fn main() -> Result<()> {
if !(version.major == 0 && version.minor == 0) { if !(version.major == 0 && version.minor == 0) {
manifests.map.insert( manifests.map.insert(
Reverse(Version::omitted(version.major, Some(version.minor))), Reverse(Version::omitted(version.major, Some(version.minor))),
ManifestRef::Ref { ManifestRef::Ref { version: version.clone().into() },
version: version.clone().into(),
},
); );
} }
if version.major != 0 { if version.major != 0 {
manifests.map.insert( manifests
Reverse(Version::omitted(version.major, None)), .map
ManifestRef::Ref { .insert(Reverse(Version::omitted(version.major, None)), ManifestRef::Ref {
version: version.clone().into(), version: version.clone().into(),
}, });
);
} }
prev_version = version; prev_version = version;
} }
manifests.map.insert( manifests.map.insert(Reverse(Version::latest()), ManifestRef::Ref {
Reverse(Version::latest()), version: prev_version.clone().into(),
ManifestRef::Ref { });
version: prev_version.clone().into(),
},
);
} }
let ManifestRef::Ref { let ManifestRef::Ref { version: latest_version } =
version: latest_version, manifests.map.first_key_value().unwrap().1.clone()
} = manifests.map.first_key_value().unwrap().1.clone()
else { else {
unreachable!() unreachable!()
}; };
if latest_only { if latest_only {
manifests manifests.map.retain(|k, _| k.0 == Version::latest() || k.0 == latest_version);
.map
.retain(|k, _| k.0 == Version::latest() || k.0 == latest_version);
} }
let ManifestRef::Real(latest_manifest) = &manifests.map[&Reverse(latest_version.clone())] let ManifestRef::Real(latest_manifest) = &manifests.map[&Reverse(latest_version.clone())]
else { else {
@@ -338,16 +317,12 @@ fn main() -> Result<()> {
continue; continue;
} }
if p == HostPlatform::x86_64_linux_gnu if p == HostPlatform::x86_64_linux_gnu
&& latest_manifest && latest_manifest.download_info.contains_key(&HostPlatform::x86_64_linux_musl)
.download_info
.contains_key(&HostPlatform::x86_64_linux_musl)
{ {
continue; continue;
} }
if p == HostPlatform::aarch64_linux_gnu if p == HostPlatform::aarch64_linux_gnu
&& latest_manifest && latest_manifest.download_info.contains_key(&HostPlatform::aarch64_linux_musl)
.download_info
.contains_key(&HostPlatform::aarch64_linux_musl)
{ {
continue; continue;
} }
@@ -358,9 +333,7 @@ fn main() -> Result<()> {
} }
let original_manifests = manifests.clone(); let original_manifests = manifests.clone();
let mut template = Some(ManifestTemplate { let mut template = Some(ManifestTemplate { download_info: BTreeMap::new() });
download_info: BTreeMap::new(),
});
'outer: for (version, manifest) in &mut manifests.map { 'outer: for (version, manifest) in &mut manifests.map {
let ManifestRef::Real(manifest) = manifest else { let ManifestRef::Real(manifest) = manifest else {
continue; continue;
@@ -376,13 +349,10 @@ fn main() -> Result<()> {
break 'outer; break 'outer;
} }
} else { } else {
t.download_info.insert( t.download_info.insert(*platform, ManifestTemplateDownloadInfo {
*platform, url: template_url,
ManifestTemplateDownloadInfo { bin: template_bin,
url: template_url, });
bin: template_bin,
},
);
} }
} }
} }
@@ -587,9 +557,7 @@ impl<'de> Deserialize<'de> for Version {
D: serde::Deserializer<'de>, D: serde::Deserializer<'de>,
{ {
use serde::de::Error as _; use serde::de::Error as _;
String::deserialize(deserializer)? String::deserialize(deserializer)?.parse().map_err(D::Error::custom)
.parse()
.map_err(D::Error::custom)
} }
} }