From 78b2311e767f198843befd57902c333aa8a149be Mon Sep 17 00:00:00 2001 From: UndiedGamer Date: Fri, 27 Dec 2024 18:47:33 +0530 Subject: [PATCH] feat: deprecate windows and prefer wsl --- .github/workflows/cd.yml | 26 ++++++---------- .github/workflows/ci.yml | 13 +++----- README.md | 15 ++++++++-- install.sh | 50 +++++++++++++++++++++++++++++++ src/main.zig | 65 ++++++++++++---------------------------- 5 files changed, 95 insertions(+), 74 deletions(-) create mode 100644 install.sh diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 9a6b72c..5baea2b 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -1,4 +1,4 @@ -name: CI +name: Continous Delivery on: release: types: [created] @@ -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 @@ -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 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3cde139..d7430fc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/README.md b/README.md index 39b03e4..4e721c6 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..5d92b9f --- /dev/null +++ b/install.sh @@ -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 diff --git a/src/main.zig b/src/main.zig index 2ba3139..e4c23eb 100644 --- a/src/main.zig +++ b/src/main.zig @@ -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 { @@ -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))); @@ -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;