Skip to content

Commit

Permalink
feat: deprecate windows and prefer wsl
Browse files Browse the repository at this point in the history
  • Loading branch information
UndiedGamer committed Dec 27, 2024
1 parent bcf3f99 commit 78b2311
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 74 deletions.
26 changes: 9 additions & 17 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Continous Delivery
on:
release:
types: [created]
Expand All @@ -13,22 +13,6 @@ jobs:
fail-fast: false
matrix:
platform:
- release_for: Windows-x86_64
os: windows-latest
target: x86_64-pc-windows-msvc
zig_target: x86_64-windows-msvc
rust_bin: create-docx.exe
zig_bin: pfcreator.exe
name: pfcreator-windows-x86_64
command: build
- release_for: Windows-aarch64
os: windows-latest
target: aarch64-pc-windows-msvc
zig_target: aarch64-windows-msvc
rust_bin: create-docx.exe
zig_bin: pfcreator.exe
name: pfcreator-windows-aarch64
command: build
- release_for: macOS-aarch64
os: macOS-latest
target: aarch64-apple-darwin
Expand All @@ -37,6 +21,14 @@ jobs:
zig_bin: pfcreator
name: pfcreator-darwin-aarch64
command: build
- release_for: macOS-x86_64
os: macOS-latest
target: x86_64-apple-darwin
zig_target: x86_64-macos-none
rust_bin: create-docx
zig_bin: pfcreator
name: pfcreator-darwin-x86_64
command: build
- release_for: Linux-x86_64
os: ubuntu-latest
target: x86_64-unknown-linux-gnu
Expand Down
13 changes: 4 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,15 @@ jobs:
arch: arm64
target: aarch64-unknown-linux-gnu
zig-target: aarch64-linux-gnu
# Windows builds
- os: windows-latest
arch: x64
target: x86_64-pc-windows-msvc
zig-target: x86_64-windows-msvc
- os: windows-latest
arch: arm64
target: aarch64-pc-windows-msvc
zig-target: aarch64-windows-msvc
# macOS builds
- os: macos-latest
arch: arm64
target: aarch64-apple-darwin
zig-target: aarch64-macos-none
- os: macos-latest
arch: x64
target: x86_64-apple-darwin
zig-target: x86_64-macos-none

steps:
- uses: actions/checkout@v4
Expand Down
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,19 @@
## How to Use

### 1. Installation

*Will provide binaries later*
### Linux and MacOS
1. Run the installer via
```bash
curl -fsSL https://raw.githubusercontent.com/UndiedGamer/pfcreator/refs/heads/main/install.sh | sh
```
2. Source your shell profile (`.bashrc`, `.zshrc`, etc.) or create a new terminal instance to use the `pfcreator` command.

#### Windows
1. Enable [Windows Subsystem for Linux (WSL)](https://learn.microsoft.com/en-us/windows/wsl/install).
2. Open Ubuntu or your distro of choice in Windows Terminal or from Start Menu.
3. Follow Linux steps.
> [!IMPORTANT]
> WSL ships with gcc/g++ but python does not, you might have to install python inside WSL.
### 2. Set Up Your Files

Expand Down
50 changes: 50 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

set -e

echo "Welcome to the pfcreator installer!"
echo "This script will install pfcreator on your system."
RELEASE_URL="https://github.com/UndiedGamer/pfcreator/releases/download/v1.0.0"

TEMP_DIR=$(mktemp -d)
trap 'rm -rf "$TEMP_DIR"' EXIT

OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)

TARBALL=""
if [ "$OS" = "linux" ]; then
if [ "$ARCH" = "x86_64" ]; then
TARBALL="pfcreator-linux-x86_64.tar.gz"
elif [ "$ARCH" = "arm64" ]; then
TARBALL="pfcreator-linux-aarch64.tar.gz"
fi
elif [ "$OS" = "darwin" ]; then
TARBALL="pfcreator-darwin-aarch64.tar.gz"
else
echo "Unsupported OS: $OS"
exit 1
fi

if [ -z "$TARBALL" ]; then
echo "Unsupported architecture: $ARCH"
exit 1
fi

echo "Downloading $TARBALL..."
curl -fsSL "$RELEASE_URL/$TARBALL" -o "$TEMP_DIR/$TARBALL"

echo "Extracting $TARBALL..."
tar -xzf "$TEMP_DIR/$TARBALL" -C "$TEMP_DIR"

echo "Installing binaries..."
for binary in "$TEMP_DIR"/*/*; do
if [ -x "$binary" ] && [ ! -d "$binary" ]; then
echo "Copying $(basename "$binary") to /usr/local/bin"
sudo cp "$binary" /usr/local/bin/
sudo chmod +x "/usr/local/bin/$(basename "$binary")"
fi
done

echo "pfcreator has been successfully installed!"
exit 0
65 changes: 19 additions & 46 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,7 @@ pub fn main() !void {
file.close();

// Create a temporary file for output capture
const tmp_output_path = if (builtin.os.tag == .windows)
"temp_output.txt"
else
"/tmp/terminal_output.txt";
const tmp_output_path = "/tmp/terminal_output.txt";

// Clear the output file
{
Expand Down Expand Up @@ -172,55 +169,31 @@ pub fn main() !void {
}
defer std.fs.cwd().deleteFile("./a.out") catch {};

if (builtin.os.tag == .windows) {
const ps_cmd = try std.fmt.allocPrint(allocator, "& './a.out' | Tee-Object -FilePath '{s}'", .{tmp_output_path});
defer allocator.free(ps_cmd);
// Use script command with explicit file
const shell_cmd = try std.fmt.allocPrint(allocator, "script -q {s} ./a.out", .{tmp_output_path});
defer allocator.free(shell_cmd);

var run_process = std.process.Child.init(&[_][]const u8{ "pwsh", "-Command", ps_cmd }, allocator);
run_process.spawn() catch {
std.debug.print("Failed to run file: {s}\n", .{entry.name});
std.process.exit(1);
};
_ = try run_process.wait();
} else {
// Use script command with explicit file
const shell_cmd = try std.fmt.allocPrint(allocator, "script -q {s} ./a.out", .{tmp_output_path});
defer allocator.free(shell_cmd);

var run_process = std.process.Child.init(&[_][]const u8{ "bash", "-c", shell_cmd }, allocator);
run_process.spawn() catch {
std.debug.print("Failed to run file: {s}\n", .{entry.name});
std.process.exit(1);
};
_ = try run_process.wait();
}
var run_process = std.process.Child.init(&[_][]const u8{ "bash", "-c", shell_cmd }, allocator);
run_process.spawn() catch {
std.debug.print("Failed to run file: {s}\n", .{entry.name});
std.process.exit(1);
};
_ = try run_process.wait();

// Read output file directly
output = try processOutput(allocator, try std.fs.cwd().readFileAlloc(allocator, tmp_output_path, std.math.maxInt(usize)));
} else if (std.mem.eql(u8, extension, ".py")) {
const script_path = try std.mem.concat(allocator, u8, &[_][]const u8{ full_dir_path, "/", entry.name });
defer allocator.free(script_path);
if (builtin.os.tag == .windows) {
const ps_cmd = try std.fmt.allocPrint(allocator, "python -u {s} | Tee-Object -FilePath '{s}'", .{ script_path, tmp_output_path });
defer allocator.free(ps_cmd);
const shell_cmd = try std.fmt.allocPrint(allocator, "script -q {s} python -u {s}", .{ tmp_output_path, script_path });
defer allocator.free(shell_cmd);

var run_process = std.process.Child.init(&[_][]const u8{ "pwsh", "-Command", ps_cmd }, allocator);
run_process.spawn() catch {
std.debug.print("Failed to run file: {s}\n", .{entry.name});
std.process.exit(1);
};
_ = try run_process.wait();
} else {
const shell_cmd = try std.fmt.allocPrint(allocator, "script -q {s} python -u {s}", .{ tmp_output_path, script_path });
defer allocator.free(shell_cmd);

var run_process = std.process.Child.init(&[_][]const u8{ "bash", "-c", shell_cmd }, allocator);
run_process.spawn() catch {
std.debug.print("Failed to run file: {s}\n", .{entry.name});
std.process.exit(1);
};
_ = try run_process.wait();
}
var run_process = std.process.Child.init(&[_][]const u8{ "bash", "-c", shell_cmd }, allocator);
run_process.spawn() catch {
std.debug.print("Failed to run file: {s}\n", .{entry.name});
std.process.exit(1);
};
_ = try run_process.wait();

// Read output file directly
output = try processOutput(allocator, try std.fs.cwd().readFileAlloc(allocator, tmp_output_path, std.math.maxInt(usize)));
Expand Down Expand Up @@ -280,7 +253,7 @@ pub fn main() !void {
const rust_executable_path = if (builtin.mode == .Debug)
"target/release/create-docx"
else
"./create-docx";
"/usr/local/bin/create-docx";

var rust_process = std.process.Child.init(&[_][]const u8{ rust_executable_path, dir_path }, allocator);
rust_process.stderr_behavior = .Pipe;
Expand Down

0 comments on commit 78b2311

Please sign in to comment.