Skip to content

Commit

Permalink
feat(install): setup installation with make install
Browse files Browse the repository at this point in the history
  • Loading branch information
kkharji committed May 26, 2022
1 parent e86eb5e commit 3d32fbb
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
target
bin
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
$(VERBOSE).SILENT:
.PHONY: test
default: test
RELEASE_ROOT:target/release

test:
cargo test --workspace
Expand All @@ -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"
2 changes: 1 addition & 1 deletion lua/xbase/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn ensure(lua: &Lua, _: ()) -> LuaResult<bool> {
// 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 {
Expand Down
5 changes: 3 additions & 2 deletions src/compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
Expand All @@ -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": [
Expand Down
29 changes: 26 additions & 3 deletions src/constants.rs
Original file line number Diff line number Diff line change
@@ -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<tokio::sync::Mutex<crate::state::State>>;
Expand Down

0 comments on commit 3d32fbb

Please sign in to comment.