simplify version checking
This commit is contained in:
		@@ -1 +0,0 @@
 | 
			
		||||
1.0.1
 | 
			
		||||
@@ -1 +0,0 @@
 | 
			
		||||
24.3
 | 
			
		||||
							
								
								
									
										10
									
								
								Earthfile
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								Earthfile
									
									
									
									
									
								
							@@ -12,16 +12,14 @@ deps-base:
 | 
			
		||||
# Install Cap'n Proto
 | 
			
		||||
deps-capnp:
 | 
			
		||||
    FROM +deps-base
 | 
			
		||||
    COPY .capnp_version /
 | 
			
		||||
    COPY scripts/earthly/install_capnproto.sh /
 | 
			
		||||
    RUN /bin/bash /install_capnproto.sh 1; rm /install_capnproto.sh .capnp_version
 | 
			
		||||
    RUN /bin/bash /install_capnproto.sh 1; rm /install_capnproto.sh
 | 
			
		||||
 | 
			
		||||
# Install protoc
 | 
			
		||||
deps-protoc:
 | 
			
		||||
    FROM +deps-capnp
 | 
			
		||||
    COPY .protoc_version /
 | 
			
		||||
    COPY scripts/earthly/install_protoc.sh /
 | 
			
		||||
    RUN /bin/bash /install_protoc.sh; rm /install_protoc.sh .protoc_version
 | 
			
		||||
    RUN /bin/bash /install_protoc.sh; rm /install_protoc.sh
 | 
			
		||||
 | 
			
		||||
# Install Rust
 | 
			
		||||
deps-rust:
 | 
			
		||||
@@ -73,14 +71,14 @@ deps-linux:
 | 
			
		||||
# Code + Linux deps
 | 
			
		||||
code-linux:
 | 
			
		||||
    FROM +deps-linux
 | 
			
		||||
    COPY --dir .cargo .capnp_version .protoc_version files scripts veilid-cli veilid-core veilid-server veilid-tools veilid-flutter veilid-wasm Cargo.lock Cargo.toml /veilid
 | 
			
		||||
    COPY --dir .cargo files scripts veilid-cli veilid-core veilid-server veilid-tools veilid-flutter veilid-wasm Cargo.lock Cargo.toml /veilid
 | 
			
		||||
    RUN cat /veilid/scripts/earthly/cargo-linux/config.toml >> /veilid/.cargo/config.toml
 | 
			
		||||
    WORKDIR /veilid
 | 
			
		||||
 | 
			
		||||
# Code + Linux + Android deps
 | 
			
		||||
code-android:
 | 
			
		||||
    FROM +deps-android
 | 
			
		||||
    COPY --dir .cargo .capnp_version .protoc_version files scripts veilid-cli veilid-core veilid-server veilid-tools veilid-flutter veilid-wasm Cargo.lock Cargo.toml /veilid
 | 
			
		||||
    COPY --dir .cargo files scripts veilid-cli veilid-core veilid-server veilid-tools veilid-flutter veilid-wasm Cargo.lock Cargo.toml /veilid
 | 
			
		||||
    RUN cat /veilid/scripts/earthly/cargo-linux/config.toml >> /veilid/.cargo/config.toml
 | 
			
		||||
    RUN cat /veilid/scripts/earthly/cargo-android/config.toml >> /veilid/.cargo/config.toml
 | 
			
		||||
    WORKDIR /veilid
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +1,6 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
 | 
			
		||||
if [ -f ".capnp_version" ]; then 
 | 
			
		||||
    CAPNPROTO_VERSION=$(cat ".capnp_version")
 | 
			
		||||
else
 | 
			
		||||
    CAPNPROTO_VERSION=$(cat "$SCRIPTDIR/../../.capnp_version")
 | 
			
		||||
fi
 | 
			
		||||
CAPNPROTO_VERSION="1.0.1" # Keep in sync with veilid-core/build.rs
 | 
			
		||||
 | 
			
		||||
mkdir /tmp/capnproto-install
 | 
			
		||||
pushd /tmp/capnproto-install
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +1,6 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
 | 
			
		||||
if [ -f ".protoc_version" ]; then 
 | 
			
		||||
    PROTOC_VERSION=$(cat ".protoc_version")
 | 
			
		||||
else
 | 
			
		||||
    PROTOC_VERSION=$(cat "$SCRIPTDIR/../../.protoc_version")
 | 
			
		||||
fi
 | 
			
		||||
PROTOC_VERSION="24.3" # Keep in sync with veilid-core/build.rs
 | 
			
		||||
 | 
			
		||||
UNAME_M=$(uname -m)
 | 
			
		||||
if [[ "$UNAME_M" == "x86_64" ]]; then 
 | 
			
		||||
 
 | 
			
		||||
@@ -1,26 +1,14 @@
 | 
			
		||||
use std::path::PathBuf;
 | 
			
		||||
use std::process::{Command, Stdio};
 | 
			
		||||
 | 
			
		||||
fn search_file<T: AsRef<str>, P: AsRef<str>>(start: T, name: P) -> Option<PathBuf> {
 | 
			
		||||
    let start_path = PathBuf::from(start.as_ref()).canonicalize().ok();
 | 
			
		||||
    let mut path = start_path.as_deref();
 | 
			
		||||
    while let Some(some_path) = path {
 | 
			
		||||
        let file_path = some_path.join(name.as_ref());
 | 
			
		||||
        if file_path.exists() {
 | 
			
		||||
            return Some(file_path.to_owned());
 | 
			
		||||
        }
 | 
			
		||||
        path = some_path.parent();
 | 
			
		||||
    }
 | 
			
		||||
    None
 | 
			
		||||
}
 | 
			
		||||
const CAPNP_VERSION: &str = "1.0.1"; // Keep in sync with scripts/install_capnp.sh
 | 
			
		||||
const PROTOC_VERSION: &str = "24.3"; // Keep in sync with scripts/install_protoc.sh
 | 
			
		||||
 | 
			
		||||
fn get_desired_capnp_version_string() -> String {
 | 
			
		||||
    let capnp_path = search_file(env!("CARGO_MANIFEST_DIR"), ".capnp_version")
 | 
			
		||||
        .expect("should find .capnp_version file");
 | 
			
		||||
    std::fs::read_to_string(&capnp_path)
 | 
			
		||||
        .unwrap_or_else(|_| panic!("can't read .capnp_version file here: {:?}", capnp_path))
 | 
			
		||||
        .trim()
 | 
			
		||||
        .to_owned()
 | 
			
		||||
    CAPNP_VERSION.to_string()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn get_desired_protoc_version_string() -> String {
 | 
			
		||||
    PROTOC_VERSION.to_string()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn get_capnp_version_string() -> String {
 | 
			
		||||
@@ -40,15 +28,6 @@ fn get_capnp_version_string() -> String {
 | 
			
		||||
    s[20..].to_owned()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn get_desired_protoc_version_string() -> String {
 | 
			
		||||
    let protoc_path = search_file(env!("CARGO_MANIFEST_DIR"), ".protoc_version")
 | 
			
		||||
        .expect("should find .protoc_version file");
 | 
			
		||||
    std::fs::read_to_string(&protoc_path)
 | 
			
		||||
        .unwrap_or_else(|_| panic!("can't read .protoc_version file here: {:?}", protoc_path))
 | 
			
		||||
        .trim()
 | 
			
		||||
        .to_owned()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn get_protoc_version_string() -> String {
 | 
			
		||||
    let output = Command::new("protoc")
 | 
			
		||||
        .arg("--version")
 | 
			
		||||
@@ -67,63 +46,69 @@ fn get_protoc_version_string() -> String {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn main() {
 | 
			
		||||
    let desired_capnp_version_string = get_desired_capnp_version_string();
 | 
			
		||||
    let capnp_version_string = get_capnp_version_string();
 | 
			
		||||
    let desired_protoc_version_string = get_desired_protoc_version_string();
 | 
			
		||||
    let protoc_version_string = get_protoc_version_string();
 | 
			
		||||
    #[cfg(doc)]
 | 
			
		||||
    return;
 | 
			
		||||
 | 
			
		||||
    // Check capnp version
 | 
			
		||||
    let desired_capnp_major_version = desired_capnp_version_string
 | 
			
		||||
        .split_once('.')
 | 
			
		||||
        .unwrap()
 | 
			
		||||
        .0
 | 
			
		||||
        .parse::<usize>()
 | 
			
		||||
        .expect("should be valid int");
 | 
			
		||||
 | 
			
		||||
    if capnp_version_string
 | 
			
		||||
        .split_once('.')
 | 
			
		||||
        .unwrap()
 | 
			
		||||
        .0
 | 
			
		||||
        .parse::<usize>()
 | 
			
		||||
        .expect("should be valid int")
 | 
			
		||||
        != desired_capnp_major_version
 | 
			
		||||
    #[cfg(not(doc))]
 | 
			
		||||
    {
 | 
			
		||||
        panic!(
 | 
			
		||||
            "capnproto version should be major version 1, preferably {} but is {}",
 | 
			
		||||
            desired_capnp_version_string, capnp_version_string
 | 
			
		||||
        );
 | 
			
		||||
    } else if capnp_version_string != desired_capnp_version_string {
 | 
			
		||||
        println!(
 | 
			
		||||
            "capnproto version may be untested: {}",
 | 
			
		||||
            capnp_version_string
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
        let desired_capnp_version_string = get_desired_capnp_version_string();
 | 
			
		||||
        let capnp_version_string = get_capnp_version_string();
 | 
			
		||||
        let desired_protoc_version_string = get_desired_protoc_version_string();
 | 
			
		||||
        let protoc_version_string = get_protoc_version_string();
 | 
			
		||||
 | 
			
		||||
    // Check protoc version
 | 
			
		||||
    let desired_protoc_major_version = desired_protoc_version_string
 | 
			
		||||
        .split_once('.')
 | 
			
		||||
        .unwrap()
 | 
			
		||||
        .0
 | 
			
		||||
        .parse::<usize>()
 | 
			
		||||
        .expect("should be valid int");
 | 
			
		||||
    if protoc_version_string
 | 
			
		||||
        .split_once('.')
 | 
			
		||||
        .unwrap()
 | 
			
		||||
        .0
 | 
			
		||||
        .parse::<usize>()
 | 
			
		||||
        .expect("should be valid int")
 | 
			
		||||
        < desired_protoc_major_version
 | 
			
		||||
    {
 | 
			
		||||
        panic!(
 | 
			
		||||
            "protoc version should be at least major version {} but is {}",
 | 
			
		||||
            desired_protoc_major_version, protoc_version_string
 | 
			
		||||
        );
 | 
			
		||||
    } else if protoc_version_string != desired_protoc_version_string {
 | 
			
		||||
        println!("protoc version may be untested: {}", protoc_version_string);
 | 
			
		||||
    }
 | 
			
		||||
        // Check capnp version
 | 
			
		||||
        let desired_capnp_major_version = desired_capnp_version_string
 | 
			
		||||
            .split_once('.')
 | 
			
		||||
            .unwrap()
 | 
			
		||||
            .0
 | 
			
		||||
            .parse::<usize>()
 | 
			
		||||
            .expect("should be valid int");
 | 
			
		||||
 | 
			
		||||
    ::capnpc::CompilerCommand::new()
 | 
			
		||||
        .file("proto/veilid.capnp")
 | 
			
		||||
        .run()
 | 
			
		||||
        .expect("compiling schema");
 | 
			
		||||
        if capnp_version_string
 | 
			
		||||
            .split_once('.')
 | 
			
		||||
            .unwrap()
 | 
			
		||||
            .0
 | 
			
		||||
            .parse::<usize>()
 | 
			
		||||
            .expect("should be valid int")
 | 
			
		||||
            != desired_capnp_major_version
 | 
			
		||||
        {
 | 
			
		||||
            panic!(
 | 
			
		||||
                "capnproto version should be major version 1, preferably {} but is {}",
 | 
			
		||||
                desired_capnp_version_string, capnp_version_string
 | 
			
		||||
            );
 | 
			
		||||
        } else if capnp_version_string != desired_capnp_version_string {
 | 
			
		||||
            println!(
 | 
			
		||||
                "capnproto version may be untested: {}",
 | 
			
		||||
                capnp_version_string
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Check protoc version
 | 
			
		||||
        let desired_protoc_major_version = desired_protoc_version_string
 | 
			
		||||
            .split_once('.')
 | 
			
		||||
            .unwrap()
 | 
			
		||||
            .0
 | 
			
		||||
            .parse::<usize>()
 | 
			
		||||
            .expect("should be valid int");
 | 
			
		||||
        if protoc_version_string
 | 
			
		||||
            .split_once('.')
 | 
			
		||||
            .unwrap()
 | 
			
		||||
            .0
 | 
			
		||||
            .parse::<usize>()
 | 
			
		||||
            .expect("should be valid int")
 | 
			
		||||
            < desired_protoc_major_version
 | 
			
		||||
        {
 | 
			
		||||
            panic!(
 | 
			
		||||
                "protoc version should be at least major version {} but is {}",
 | 
			
		||||
                desired_protoc_major_version, protoc_version_string
 | 
			
		||||
            );
 | 
			
		||||
        } else if protoc_version_string != desired_protoc_version_string {
 | 
			
		||||
            println!("protoc version may be untested: {}", protoc_version_string);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ::capnpc::CompilerCommand::new()
 | 
			
		||||
            .file("proto/veilid.capnp")
 | 
			
		||||
            .run()
 | 
			
		||||
            .expect("compiling schema");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user