Skip to content

Commit

Permalink
move toolchain: preserve .exe extension for windows (MystenLabs#16218)
Browse files Browse the repository at this point in the history
## Description 

Toolchain versioned builds on windows will use `sui.exe` and invoke
`sui.exe` rather than just `sui` so that windows users don't need to
strip the `.exe` extension in order for things to work.

## Test Plan 

👀 

---
If your changes are not user-facing and do not break anything, you can
skip the following section. Otherwise, please briefly describe what has
changed under the Release Notes section.

### Type of Change (Check all that apply)

- [ ] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
  • Loading branch information
rvantonder authored Feb 15, 2024
1 parent 15ad3a6 commit 6af96d1
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions crates/sui-source-validation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ mod tests;
const CURRENT_COMPILER_VERSION: &str = env!("CARGO_PKG_VERSION");
const LEGACY_COMPILER_VERSION: &str = CURRENT_COMPILER_VERSION; // TODO: update this when Move 2024 is released
const PRE_TOOLCHAIN_MOVE_LOCK_VERSION: u64 = 0; // Used to detect lockfiles pre-toolchain versioning support
const CANONICAL_BINARY_NAME: &str = "sui";
const CANONICAL_UNIX_BINARY_NAME: &str = "sui";
const CANONICAL_WIN_BINARY_NAME: &str = "sui.exe";

#[derive(Debug, Error)]
pub enum SourceVerificationError {
Expand Down Expand Up @@ -610,12 +611,19 @@ fn download_and_compile(
) -> anyhow::Result<()> {
let dest_dir = PathBuf::from_iter([&*MOVE_HOME, "binaries"]); // E.g., ~/.move/binaries
let dest_version = dest_dir.join(compiler_version);
let mut dest_canonical_binary = dest_version.clone();
dest_canonical_binary.extend(["target", "release", CANONICAL_BINARY_NAME]);
let mut dest_canonical_path = dest_version.clone();
dest_canonical_path.extend(["target", "release"]);
let mut dest_canonical_binary = dest_canonical_path.clone();

let platform = detect_platform(&root, compiler_version, &dest_canonical_path)?;
if platform == "windows-x86_64" {
dest_canonical_binary.push(CANONICAL_WIN_BINARY_NAME);
} else {
dest_canonical_binary.push(CANONICAL_UNIX_BINARY_NAME);
}

if !dest_canonical_binary.exists() {
// Check the platform and proceed if we can download a binary. If not, the user should follow error instructions to sideload the binary.
let mut platform = detect_platform(&root, compiler_version, &dest_canonical_binary)?;
// Download if binary does not exist.
let mainnet_url = format!(
"https://github.com/MystenLabs/sui/releases/download/mainnet-v{compiler_version}/sui-mainnet-v{compiler_version}-{platform}.tgz",
Expand Down Expand Up @@ -664,10 +672,12 @@ fn download_and_compile(
.map_err(|e| anyhow!("failed to untar compiler binary: {e}"))?;

let mut dest_binary = dest_version.clone();
dest_binary.extend(["target", "release"]);
if platform == "windows-x86_64" {
platform = format!("{platform}.exe");
dest_binary.push(&format!("sui-{platform}.exe"));
} else {
dest_binary.push(&format!("sui-{platform}"));
}
dest_binary.extend(["target", "release", &format!("sui-{platform}")]);
let dest_binary_os = OsStr::new(dest_binary.as_path());
set_executable_permission(dest_binary_os)?;
std::fs::rename(dest_binary_os, dest_canonical_binary.clone())?;
Expand Down Expand Up @@ -717,15 +727,21 @@ fn detect_platform(
("macos", "x86_64") => "macos-x86_64",
("linux", "x86_64") => "ubuntu-x86_64",
("windows", "x86_64") => "windows-x86_64",
(os, arch) => bail!(
"The package {} needs to be built with sui compiler version {compiler_version} but there \
is no binary release available to download for your platform:\n\
Operating System: {os}\n\
Architecture: {arch}\n\
You can manually put a `sui` binary for your platform in {} and rerun your command to continue.",
package_path.display(),
dest_dir.display(),
),
(os, arch) => {
let mut binary_name = CANONICAL_UNIX_BINARY_NAME;
if os == "windows" {
binary_name = CANONICAL_WIN_BINARY_NAME;
};
bail!(
"The package {} needs to be built with sui compiler version {compiler_version} but there \
is no binary release available to download for your platform:\n\
Operating System: {os}\n\
Architecture: {arch}\n\
You can manually put a {binary_name} binary for your platform in {} and rerun your command to continue.",
package_path.display(),
dest_dir.display(),
)
}
};
Ok(s.into())
}
Expand Down

0 comments on commit 6af96d1

Please sign in to comment.