Skip to content
This repository was archived by the owner on Dec 15, 2025. It is now read-only.

Commit 56612fc

Browse files
committed
...
1 parent 0533984 commit 56612fc

5 files changed

Lines changed: 209 additions & 7 deletions

File tree

Cargo.lock

Lines changed: 115 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ thiserror = "1.0"
2626
clap = "2.33"
2727
git-version = "0.3.5"
2828
command-group = "1.0.8"
29+
dirs = "5.0"
2930
hyper = "1.6"
3031
# axum = { version = "0.7.4", features = ["http1"] }
3132
bytes = "1.0"
@@ -46,4 +47,3 @@ path = "src/lib.rs"
4647
[[bin]]
4748
name = "zinit"
4849
path = "src/main.rs"
49-

osx_install.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# macOS Installation Guide for Cross-Compilation to aarch64-unknown-linux-musl
2+
3+
This guide outlines the steps to set up your macOS environment for cross-compiling Rust projects to the `aarch64-unknown-linux-musl` target. This is particularly useful for building binaries that can run on ARM-based Linux systems (e.g., Raspberry Pi, AWS Graviton) using musl libc.
4+
5+
## Prerequisites
6+
7+
* Homebrew (https://brew.sh/) installed on your macOS system.
8+
* Rust and Cargo installed (e.g., via `rustup`).
9+
10+
## Step 1: Install the `aarch64-linux-musl-gcc` Toolchain
11+
12+
The `aarch64-linux-musl-gcc` toolchain is required for linking when cross-compiling to `aarch64-unknown-linux-musl`. You can install it using Homebrew:
13+
14+
```bash
15+
brew install messense/macos-cross-toolchains/aarch64-linux-musl-cross
16+
```
17+
18+
## Step 2: Link `musl-gcc`
19+
20+
Some build scripts or tools might look for `musl-gcc`. To ensure compatibility, create a symbolic link:
21+
22+
```bash
23+
sudo ln -s /opt/homebrew/bin/aarch64-linux-musl-gcc /opt/homebrew/bin/musl-gcc
24+
```
25+
26+
You might be prompted for your system password to complete this operation.
27+
28+
## Step 3: Add the Rust Target
29+
30+
Add the `aarch64-unknown-linux-musl` target to your Rust toolchain:
31+
32+
```bash
33+
rustup target add aarch64-unknown-linux-musl
34+
```
35+
36+
## Step 4: Build Your Project
37+
38+
Now you can build your Rust project for the `aarch64-unknown-linux-musl` target using Cargo:
39+
40+
```bash
41+
cargo build --release --target aarch64-unknown-linux-musl
42+
```
43+
44+
Alternatively, if you are using the provided `Makefile`, you can use the new target:
45+
46+
```bash
47+
make release-aarch64-musl
48+
```
49+
50+
This will produce a release binary located in `target/aarch64-unknown-linux-musl/release/`.
51+
52+
## Step 5: Running Zinit
53+
54+
After building, you can run `zinit`. First, you need to start the `zinit` daemon using the `init` subcommand. On macOS, `zinit` will now default to using `~/hero/cfg/zinit` as its configuration directory. This will create the Unix socket at `/tmp/zinit.sock` and start managing services.
55+
56+
Once the directory is created (if it doesn't exist, `zinit` will create it automatically), you can run the `init` command:
57+
58+
```bash
59+
/path/to/your/zinit init
60+
```
61+
62+
Replace `/path/to/your/zinit` with the actual path to your compiled `zinit` binary (e.g., `~/hero/bin/zinit` if you copied it there).
63+
64+
Once the daemon is running, you can interact with it using other `zinit` commands. For example, to list services:
65+
66+
```bash
67+
/path/to/your/zinit list
68+
```
69+
70+
If you encounter a "failed to connect to socket" error, ensure that the `zinit init` command is running in the background.

src/app/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ pub async fn init(
5858
container: bool,
5959
debug: bool,
6060
) -> Result<ApiServer> {
61-
//std::fs::create_dir_all(config)?;
61+
fs::create_dir_all(config)
62+
.await
63+
.with_context(|| format!("failed to create config directory '{}'", config))?;
6264
if let Err(err) = logger(if debug {
6365
log::LevelFilter::Debug
6466
} else {

src/main.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async fn main() -> Result<()> {
1515
.author("ThreeFold Tech, https://github.com/threefoldtech")
1616
.version(GIT_VERSION)
1717
.about("A runit replacement")
18-
.arg(Arg::with_name("socket").value_name("SOCKET").short("s").long("socket").default_value("/var/run/zinit.sock").help("path to unix socket"))
18+
.arg(Arg::with_name("socket").value_name("SOCKET").short("s").long("socket").default_value("/tmp/zinit.sock").help("path to unix socket"))
1919
.arg(Arg::with_name("debug").short("d").long("debug").help("run in debug mode"))
2020
.subcommand(
2121
SubCommand::with_name("init")
@@ -24,8 +24,7 @@ async fn main() -> Result<()> {
2424
.value_name("DIR")
2525
.short("c")
2626
.long("config")
27-
.help("service configurations directory")
28-
.default_value("/etc/zinit/"),
27+
.help("service configurations directory"),
2928
)
3029
.arg(
3130
Arg::with_name("buffer")
@@ -158,14 +157,30 @@ async fn main() -> Result<()> {
158157
)
159158
.get_matches();
160159

160+
use dirs; // Add this import
161+
161162
let socket = matches.value_of("socket").unwrap();
162163
let debug = matches.is_present("debug");
163-
//let debug = true;
164+
165+
let config_path = if let Some(config_arg) = matches.value_of("config") {
166+
config_arg.to_string()
167+
} else {
168+
#[cfg(target_os = "macos")]
169+
{
170+
let home_dir = dirs::home_dir().ok_or_else(|| anyhow::anyhow!("Could not determine home directory"))?;
171+
home_dir.join("hero").join("cfg").join("zinit").to_str().ok_or_else(|| anyhow::anyhow!("Invalid path for config directory"))?.to_string()
172+
}
173+
#[cfg(not(target_os = "macos"))]
174+
{
175+
"/etc/zinit/".to_string()
176+
}
177+
};
178+
164179
let result = match matches.subcommand() {
165180
("init", Some(matches)) => {
166181
let _server = app::init(
167182
matches.value_of("buffer").unwrap().parse().unwrap(),
168-
matches.value_of("config").unwrap(),
183+
&config_path, // Use the determined config_path
169184
socket,
170185
matches.is_present("container"),
171186
debug,

0 commit comments

Comments
 (0)