From 3d32fbbf4295f34197504a59d526edfc30d78caa Mon Sep 17 00:00:00 2001 From: tami5 Date: Thu, 26 May 2022 14:58:22 +0300 Subject: [PATCH] feat(install): setup installation with make install --- .gitignore | 1 + Cargo.toml | 2 +- Makefile | 26 ++++++++++++++++++++++++++ lua/xbase/lib.rs | 2 +- src/compile/mod.rs | 5 +++-- src/constants.rs | 29 ++++++++++++++++++++++++++--- 6 files changed, 58 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index eb5a316..d44cd35 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ target +bin diff --git a/Cargo.toml b/Cargo.toml index ef365bd..2fcde9d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,7 @@ server = [ "compilation", "crossbeam-channel" ] -lua = [ "mlua", "serial", "simctl" ] +lua = [ "mlua", "serial", "simctl", "lazy_static" ] serial = [ "serde", "serde_json", "serde_yaml" ] compilation = [ "serial", "lazy_static", "shell-words", "xcode" ] logging = [ "tracing", "tracing-appender", "tracing-subscriber" ] diff --git a/Makefile b/Makefile index e4445b9..f06c686 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ $(VERBOSE).SILENT: .PHONY: test default: test +RELEASE_ROOT:target/release test: cargo test --workspace @@ -21,3 +22,28 @@ watchdaemon: watchserver: RUST_LOG="trace" cargo watch -x 'build --bin xbase-server --features=server' -w 'src' -w 'Cargo.toml' -c + +clean: + rm -rf bin; + rm -rf lua/libxbase.so + +install: clean + mkdir bin + cargo build --release --bin xbase-server --features=server + cargo build --release --bin xbase-daemon --features=daemon + cargo build --release -p libxbase + mv target/release/xbase-daemon ./bin/xbase-daemon + mv target/release/xbase-server ./bin/xbase-server + mv target/release/liblibxbase.dylib ./lua/libxbase.so + cargo clean # NOTE: 3.2 GB must be cleaned up + echo "DONE" + +install_debug: clean + mkdir bin + cargo build --bin xbase-server --features=server + cargo build --bin xbase-daemon --features=daemon + cargo build -p libxbase + ln -sf ../target/debug/xbase-daemon ./bin/xbase-daemon + ln -sf ../target/debug/xbase-server ./bin/xbase-server + ln -sf ../target/debug/liblibxbase.dylib ./lua/libxbase.so + echo "DONE" diff --git a/lua/xbase/lib.rs b/lua/xbase/lib.rs index 0705980..e6a2272 100644 --- a/lua/xbase/lib.rs +++ b/lua/xbase/lib.rs @@ -36,7 +36,7 @@ pub fn ensure(lua: &Lua, _: ()) -> LuaResult { // FIXME(dameon): resulting in connection refused if is_running(lua, ()).unwrap() { Ok(false) - } else if Command::new(DAEMON_BINARY).spawn().is_ok() { + } else if Command::new(DAEMON_BINARY_PATH).spawn().is_ok() { lua.info("Spawned Background Server")?; Ok(true) } else { diff --git a/src/compile/mod.rs b/src/compile/mod.rs index 15a985e..2391661 100644 --- a/src/compile/mod.rs +++ b/src/compile/mod.rs @@ -154,6 +154,8 @@ pub async fn update_compilation_file(root: &path::PathBuf) -> Result<()> { /// Ensure that buildServer.json exists in root directory. #[cfg(feature = "daemon")] pub async fn ensure_server_config(root: &path::PathBuf) -> Result<()> { + use crate::constants::SERVER_BINARY_PATH; + let path = root.join("buildServer.json"); if tokio::fs::File::open(&path).await.is_ok() { return Ok(()); @@ -164,8 +166,7 @@ pub async fn ensure_server_config(root: &path::PathBuf) -> Result<()> { let mut file = tokio::fs::File::create(path).await?; let config = serde_json::json! ({ "name": "Xbase", - // FIXME: Point to user xbase-server - "argv": ["/Users/tami5/repos/neovim/xbase.nvim/target/debug/xbase-server"], + "argv": [SERVER_BINARY_PATH], "version": "0.1", "bspVersion": "0.2", "languages": [ diff --git a/src/constants.rs b/src/constants.rs index 308cdee..1e4a42f 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -1,6 +1,29 @@ -pub const DAEMON_SOCKET_PATH: &str = "/tmp/xbase-daemon.socket"; -pub const DAEMON_PID_PATH: &str = "/tmp/xbase-daemon-pid"; -pub const DAEMON_BINARY: &str = "/Users/tami5/repos/neovim/xbase.nvim/target/debug/xbase-daemon"; +/// Where the daemon socket path will be located +pub static DAEMON_SOCKET_PATH: &str = "/tmp/xbase-daemon.socket"; + +/// Where the daemon pid will be located +pub static DAEMON_PID_PATH: &str = "/tmp/xbase-daemon-pid"; + +/// HACK: This static path would break if a pre-built binary is to be distributed. +/// +/// A soultion might be to move binaries to `~/.local/share/xbase/bin` +/// Where the daemon binary will be located. +pub static DAEMON_BINARY_PATH: &'static str = { + if cfg!(debug_assertions) { + concat!(env!("CARGO_MANIFEST_DIR"), "/target/debug/xbase-daemon") + } else { + concat!(env!("CARGO_MANIFEST_DIR"), "/bin/xbase-daemon") + } +}; + +/// Where the server binary will be located. +pub static SERVER_BINARY_PATH: &'static str = { + if cfg!(debug_assertions) { + concat!(env!("CARGO_MANIFEST_DIR"), "/target/debug/xbase-server") + } else { + concat!(env!("CARGO_MANIFEST_DIR"), "/bin/xbase-server") + } +}; #[cfg(feature = "daemon")] pub type DaemonSharedState = std::sync::Arc>;