mirror of
				https://github.com/edera-dev/krata.git
				synced 2025-11-03 07:19:37 +00:00 
			
		
		
		
	kratactl: initial windows bringup
This commit is contained in:
		
							
								
								
									
										7
									
								
								.github/workflows/client.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										7
									
								
								.github/workflows/client.yml
									
									
									
									
										vendored
									
									
								
							@ -7,9 +7,14 @@ jobs:
 | 
				
			|||||||
        os:
 | 
					        os:
 | 
				
			||||||
        - { name: linux, on: ubuntu-latest }
 | 
					        - { name: linux, on: ubuntu-latest }
 | 
				
			||||||
        - { name: darwin, on: macos-14 }
 | 
					        - { name: darwin, on: macos-14 }
 | 
				
			||||||
 | 
					        - { name: windows, on: windows-latest }
 | 
				
			||||||
        arch:
 | 
					        arch:
 | 
				
			||||||
        - x86_64
 | 
					        - x86_64
 | 
				
			||||||
        - aarch64
 | 
					        - aarch64
 | 
				
			||||||
 | 
					        exclude:
 | 
				
			||||||
 | 
					        # aarch64 windows support is not available in downstream dependencies
 | 
				
			||||||
 | 
					        - os: { name: windows, on: windows-latest }
 | 
				
			||||||
 | 
					          arch: aarch64
 | 
				
			||||||
    env:
 | 
					    env:
 | 
				
			||||||
      TARGET_OS: "${{ matrix.os.name }}"
 | 
					      TARGET_OS: "${{ matrix.os.name }}"
 | 
				
			||||||
      TARGET_ARCH: "${{ matrix.arch }}"
 | 
					      TARGET_ARCH: "${{ matrix.arch }}"
 | 
				
			||||||
@ -29,4 +34,6 @@ jobs:
 | 
				
			|||||||
      if: ${{ matrix.os.name == 'darwin' }}
 | 
					      if: ${{ matrix.os.name == 'darwin' }}
 | 
				
			||||||
    - run: ./hack/ci/install-mac-deps.sh
 | 
					    - run: ./hack/ci/install-mac-deps.sh
 | 
				
			||||||
      if: ${{ matrix.os.name == 'darwin' }}
 | 
					      if: ${{ matrix.os.name == 'darwin' }}
 | 
				
			||||||
 | 
					    - run: ./hack/ci/install-windows-deps.sh
 | 
				
			||||||
 | 
					      if: ${{ matrix.os.name == 'windows' }}
 | 
				
			||||||
    - run: ./hack/build/cargo.sh build --bin kratactl
 | 
					    - run: ./hack/build/cargo.sh build --bin kratactl
 | 
				
			||||||
 | 
				
			|||||||
@ -13,13 +13,15 @@ env_logger = { workspace = true }
 | 
				
			|||||||
krata = { path = "../krata" }
 | 
					krata = { path = "../krata" }
 | 
				
			||||||
log = { workspace = true }
 | 
					log = { workspace = true }
 | 
				
			||||||
serde = { workspace = true }
 | 
					serde = { workspace = true }
 | 
				
			||||||
termion = { workspace = true }
 | 
					 | 
				
			||||||
tokio = { workspace = true }
 | 
					tokio = { workspace = true }
 | 
				
			||||||
tokio-stream = { workspace = true }
 | 
					tokio-stream = { workspace = true }
 | 
				
			||||||
tonic = { workspace = true }
 | 
					tonic = { workspace = true }
 | 
				
			||||||
tower = { workspace = true }
 | 
					tower = { workspace = true }
 | 
				
			||||||
url = { workspace = true }
 | 
					url = { workspace = true }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[target.'cfg(unix)'.dependencies]
 | 
				
			||||||
 | 
					termion = { workspace = true }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[lib]
 | 
					[lib]
 | 
				
			||||||
name = "kratactl"
 | 
					name = "kratactl"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,13 @@
 | 
				
			|||||||
 | 
					#[cfg(not(unix))]
 | 
				
			||||||
 | 
					use anyhow::anyhow;
 | 
				
			||||||
use anyhow::Result;
 | 
					use anyhow::Result;
 | 
				
			||||||
use krata::{control::control_service_client::ControlServiceClient, dial::ControlDialAddress};
 | 
					use krata::{control::control_service_client::ControlServiceClient, dial::ControlDialAddress};
 | 
				
			||||||
 | 
					#[cfg(unix)]
 | 
				
			||||||
use tokio::net::UnixStream;
 | 
					use tokio::net::UnixStream;
 | 
				
			||||||
use tonic::transport::{Channel, ClientTlsConfig, Endpoint, Uri};
 | 
					#[cfg(unix)]
 | 
				
			||||||
 | 
					use tonic::transport::Uri;
 | 
				
			||||||
 | 
					use tonic::transport::{Channel, ClientTlsConfig, Endpoint};
 | 
				
			||||||
 | 
					#[cfg(unix)]
 | 
				
			||||||
use tower::service_fn;
 | 
					use tower::service_fn;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub struct ControlClientProvider {}
 | 
					pub struct ControlClientProvider {}
 | 
				
			||||||
@ -10,13 +16,13 @@ impl ControlClientProvider {
 | 
				
			|||||||
    pub async fn dial(addr: ControlDialAddress) -> Result<ControlServiceClient<Channel>> {
 | 
					    pub async fn dial(addr: ControlDialAddress) -> Result<ControlServiceClient<Channel>> {
 | 
				
			||||||
        let channel = match addr {
 | 
					        let channel = match addr {
 | 
				
			||||||
            ControlDialAddress::UnixSocket { path } => {
 | 
					            ControlDialAddress::UnixSocket { path } => {
 | 
				
			||||||
                // This URL is not actually used but is required to be specified.
 | 
					                #[cfg(not(unix))]
 | 
				
			||||||
                Endpoint::try_from(format!("unix://localhost/{}", path))?
 | 
					                return Err(anyhow!(
 | 
				
			||||||
                    .connect_with_connector(service_fn(|uri: Uri| {
 | 
					                    "unix sockets are not supported on this platform (path {})",
 | 
				
			||||||
                        let path = uri.path().to_string();
 | 
					                    path
 | 
				
			||||||
                        UnixStream::connect(path)
 | 
					                ));
 | 
				
			||||||
                    }))
 | 
					                #[cfg(unix)]
 | 
				
			||||||
                    .await?
 | 
					                ControlClientProvider::dial_unix_socket(path).await?
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            ControlDialAddress::Tcp { host, port } => {
 | 
					            ControlDialAddress::Tcp { host, port } => {
 | 
				
			||||||
@ -41,4 +47,15 @@ impl ControlClientProvider {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        Ok(ControlServiceClient::new(channel))
 | 
					        Ok(ControlServiceClient::new(channel))
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[cfg(unix)]
 | 
				
			||||||
 | 
					    async fn dial_unix_socket(path: String) -> Result<Channel> {
 | 
				
			||||||
 | 
					        // This URL is not actually used but is required to be specified.
 | 
				
			||||||
 | 
					        Ok(Endpoint::try_from(format!("unix://localhost/{}", path))?
 | 
				
			||||||
 | 
					            .connect_with_connector(service_fn(|uri: Uri| {
 | 
				
			||||||
 | 
					                let path = uri.path().to_string();
 | 
				
			||||||
 | 
					                UnixStream::connect(path)
 | 
				
			||||||
 | 
					            }))
 | 
				
			||||||
 | 
					            .await?)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,8 +1,3 @@
 | 
				
			|||||||
use std::{
 | 
					 | 
				
			||||||
    io::stdout,
 | 
					 | 
				
			||||||
    os::fd::{AsRawFd, FromRawFd},
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
use anyhow::Result;
 | 
					use anyhow::Result;
 | 
				
			||||||
use async_stream::stream;
 | 
					use async_stream::stream;
 | 
				
			||||||
use krata::{
 | 
					use krata::{
 | 
				
			||||||
@ -10,9 +5,13 @@ use krata::{
 | 
				
			|||||||
    control::{watch_events_reply::Event, ConsoleDataReply, ConsoleDataRequest},
 | 
					    control::{watch_events_reply::Event, ConsoleDataReply, ConsoleDataRequest},
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use log::debug;
 | 
					use log::debug;
 | 
				
			||||||
 | 
					#[cfg(unix)]
 | 
				
			||||||
 | 
					use std::os::fd::{AsRawFd, FromRawFd};
 | 
				
			||||||
 | 
					#[cfg(unix)]
 | 
				
			||||||
use termion::raw::IntoRawMode;
 | 
					use termion::raw::IntoRawMode;
 | 
				
			||||||
 | 
					#[cfg(unix)]
 | 
				
			||||||
 | 
					use tokio::fs::File;
 | 
				
			||||||
use tokio::{
 | 
					use tokio::{
 | 
				
			||||||
    fs::File,
 | 
					 | 
				
			||||||
    io::{stdin, AsyncReadExt, AsyncWriteExt},
 | 
					    io::{stdin, AsyncReadExt, AsyncWriteExt},
 | 
				
			||||||
    task::JoinHandle,
 | 
					    task::JoinHandle,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
@ -48,8 +47,14 @@ impl StdioConsoleStream {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub async fn stdout(mut stream: Streaming<ConsoleDataReply>) -> Result<()> {
 | 
					    pub async fn stdout(mut stream: Streaming<ConsoleDataReply>) -> Result<()> {
 | 
				
			||||||
        let terminal = stdout().into_raw_mode()?;
 | 
					        #[cfg(unix)]
 | 
				
			||||||
        let mut stdout = unsafe { File::from_raw_fd(terminal.as_raw_fd()) };
 | 
					        let terminal = std::io::stdout().into_raw_mode()?;
 | 
				
			||||||
 | 
					        #[cfg(unix)]
 | 
				
			||||||
 | 
					        let mut stdout =
 | 
				
			||||||
 | 
					            unsafe { File::from_std(std::fs::File::from_raw_fd(terminal.as_raw_fd())) };
 | 
				
			||||||
 | 
					        #[cfg(not(unix))]
 | 
				
			||||||
 | 
					        let mut stdout = tokio::io::stdout();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        while let Some(reply) = stream.next().await {
 | 
					        while let Some(reply) = stream.next().await {
 | 
				
			||||||
            let reply = reply?;
 | 
					            let reply = reply?;
 | 
				
			||||||
            if reply.data.is_empty() {
 | 
					            if reply.data.is_empty() {
 | 
				
			||||||
 | 
				
			|||||||
@ -14,8 +14,14 @@ then
 | 
				
			|||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
HOST_OS="$(uname -s)"
 | 
					HOST_OS="$(uname -s)"
 | 
				
			||||||
 | 
					HOST_OS="$(echo "${HOST_OS}" | awk -F '_' '{print $1}')"
 | 
				
			||||||
HOST_OS="$(echo "${HOST_OS}" | tr '[:upper:]' '[:lower:]')"
 | 
					HOST_OS="$(echo "${HOST_OS}" | tr '[:upper:]' '[:lower:]')"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [ "${HOST_OS}" = "mingw64" ]
 | 
				
			||||||
 | 
					then
 | 
				
			||||||
 | 
					  HOST_OS="windows"
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [ -z "${TARGET_OS}" ]
 | 
					if [ -z "${TARGET_OS}" ]
 | 
				
			||||||
then
 | 
					then
 | 
				
			||||||
  TARGET_OS="${HOST_OS}"
 | 
					  TARGET_OS="${HOST_OS}"
 | 
				
			||||||
 | 
				
			|||||||
@ -19,7 +19,13 @@ fi
 | 
				
			|||||||
if [ -z "${TARGET_OS}" ]
 | 
					if [ -z "${TARGET_OS}" ]
 | 
				
			||||||
then
 | 
					then
 | 
				
			||||||
  TARGET_OS="$(uname -s)"
 | 
					  TARGET_OS="$(uname -s)"
 | 
				
			||||||
 | 
					  TARGET_OS="$(echo "${TARGET_OS}" | awk -F '_' '{print $1}')"
 | 
				
			||||||
  TARGET_OS="$(echo "${TARGET_OS}" | tr '[:upper:]' '[:lower:]')"
 | 
					  TARGET_OS="$(echo "${TARGET_OS}" | tr '[:upper:]' '[:lower:]')"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if [ "${TARGET_OS}" = "mingw64" ]
 | 
				
			||||||
 | 
					  then
 | 
				
			||||||
 | 
					    TARGET_OS="windows"
 | 
				
			||||||
 | 
					  fi
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [ "${TARGET_OS}" = "darwin" ]
 | 
					if [ "${TARGET_OS}" = "darwin" ]
 | 
				
			||||||
@ -36,6 +42,20 @@ then
 | 
				
			|||||||
      RUST_TARGET="aarch64-apple-darwin"
 | 
					      RUST_TARGET="aarch64-apple-darwin"
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
  fi
 | 
					  fi
 | 
				
			||||||
 | 
					elif [ "${TARGET_OS}" = "windows" ]
 | 
				
			||||||
 | 
					then
 | 
				
			||||||
 | 
					  if [ -z "${RUST_TARGET}" ]
 | 
				
			||||||
 | 
					  then
 | 
				
			||||||
 | 
					    if [ "${TARGET_ARCH}" = "x86_64" ]
 | 
				
			||||||
 | 
					    then
 | 
				
			||||||
 | 
					      RUST_TARGET="x86_64-pc-windows-msvc"
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if [ "${TARGET_ARCH}" = "aarch64" ]
 | 
				
			||||||
 | 
					    then
 | 
				
			||||||
 | 
					      RUST_TARGET="aarch64-pc-windows-msvc"
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					  fi
 | 
				
			||||||
else
 | 
					else
 | 
				
			||||||
  if [ -z "${RUST_TARGET}" ]
 | 
					  if [ -z "${RUST_TARGET}" ]
 | 
				
			||||||
  then
 | 
					  then
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										4
									
								
								hack/ci/install-windows-deps.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								hack/ci/install-windows-deps.sh
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,4 @@
 | 
				
			|||||||
 | 
					#!/bin/sh
 | 
				
			||||||
 | 
					set -e
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					winget install protobuf
 | 
				
			||||||
		Reference in New Issue
	
	Block a user