Skip to content

Commit bc0b2e5

Browse files
committed
improve cross platofrm build
1 parent 102b3f4 commit bc0b2e5

File tree

12 files changed

+248
-0
lines changed

12 files changed

+248
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

.github/workflows/build-test.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Build and Test
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build-and-test:
11+
name: Build and Test
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
17+
- name: Set up Rust
18+
uses: actions-rs/toolchain@v1
19+
with:
20+
toolchain: stable
21+
override: true
22+
components: rustfmt, clippy
23+
targets: x86_64-unknown-linux-musl, x86_64-pc-windows-gnu
24+
25+
- name: Install cross
26+
run: cargo install cross
27+
28+
- name: Check formatting
29+
uses: actions-rs/cargo@v1
30+
with:
31+
command: fmt
32+
args: --all -- --check
33+
34+
- name: Clippy
35+
uses: actions-rs/cargo@v1
36+
with:
37+
command: clippy
38+
args: -- -D warnings
39+
40+
- name: Build
41+
uses: actions-rs/cargo@v1
42+
with:
43+
command: build
44+
args: --verbose
45+
46+
- name: Run tests
47+
uses: actions-rs/cargo@v1
48+
with:
49+
command: test
50+
args: --verbose
51+
52+
- name: Cache dependencies
53+
uses: actions/cache@v2
54+
with:
55+
path: |
56+
~/.cargo/registry
57+
~/.cargo/git
58+
target
59+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

.github/workflows/release.yaml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
release:
10+
strategy:
11+
matrix:
12+
os: [ubuntu-latest, macos-latest]
13+
runs-on: ${{ matrix.os }}
14+
steps:
15+
- uses: actions/checkout@v2
16+
17+
- name: Set up Rust
18+
uses: actions-rs/toolchain@v1
19+
with:
20+
toolchain: stable
21+
override: true
22+
target: ${{ matrix.os == 'ubuntu-latest' && 'x86_64-unknown-linux-musl' || 'aarch64-apple-darwin' }}
23+
24+
- name: Install cross (Linux only)
25+
if: matrix.os == 'ubuntu-latest'
26+
run: cargo install cross
27+
28+
- name: Make build script executable
29+
run: chmod +x build.sh
30+
31+
- name: Build
32+
run: ./build.sh
33+
34+
- name: Create Release
35+
id: create_release
36+
uses: actions/create-release@v1
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
with:
40+
tag_name: ${{ github.ref }}
41+
release_name: Release ${{ github.ref }}
42+
draft: false
43+
prerelease: false
44+
45+
- name: Upload Linux Binary
46+
uses: actions/upload-release-asset@v1
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
with:
50+
upload_url: ${{ steps.create_release.outputs.upload_url }}
51+
asset_path: ./releases/ruspy-linux.tar.gz
52+
asset_name: ruspy-linux.tar.gz
53+
asset_content_type: application/gzip
54+
55+
- name: Upload Windows Binary
56+
uses: actions/upload-release-asset@v1
57+
env:
58+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
with:
60+
upload_url: ${{ steps.create_release.outputs.upload_url }}
61+
asset_path: ./releases/ruspy-windows.zip
62+
asset_name: ruspy-windows.zip
63+
asset_content_type: application/zip

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/target
2+
.env
3+
/releases

Cargo.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+12
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,17 @@ repository = "https://github.com/Himasnhu-at/ruspy.git"
1010
license = "BSD-Clause-3"
1111

1212
[dependencies]
13+
dotenv = "0.15.0"
1314
env_logger = "0.11.5"
1415
log = "0.4.22"
16+
17+
[profile.release]
18+
opt-level = 3 # Maximum optimization
19+
lto = true # Enable link-time optimization
20+
codegen-units = 1 # Reduce parallel code generation units to increase optimization
21+
panic = 'abort' # Remove panic unwinding to reduce binary size
22+
strip = true # Strip symbols from binary
23+
24+
[[bin]]
25+
name = "ruspy"
26+
path = "src/main.rs"

Readme.md

+55
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,58 @@ This project is licensed under the BSD-Clause-3 License - see the [LICENSE](LICE
5454
## Contact
5555

5656
For any questions, please contact Himanshu at [email protected].
57+
58+
### Binary Installation
59+
60+
You can download pre-built binaries for your platform:
61+
62+
#### Linux
63+
64+
```bash
65+
curl -LO https://github.com/Himasnhu-at/ruspy/releases/latest/download/ruspy-linux.tar.gz
66+
tar xzf ruspy-linux.tar.gz
67+
sudo mv ruspy-linux /usr/local/bin/ruspy
68+
```
69+
70+
#### Windows
71+
72+
Download `ruspy-windows.zip` from the releases page and extract it.
73+
74+
#### macOS
75+
76+
```bash
77+
curl -LO https://github.com/Himasnhu-at/ruspy/releases/latest/download/ruspy-macos.tar.gz
78+
tar xzf ruspy-macos.tar.gz
79+
sudo mv ruspy-macos /usr/local/bin/ruspy
80+
```
81+
82+
6. To build the releases, run:
83+
84+
> [!NOTE]
85+
> Before running the build script, make sure you have cross toolchain installed.
86+
> MacOS build is only supported on macOS.
87+
> Toolchains:
88+
>
89+
> - `x86_64-unknown-linux-musl`
90+
> - `x86_64-pc-windows-gnu`
91+
> - `aarch64-apple-darwin`
92+
>
93+
> To install, run:
94+
>
95+
> ```cargo
96+
> rustup target add x86_64-unknown-linux-musl
97+
> rustup target add x86_64-pc-windows-gnu
98+
> rustup target add aarch64-apple-darwin
99+
> ```
100+
101+
```bash
102+
chmod +x build.sh
103+
./build.sh
104+
```
105+
106+
This setup will:
107+
108+
- Optimize the binary size and performance
109+
- Create static binaries that don't require Rust installation
110+
- Support cross-compilation for different platforms
111+
- Package the binaries appropriately for each platform

build.sh

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
# Create release directory
4+
mkdir -p releases
5+
6+
# Build for Linux (static binary)
7+
echo "Building for Linux..."
8+
cross build --target x86_64-unknown-linux-musl --release
9+
cp target/x86_64-unknown-linux-musl/release/ruspy releases/ruspy-linux
10+
11+
# Build for Windows
12+
echo "Building for Windows..."
13+
cross build --target x86_64-pc-windows-gnu --release
14+
cp target/x86_64-pc-windows-gnu/release/ruspy.exe releases/ruspy-windows.exe
15+
16+
# Build for M1 Mac (only on macOS)
17+
if [[ "$OSTYPE" == "darwin"* ]]; then
18+
echo "Building for M1 Mac..."
19+
# Build natively instead of using cross
20+
cargo build --target aarch64-apple-darwin --release
21+
cp target/aarch64-apple-darwin/release/ruspy releases/ruspy-macos
22+
else
23+
echo "Skipping macOS build (not on macOS)"
24+
fi
25+
26+
# Create archives
27+
cd releases
28+
if [ -f ruspy-linux ]; then
29+
tar czf ruspy-linux.tar.gz ruspy-linux
30+
fi
31+
32+
if [ -f ruspy-windows.exe ]; then
33+
zip ruspy-windows.zip ruspy-windows.exe
34+
fi
35+
36+
if [ -f ruspy-macos ]; then
37+
tar czf ruspy-macos.tar.gz ruspy-macos
38+
fi
39+
cd ..

cross.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[target.x86_64-unknown-linux-musl]
2+
image = "rustembedded/cross:x86_64-unknown-linux-musl"
3+
4+
[target.x86_64-pc-windows-gnu]
5+
image = "rustembedded/cross:x86_64-pc-windows-gnu"
6+
7+
[target.aarch64-apple-darwin]
8+
# Remove the Docker image specification since we'll build natively on macOS

src/.DS_Store

6 KB
Binary file not shown.

src/main.rs

+2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ mod lexer;
33
mod parser;
44
mod types;
55

6+
use dotenv::dotenv;
67
use env_logger;
78
use interpreter::Interpreter;
89
use lexer::Lexer;
910
use log::info;
1011
use parser::Parser;
1112

1213
fn main() -> Result<(), String> {
14+
dotenv().ok();
1315
env_logger::init();
1416
info!("Starting Ruspy interpreter");
1517

src/types/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ impl Div for RuspyType {
140140
}
141141

142142
// Implementation for type inference
143+
#[allow(dead_code)]
143144
pub fn infer_type(value: &str) -> RuspyType {
144145
if let Ok(i) = value.parse::<i32>() {
145146
RuspyType::Int(i)

0 commit comments

Comments
 (0)