Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 36 additions & 14 deletions .github/workflows/burrito-xcomp-check.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,48 @@
name: "Burrito Cross Build Build Tests"

on:
pull_request:
push:
branches: [main]

jobs:
build_examples:
name: build_examples_${{ matrix.host }}
name: build_examples_${{ matrix.host }}_${{ matrix.zig }}
runs-on: ${{ matrix.host }}
strategy:
fail-fast: false
matrix:
host: [ubuntu-latest, macos-latest]
zig: ["0.16.0"]
steps:
# Deps
- uses: actions/checkout@v4

- uses: erlef/setup-beam@v1
if: matrix.host == 'ubuntu-latest'
with:
otp-version: "27.3"
elixir-version: "1.18.3"

- uses: erlef/setup-beam@v1
if: matrix.host == 'macos-latest'
with:
otp-version: "27.3"
elixir-version: "1.18.3"

- uses: goto-bus-stop/setup-zig@v2
with:
version: 0.15.2
version: ${{ matrix.zig }}

- name: Set up Homebrew
if: matrix.host == 'macos-latest'
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master

- run: sudo apt-get -y install xz-utils
if: matrix.host == 'ubuntu-latest'
- run: brew install elixir xz

- run: brew install xz
if: matrix.host == 'macos-latest'

# Restore Cache
Expand All @@ -36,13 +51,13 @@ jobs:
id: cache-restore-linux
with:
path: /home/runner/.cache/burrito_file_cache/
key: burrito-download-cache_${{ matrix.host }}
key: burrito-download-cache_${{ matrix.host }}_${{ matrix.zig }}
- uses: actions/cache/restore@v3
if: matrix.host == 'macos-latest'
id: cache-restore-macos
with:
path: /Users/runner/Library/Caches/burrito_file_cache/
key: burrito-download-cache_${{ matrix.host }}
key: burrito-download-cache_${{ matrix.host }}_${{ matrix.zig }}

# Build Example CLI App
- name: cli_example
Expand All @@ -55,62 +70,69 @@ jobs:
id: cache-save-linux
with:
path: /home/runner/.cache/burrito_file_cache/
key: burrito-download-cache_${{ matrix.host }}
key: burrito-download-cache_${{ matrix.host }}_${{ matrix.zig }}

# Save Cache (macOS)
- uses: actions/cache/save@v3
if: matrix.host == 'macos-latest'
id: cache-save-macos
with:
path: /Users/runner/Library/Caches/burrito_file_cache/
key: burrito-download-cache_${{ matrix.host }}
key: burrito-download-cache_${{ matrix.host }}_${{ matrix.zig }}

# Upload Wrapped Binaries
- name: Upload Binaries
uses: actions/upload-artifact@v4
with:
name: burrito_${{ matrix.host }}_host_bins
name: burrito_${{ matrix.host }}_${{ matrix.zig }}_host_bins
path: ./examples/**/burrito_out/*
retention-days: 1

#### Run example binaries ####
# Windows binaries: built on Linux/macOS hosts, run on windows-latest
run_examples_windows:
needs: build_examples
strategy:
fail-fast: false
matrix:
host: [ubuntu-latest, macos-latest]
zig: ["0.16.0"]
runs-on: windows-latest
needs: build_examples
steps:
- name: Download a single artifact
uses: actions/download-artifact@v4
with:
name: burrito_${{ matrix.host }}_host_bins
name: burrito_${{ matrix.host }}_${{ matrix.zig }}_host_bins
- run: cli_example/burrito_out/example_cli_app_windows.exe

run_examples_linux:
needs: build_examples
strategy:
fail-fast: false
matrix:
host: [ubuntu-latest, macos-latest]
zig: ["0.16.0"]
runs-on: ubuntu-latest
needs: build_examples
steps:
- name: Download a single artifact
uses: actions/download-artifact@v4
with:
name: burrito_${{ matrix.host }}_host_bins
name: burrito_${{ matrix.host }}_${{ matrix.zig }}_host_bins
- run: chmod +x cli_example/burrito_out/example_cli_app_linux
- run: cli_example/burrito_out/example_cli_app_linux

run_examples_macos:
needs: build_examples
strategy:
fail-fast: false
matrix:
host: [ubuntu-latest, macos-latest]
zig: ["0.16.0"]
runs-on: macos-latest
needs: build_examples
steps:
- name: Download a single artifact
uses: actions/download-artifact@v4
with:
name: burrito_${{ matrix.host }}_host_bins
name: burrito_${{ matrix.host }}_${{ matrix.zig }}_host_bins
- run: chmod +x cli_example/burrito_out/example_cli_app_macos
- run: cli_example/burrito_out/example_cli_app_macos
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
zig 0.15.2
zig 0.16.0
erlang 28.0.2
elixir 1.18.4-otp-28
38 changes: 16 additions & 22 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
////
// DO NOT EDIT THIS FILE
////

const std = @import("std");
const foilz = @import("src/archiver.zig");
const builtin = @import("builtin");

const log = std.log;

const CrossTarget = std.zig.CrossTarget;
const Mode = std.builtin.Mode;
const LibExeObjStep = std.build.LibExeObjStep;

pub fn build(b: *std.Build) !void {
log.info("Zig is building an Elixir binary... ⚡", .{});

Expand All @@ -25,7 +17,8 @@ pub fn build(b: *std.Build) !void {
pub fn run_archiver(b: *std.Build) !void {
log.info("Generating and compressing release payload... 📦", .{});

const release_path = try std.process.getEnvVarOwned(b.allocator, "__BURRITO_RELEASE_PATH");
const release_path = b.graph.environ_map.get("__BURRITO_RELEASE_PATH") orelse
return error.MissingEnv;
try foilz.pack_directory(b.allocator, release_path, "./payload.foilz");

if (builtin.os.tag == .windows) {
Expand All @@ -46,19 +39,20 @@ pub fn run_archiver(b: *std.Build) !void {
pub fn build_wrapper(b: *std.Build) !void {
log.info("Building wrapper and embedding payload... 🌯", .{});

const release_name = try std.process.getEnvVarOwned(b.allocator, "__BURRITO_RELEASE_NAME");
const plugin_path = std.process.getEnvVarOwned(b.allocator, "__BURRITO_PLUGIN_PATH") catch null;
const is_prod = std.process.getEnvVarOwned(b.allocator, "__BURRITO_IS_PROD") catch "1";
const musl_runtime_path = std.process.getEnvVarOwned(b.allocator, "__BURRITO_MUSL_RUNTIME_PATH") catch "";
const release_name = b.graph.environ_map.get("__BURRITO_RELEASE_NAME") orelse
return error.MissingEnv;
const plugin_path = b.graph.environ_map.get("__BURRITO_PLUGIN_PATH");
const is_prod = b.graph.environ_map.get("__BURRITO_IS_PROD") orelse "1";
const musl_runtime_path = b.graph.environ_map.get("__BURRITO_MUSL_RUNTIME_PATH") orelse "";
var opt_level = std.builtin.OptimizeMode.Debug;

if (std.mem.eql(u8, is_prod, "1")) {
opt_level = std.builtin.OptimizeMode.ReleaseSmall;
}

var file = try std.fs.cwd().openFile("payload.foilz", .{});
defer file.close();
const uncompressed_size = try file.getEndPos();
var file = try std.Io.Dir.cwd().openFile(b.graph.io, "payload.foilz", .{});
defer file.close(b.graph.io);
const uncompressed_size = try file.length(b.graph.io);
const target = b.standardTargetOptions(.{});

const wrapper_exe = b.addExecutable(.{
Expand All @@ -82,11 +76,11 @@ pub fn build_wrapper(b: *std.Build) !void {
exe_options.addOption([]const u8, "MUSL_RUNTIME_PATH", musl_runtime_path);

if (target.result.os.tag == .windows) {
wrapper_exe.addIncludePath(b.path("src/"));
wrapper_exe.root_module.addIncludePath(b.path("src/"));
}

// Link standard C libary to the wrapper
wrapper_exe.linkSystemLibrary("c");
wrapper_exe.root_module.linkSystemLibrary("c", .{});

if (plugin_path) |plugin| {
log.info("Plugin found! {s} 🔌", .{plugin});
Expand All @@ -101,10 +95,10 @@ pub fn build_wrapper(b: *std.Build) !void {
wrapper_exe.root_module.addImport("burrito_plugin", plug_mod);
}

wrapper_exe.addIncludePath(b.path("src/xz"));
wrapper_exe.addCSourceFile(.{ .file = b.path("src/xz/xz_crc32.c") });
wrapper_exe.addCSourceFile(.{ .file = b.path("src/xz/xz_dec_lzma2.c") });
wrapper_exe.addCSourceFile(.{ .file = b.path("src/xz/xz_dec_stream.c") });
wrapper_exe.root_module.addIncludePath(b.path("src/xz"));
wrapper_exe.root_module.addCSourceFile(.{ .file = b.path("src/xz/xz_crc32.c") });
wrapper_exe.root_module.addCSourceFile(.{ .file = b.path("src/xz/xz_dec_lzma2.c") });
wrapper_exe.root_module.addCSourceFile(.{ .file = b.path("src/xz/xz_dec_stream.c") });

b.installArtifact(wrapper_exe);
}
2 changes: 1 addition & 1 deletion lib/burrito.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Burrito do
alias Burrito.Builder
alias Burrito.Builder.Log

@zig_version_expected %Version{major: 0, minor: 15, patch: 2}
@zig_version_expected %Version{major: 0, minor: 16, patch: 0}
@openssl_version %Version{major: 3, minor: 5, patch: 1}
@musl_version %Version{major: 1, minor: 2, patch: 5}

Expand Down
Loading
Loading