Skip to content

Commit 6366f56

Browse files
committed
Only extract core if bundled-core is missing
1 parent ceff82f commit 6366f56

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ fn main() {
7373

7474
To update and build the MoonBit core library:
7575

76-
- See (and update) the printed moonbit version in `build.rs`
76+
- Delete the `bundled-core` directory
77+
- Rebuild the crate (this will create a `core` directory), see (and update) the printed moonbit version in `build.rs`
7778
- curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash -s -- 0.6.32+6f48aae3f
7879
- `Use ./update-bundle.sh
7980

build.rs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ fn main() -> Result<()> {
2222
.context("Failed to get CARGO_MANIFEST_DIR environment variable")?;
2323
let dest_path = PathBuf::from(out_dir.clone()).join(FINAL_FILE_NAME);
2424
let manifest_path = PathBuf::from(manifest_dir);
25+
let bundled_core_path = manifest_path.join("bundled-core");
2526

2627
// Download the file using reqwest (blocking)
2728
// Using a blocking request is simpler in a build script
@@ -72,29 +73,31 @@ fn main() -> Result<()> {
7273
println!("cargo:warning={:?} = {:?}", str, version.trim());
7374
}
7475
if str == CORE_TGZ {
75-
println!("cargo:info=Found core.tar.gz in archive, extracting to core",);
76-
let core_tgz_path = PathBuf::from(out_dir.clone()).join("core.tar.gz");
77-
entry.unpack(&core_tgz_path).with_context(|| {
78-
format!("Failed to unpack file {:?} to {:?}", path, core_tgz_path)
79-
})?;
80-
let bytes = std::fs::read(core_tgz_path)
81-
.with_context(|| format!("Failed to read file {:?}", path))?;
82-
let core_tar = GzDecoder::new(bytes.as_slice());
83-
let mut core_archive = Archive::new(core_tar);
76+
if !bundled_core_path.exists() {
77+
println!("cargo:info=Found core.tar.gz in archive, extracting to core",);
78+
let core_tgz_path = PathBuf::from(out_dir.clone()).join("core.tar.gz");
79+
entry.unpack(&core_tgz_path).with_context(|| {
80+
format!("Failed to unpack file {:?} to {:?}", path, core_tgz_path)
81+
})?;
82+
let bytes = std::fs::read(core_tgz_path)
83+
.with_context(|| format!("Failed to read file {:?}", path))?;
84+
let core_tar = GzDecoder::new(bytes.as_slice());
85+
let mut core_archive = Archive::new(core_tar);
8486

85-
let core_target = manifest_path.clone();
86-
let core_dir = manifest_path.join("core");
87-
if core_dir.exists() {
88-
std::fs::remove_dir_all(core_dir).with_context(|| {
89-
format!(
90-
"Failed to remove directory {:?}",
91-
manifest_path.join("core")
92-
)
87+
let core_target = manifest_path.clone();
88+
let core_dir = manifest_path.join("core");
89+
if core_dir.exists() {
90+
std::fs::remove_dir_all(core_dir).with_context(|| {
91+
format!(
92+
"Failed to remove directory {:?}",
93+
manifest_path.join("core")
94+
)
95+
})?;
96+
}
97+
core_archive.unpack(&core_target).with_context(|| {
98+
format!("Failed to unpack file {:?} to {:?}", path, core_target)
9399
})?;
94100
}
95-
core_archive.unpack(&core_target).with_context(|| {
96-
format!("Failed to unpack file {:?} to {:?}", path, core_target)
97-
})?;
98101
}
99102
}
100103
}

0 commit comments

Comments
 (0)