mirror of
https://github.com/EasyTier/EasyTier.git
synced 2024-11-16 03:32:43 +08:00
cca105e91d
Some checks are pending
EasyTier Core / pre_job (push) Waiting to run
EasyTier Core / build (linux-aarch64, ubuntu-latest, aarch64-unknown-linux-musl) (push) Blocked by required conditions
EasyTier Core / build (linux-arm, ubuntu-latest, arm-unknown-linux-musleabi) (push) Blocked by required conditions
EasyTier Core / build (linux-armhf, ubuntu-latest, arm-unknown-linux-musleabihf) (push) Blocked by required conditions
EasyTier Core / build (linux-armv7, ubuntu-latest, armv7-unknown-linux-musleabi) (push) Blocked by required conditions
EasyTier Core / build (linux-armv7hf, ubuntu-latest, armv7-unknown-linux-musleabihf) (push) Blocked by required conditions
EasyTier Core / build (linux-mips, ubuntu-latest, mips-unknown-linux-musl) (push) Blocked by required conditions
EasyTier Core / build (linux-mipsel, ubuntu-latest, mipsel-unknown-linux-musl) (push) Blocked by required conditions
EasyTier Core / build (linux-x86_64, ubuntu-latest, x86_64-unknown-linux-musl) (push) Blocked by required conditions
EasyTier Core / build (macos-aarch64, macos-latest, aarch64-apple-darwin) (push) Blocked by required conditions
EasyTier Core / build (macos-x86_64, macos-latest, x86_64-apple-darwin) (push) Blocked by required conditions
EasyTier Core / build (windows-x86_64, windows-latest, x86_64-pc-windows-msvc) (push) Blocked by required conditions
EasyTier Core / core-result (push) Blocked by required conditions
EasyTier GUI / pre_job (push) Waiting to run
EasyTier GUI / build-gui (linux-aarch64, aarch64-unknown-linux-gnu, ubuntu-latest, aarch64-unknown-linux-musl) (push) Blocked by required conditions
EasyTier GUI / build-gui (linux-x86_64, x86_64-unknown-linux-gnu, ubuntu-latest, x86_64-unknown-linux-musl) (push) Blocked by required conditions
EasyTier GUI / build-gui (macos-aarch64, aarch64-apple-darwin, macos-latest, aarch64-apple-darwin) (push) Blocked by required conditions
EasyTier GUI / build-gui (macos-x86_64, x86_64-apple-darwin, macos-latest, x86_64-apple-darwin) (push) Blocked by required conditions
EasyTier GUI / build-gui (windows-x86_64, x86_64-pc-windows-msvc, windows-latest, x86_64-pc-windows-msvc) (push) Blocked by required conditions
EasyTier GUI / gui-result (push) Blocked by required conditions
EasyTier Mobile / pre_job (push) Waiting to run
EasyTier Mobile / build-mobile (android, ubuntu-latest, android) (push) Blocked by required conditions
EasyTier Mobile / mobile-result (push) Blocked by required conditions
EasyTier Test / pre_job (push) Waiting to run
EasyTier Test / test (push) Blocked by required conditions
143 lines
4.3 KiB
Rust
143 lines
4.3 KiB
Rust
#[cfg(target_os = "windows")]
|
|
use std::{
|
|
env,
|
|
fs::File,
|
|
io::{copy, Cursor},
|
|
path::PathBuf,
|
|
};
|
|
|
|
#[cfg(target_os = "windows")]
|
|
struct WindowsBuild {}
|
|
|
|
#[cfg(target_os = "windows")]
|
|
impl WindowsBuild {
|
|
fn check_protoc_exist() -> Option<PathBuf> {
|
|
let path = env::var_os("PROTOC").map(PathBuf::from);
|
|
if path.is_some() && path.as_ref().unwrap().exists() {
|
|
return path;
|
|
}
|
|
|
|
let path = env::var_os("PATH").unwrap_or_default();
|
|
for p in env::split_paths(&path) {
|
|
let p = p.join("protoc.exe");
|
|
if p.exists() && p.is_file() {
|
|
return Some(p);
|
|
}
|
|
}
|
|
|
|
None
|
|
}
|
|
|
|
fn get_cargo_target_dir() -> Result<std::path::PathBuf, Box<dyn std::error::Error>> {
|
|
let out_dir = std::path::PathBuf::from(std::env::var("OUT_DIR")?);
|
|
let profile = std::env::var("PROFILE")?;
|
|
let mut target_dir = None;
|
|
let mut sub_path = out_dir.as_path();
|
|
while let Some(parent) = sub_path.parent() {
|
|
if parent.ends_with(&profile) {
|
|
target_dir = Some(parent);
|
|
break;
|
|
}
|
|
sub_path = parent;
|
|
}
|
|
let target_dir = target_dir.ok_or("not found")?;
|
|
Ok(target_dir.to_path_buf())
|
|
}
|
|
|
|
fn download_protoc() -> PathBuf {
|
|
println!("cargo:info=use exist protoc: {:?}", "k");
|
|
let out_dir = Self::get_cargo_target_dir().unwrap();
|
|
let fname = out_dir.join("protoc");
|
|
if fname.exists() {
|
|
println!("cargo:info=use exist protoc: {:?}", fname);
|
|
return fname;
|
|
}
|
|
|
|
println!("cargo:info=need download protoc, please wait...");
|
|
|
|
let url = "https://github.com/protocolbuffers/protobuf/releases/download/v26.0-rc1/protoc-26.0-rc-1-win64.zip";
|
|
let response = reqwest::blocking::get(url).unwrap();
|
|
println!("{:?}", response);
|
|
let mut content = response
|
|
.bytes()
|
|
.map(|v| v.to_vec())
|
|
.map(Cursor::new)
|
|
.map(zip::ZipArchive::new)
|
|
.unwrap()
|
|
.unwrap();
|
|
let protoc_zipped_file = content.by_name("bin/protoc.exe").unwrap();
|
|
let mut content = protoc_zipped_file;
|
|
|
|
copy(&mut content, &mut File::create(&fname).unwrap()).unwrap();
|
|
|
|
fname
|
|
}
|
|
|
|
pub fn check_for_win() {
|
|
// add third_party dir to link search path
|
|
println!("cargo:rustc-link-search=native=easytier/third_party/");
|
|
let protoc_path = if let Some(o) = Self::check_protoc_exist() {
|
|
println!("cargo:info=use os exist protoc: {:?}", o);
|
|
o
|
|
} else {
|
|
Self::download_protoc()
|
|
};
|
|
std::env::set_var("PROTOC", protoc_path);
|
|
}
|
|
}
|
|
|
|
fn workdir() -> Option<String> {
|
|
if let Ok(cargo_manifest_dir) = std::env::var("CARGO_MANIFEST_DIR") {
|
|
return Some(cargo_manifest_dir);
|
|
}
|
|
|
|
let dest = std::env::var("OUT_DIR");
|
|
if dest.is_err() {
|
|
return None;
|
|
}
|
|
let dest = dest.unwrap();
|
|
|
|
let seperator = regex::Regex::new(r"(/target/(.+?)/build/)|(\\target\\(.+?)\\build\\)")
|
|
.expect("Invalid regex");
|
|
let parts = seperator.split(dest.as_str()).collect::<Vec<_>>();
|
|
|
|
if parts.len() >= 2 {
|
|
return Some(parts[0].to_string());
|
|
}
|
|
|
|
None
|
|
}
|
|
|
|
fn check_locale() {
|
|
let workdir = workdir().unwrap_or("./".to_string());
|
|
|
|
let locale_path = format!("{workdir}/**/locales/**/*");
|
|
if let Ok(globs) = globwalk::glob(locale_path) {
|
|
for entry in globs {
|
|
if let Err(e) = entry {
|
|
println!("cargo:i18n-error={}", e);
|
|
continue;
|
|
}
|
|
|
|
let entry = entry.unwrap().into_path();
|
|
println!("cargo:rerun-if-changed={}", entry.display());
|
|
}
|
|
}
|
|
}
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
#[cfg(target_os = "windows")]
|
|
WindowsBuild::check_for_win();
|
|
|
|
tonic_build::configure()
|
|
.type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]")
|
|
.type_attribute("cli.DirectConnectedPeerInfo", "#[derive(Hash)]")
|
|
.type_attribute("cli.PeerInfoForGlobalMap", "#[derive(Hash)]")
|
|
.btree_map(&["."])
|
|
.compile(&["proto/cli.proto"], &["proto/"])
|
|
.unwrap();
|
|
// tonic_build::compile_protos("proto/cli.proto")?;
|
|
check_locale();
|
|
Ok(())
|
|
}
|