Skip to content

feat: continue Windows implementation #1729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions crates/fig_os_shim/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ fn append(a: impl AsRef<Path>, b: impl AsRef<Path>) -> PathBuf {

// If b has a drive letter and it's different from a's drive letter (if any),
// we need to handle it specially
let result_path = if let Some(b_drive) = b_drive {
if let Some(b_drive) = b_drive {
if a_str.starts_with(b_drive) {
// Same drive, continue with normal processing
let path_str = b_without_drive;
Expand Down Expand Up @@ -600,9 +600,7 @@ fn append(a: impl AsRef<Path>, b: impl AsRef<Path>) -> PathBuf {
}

a_path.join(b_normalized)
};

result_path
}
}

#[cfg(test)]
Expand Down
84 changes: 83 additions & 1 deletion crates/fig_proto/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,17 @@ fn protoc_version() -> Option<Version> {

fn download_protoc() {
let protoc_version = "26.1";

let tmp_folder = tempfile::tempdir().unwrap();

#[cfg(not(windows))]
download_protoc_unix(protoc_version, &tmp_folder);

#[cfg(windows)]
download_protoc_windows(protoc_version, &tmp_folder);
}

#[cfg(not(windows))]
fn download_protoc_unix(protoc_version: &str, tmp_folder: &tempfile::TempDir) {
let os = match std::env::consts::OS {
"linux" => "linux",
"macos" => "osx",
Expand Down Expand Up @@ -88,6 +96,80 @@ fn download_protoc() {
std::env::set_var("PROTOC", out_bin);
}

#[cfg(windows)]
fn download_protoc_windows(protoc_version: &str, tmp_folder: &tempfile::TempDir) {
// Determine Windows architecture (win32 or win64)
let win_arch = match std::env::consts::ARCH {
"x86_64" => "win64",
"x86" => "win32",
arch => panic!("Unsupported Windows architecture: {arch}"),
};

// Windows-specific checksums
let checksum = match win_arch {
"win64" => "9090d135a1159042b13b4e51b210e40cb820d85a5032a6eca5f9b3ca3bdfb539",
"win32" => "11fc8f280922e86d917e30f7b9960a1e77453f64990d965080697b394a8d9d74",
_ => unreachable!(),
};

// Windows-specific URL format
let download_url = format!(
"https://github.com/protocolbuffers/protobuf/releases/download/v{protoc_version}/protoc-{protoc_version}-{win_arch}.zip"
);

eprintln!("Downloading protoc from: {download_url}");

// Download using curl (assuming curl is available on Windows)
let mut download_command = Command::new("curl");
download_command
.arg("-Lf")
.arg(download_url)
.arg("-o")
.arg(tmp_folder.path().join("protoc.zip"));
assert!(download_command.spawn().unwrap().wait().unwrap().success());

// Verify checksum using PowerShell
let mut checksum_command = Command::new("powershell");
checksum_command.arg("-Command").arg(format!(
"(Get-FileHash -Path '{}' -Algorithm SHA256).Hash.ToLower()",
tmp_folder.path().join("protoc.zip").display()
));
let checksum_output = checksum_command.output().unwrap();
let checksum_output = String::from_utf8(checksum_output.stdout).unwrap().trim().to_lowercase();

eprintln!("checksum: {checksum_output:?}");
assert_eq!(
checksum_output,
checksum.to_lowercase(),
"Checksum verification failed. Expected: {}, Got: {}",
checksum.to_lowercase(),
checksum_output
);

// Extract using PowerShell
let mut unzip_command = Command::new("powershell");
unzip_command.arg("-Command").arg(format!(
"Expand-Archive -Path '{}' -DestinationPath '{}' -Force",
tmp_folder.path().join("protoc.zip").display(),
tmp_folder.path().display()
));
assert!(unzip_command.spawn().unwrap().wait().unwrap().success());

// Set output path with .exe extension for Windows
let out_bin = PathBuf::from(std::env::var("OUT_DIR").unwrap()).join("protoc.exe");

// Copy the protoc binary using PowerShell
let mut copy_command = Command::new("powershell");
copy_command.arg("-Command").arg(format!(
"Copy-Item -Path '{}' -Destination '{}'",
tmp_folder.path().join("bin").join("protoc.exe").display(),
out_bin.display()
));
assert!(copy_command.spawn().unwrap().wait().unwrap().success());

std::env::set_var("PROTOC", out_bin);
}

fn main() -> Result<()> {
println!("cargo:rerun-if-changed=build.rs");

Expand Down
1 change: 1 addition & 0 deletions crates/fig_util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ windows = { version = "0.58.0", features = [
"Win32_System_Kernel",
"Win32_System_ProcessStatus",
"Win32_System_Threading",
"Wdk_System_Threading",
] }
winreg = "0.55.0"

Expand Down
Loading
Loading