Skip to content

Commit 96d59bc

Browse files
authored
chore: a few minor build.rs cleanups (#1731)
1 parent 375e8af commit 96d59bc

File tree

1 file changed

+21
-28
lines changed

1 file changed

+21
-28
lines changed

build.rs

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
22
use fslock::LockFile;
33
use miniz_oxide::MZFlush;
4-
use miniz_oxide::MZResult;
54
use miniz_oxide::MZStatus;
65
use miniz_oxide::StreamResult;
76
use miniz_oxide::inflate::stream::InflateState;
@@ -102,7 +101,7 @@ fn main() {
102101

103102
// Build from source
104103
if env_bool("V8_FROM_SOURCE") {
105-
if is_asan && std::env::var_os("OPT_LEVEL").unwrap_or_default() == "0" {
104+
if is_asan && env::var_os("OPT_LEVEL").unwrap_or_default() == "0" {
106105
panic!(
107106
"v8 crate cannot be compiled with OPT_LEVEL=0 and ASAN.\nTry `[profile.dev.package.v8] opt-level = 1`.\nAborting before miscompilations cause issues."
108107
);
@@ -409,14 +408,12 @@ fn download_ninja_gn_binaries() {
409408

410409
fn prebuilt_profile() -> &'static str {
411410
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
412-
// Note: we always use the release build on windows.
413-
if target_os == "windows" {
414-
return "release";
415-
}
416411
// Use v8 in release mode unless $V8_FORCE_DEBUG=true
417-
match env_bool("V8_FORCE_DEBUG") {
418-
true => "debug",
419-
_ => "release",
412+
// Note: we always use the release build on windows.
413+
if target_os != "windows" && env_bool("V8_FORCE_DEBUG") {
414+
"debug"
415+
} else {
416+
"release"
420417
}
421418
}
422419

@@ -478,7 +475,7 @@ fn build_dir() -> PathBuf {
478475
);
479476
let out_dir_abs = cwd.join(out_dir);
480477

481-
// This would be target/debug or target/release
478+
// This would be `target/debug` or `target/release`
482479
out_dir_abs
483480
.parent()
484481
.unwrap()
@@ -502,8 +499,8 @@ fn download_file(url: &str, filename: &Path) {
502499
return;
503500
}
504501

505-
// Checksum (i.e: url) to avoid redownloads
506-
match std::fs::read_to_string(static_checksum_path(filename)) {
502+
// Checksum (i.e: url) to avoid re-downloads
503+
match fs::read_to_string(static_checksum_path(filename)) {
507504
Ok(c) if c == static_lib_url() => return,
508505
_ => {}
509506
};
@@ -522,7 +519,7 @@ fn download_file(url: &str, filename: &Path) {
522519
let tmpfile = filename.with_extension("tmp");
523520
if tmpfile.exists() {
524521
println!("Deleting old tmpfile {}", tmpfile.display());
525-
std::fs::remove_file(&tmpfile).unwrap();
522+
fs::remove_file(&tmpfile).unwrap();
526523
}
527524

528525
// Try downloading with python first. Python is a V8 build dependency,
@@ -559,9 +556,9 @@ fn download_file(url: &str, filename: &Path) {
559556
assert!(tmpfile.exists());
560557

561558
// Write checksum (i.e url) & move file
562-
std::fs::write(static_checksum_path(filename), url).unwrap();
559+
fs::write(static_checksum_path(filename), url).unwrap();
563560
copy_archive(&tmpfile.to_string_lossy(), filename);
564-
std::fs::remove_file(&tmpfile).unwrap();
561+
fs::remove_file(&tmpfile).unwrap();
565562

566563
assert!(filename.exists());
567564
assert!(static_checksum_path(filename).exists());
@@ -573,7 +570,7 @@ fn download_static_lib_binaries() {
573570
println!("static lib URL: {url}");
574571

575572
let dir = static_lib_dir();
576-
std::fs::create_dir_all(&dir).unwrap();
573+
fs::create_dir_all(&dir).unwrap();
577574
println!("cargo:rustc-link-search={}", dir.display());
578575

579576
download_file(&url, &static_lib_path());
@@ -590,7 +587,7 @@ where
590587
let mut input_offset = 0;
591588

592589
// Skip the gzip header
593-
gzip_header::read_gz_header(input).unwrap();
590+
gzip_header::read_gz_header(input)?;
594591

595592
loop {
596593
let bytes_read = input.read(&mut input_buffer[input_offset..])?;
@@ -607,9 +604,7 @@ where
607604
MZFlush::None,
608605
);
609606

610-
if status != MZResult::Ok(MZStatus::Ok)
611-
&& status != MZResult::Ok(MZStatus::StreamEnd)
612-
{
607+
if status != Ok(MZStatus::Ok) && status != Ok(MZStatus::StreamEnd) {
613608
return Err(io::Error::new(
614609
io::ErrorKind::Other,
615610
format!("Decompression error {status:?}"),
@@ -622,7 +617,7 @@ where
622617
input_buffer.copy_within(bytes_consumed..bytes_avail, 0);
623618
input_offset = bytes_avail - bytes_consumed;
624619

625-
if status == MZResult::Ok(MZStatus::StreamEnd) {
620+
if status == Ok(MZStatus::StreamEnd) {
626621
break; // End of decompression
627622
}
628623
}
@@ -632,8 +627,8 @@ where
632627

633628
/// Copy the V8 archive at `url` to `filename`.
634629
///
635-
/// This function doesn't use `std::fs::copy` because that would
636-
/// preveserve the file attributes such as ownership and mode flags.
630+
/// This function doesn't use [`fs::copy`] because that would
631+
/// preserve the file attributes such as ownership and mode flags.
637632
/// Instead, it copies the file contents to a new file.
638633
/// This is necessary because the V8 archive could live inside a read-only
639634
/// filesystem, and subsequent builds would fail to overwrite it.
@@ -837,8 +832,7 @@ fn maybe_symlink_root_dir(dirs: &mut Dirs) {
837832
// different drive than the output. If this is the case we'll create a
838833
// symlink called 'gn_root' in the out directory, next to 'gn_out', so it
839834
// appears as if they're both on the same drive.
840-
use std::fs::remove_dir_all;
841-
use std::fs::remove_file;
835+
use fs::{remove_dir_all, remove_file};
842836
use std::os::windows::fs::symlink_dir;
843837

844838
let get_prefix = |p: &Path| {
@@ -992,7 +986,7 @@ pub fn build(target: &str, maybe_env: Option<NinjaEnv>) {
992986
.success()
993987
);
994988

995-
// TODO This is not sufficent. We need to use "gn desc" to query the target
989+
// TODO This is not sufficient. We need to use "gn desc" to query the target
996990
// and figure out what else we need to add to the link.
997991
println!(
998992
"cargo:rustc-link-search=native={}/obj/",
@@ -1046,8 +1040,7 @@ pub fn parse_ninja_deps(s: &str) -> HashSet<String> {
10461040
out
10471041
}
10481042

1049-
/// A parser for the output of "ninja -t graph". It returns all of the input
1050-
/// files.
1043+
/// A parser for the output of "ninja -t graph". It returns all the input files.
10511044
pub fn parse_ninja_graph(s: &str) -> HashSet<String> {
10521045
let mut out = HashSet::new();
10531046
// This is extremely hacky and likely to break.

0 commit comments

Comments
 (0)