diff --git a/examples/node-pnpm-custom-node-version/package.json b/examples/node-pnpm-custom-node-version/package.json index 2779b6886..7b836178c 100644 --- a/examples/node-pnpm-custom-node-version/package.json +++ b/examples/node-pnpm-custom-node-version/package.json @@ -18,6 +18,6 @@ "typescript": "^4.2.4" }, "engines": { - "node": ">=14.2 <16" + "node": ">=16" } } diff --git a/examples/node-yarn-custom-node-version/package.json b/examples/node-yarn-custom-node-version/package.json index df284e73d..0150345a8 100644 --- a/examples/node-yarn-custom-node-version/package.json +++ b/examples/node-yarn-custom-node-version/package.json @@ -6,6 +6,6 @@ "start": "echo Node version: $(node --version) && node index.js" }, "engines": { - "node": ">=14.2 <16" + "node": "16.x" } } diff --git a/examples/zig/.gitignore b/examples/zig/.gitignore index f3162a29f..7dc0ebe54 100644 --- a/examples/zig/.gitignore +++ b/examples/zig/.gitignore @@ -1 +1,13 @@ -zig-*/ \ No newline at end of file +# Created by https://www.toptal.com/developers/gitignore/api/zig +# Edit at https://www.toptal.com/developers/gitignore?templates=zig + +### zig ### +# Zig programming language + +zig-cache/ +zig-out/ +build/ +build-*/ +docgen_tmp/ + +# End of https://www.toptal.com/developers/gitignore/api/zig diff --git a/examples/zig/build.zig b/examples/zig/build.zig index 5343eae67..93ff5e05c 100644 --- a/examples/zig/build.zig +++ b/examples/zig/build.zig @@ -1,34 +1,70 @@ const std = @import("std"); -pub fn build(b: *std.build.Builder) void { +// Although this function looks imperative, note that its job is to +// declaratively construct a build graph that will be executed by an external +// runner. +pub fn build(b: *std.Build) void { // Standard target options allows the person running `zig build` to choose // what target to build for. Here we do not override the defaults, which // means any target is allowed, and the default is native. Other options // for restricting supported target set are available. const target = b.standardTargetOptions(.{}); - // Standard release options allow the person running `zig build` to select - // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. - const mode = b.standardReleaseOptions(); + // Standard optimization options allow the person running `zig build` to select + // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not + // set a preferred release mode, allowing the user to decide how to optimize. + const optimize = b.standardOptimizeOption(.{}); - const exe = b.addExecutable("zig", "src/main.zig"); - exe.setTarget(target); - exe.setBuildMode(mode); - exe.install(); + const exe = b.addExecutable(.{ + .name = "zig", + // In this case the main source file is merely a path, however, in more + // complicated build scripts, this could be a generated file. + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = optimize, + }); - const run_cmd = exe.run(); + // This declares intent for the executable to be installed into the + // standard location when the user invokes the "install" step (the default + // step when running `zig build`). + b.installArtifact(exe); + + // This *creates* a Run step in the build graph, to be executed when another + // step is evaluated that depends on it. The next line below will establish + // such a dependency. + const run_cmd = b.addRunArtifact(exe); + + // By making the run step depend on the install step, it will be run from the + // installation directory rather than directly from within the cache directory. + // This is not necessary, however, if the application depends on other installed + // files, this ensures they will be present and in the expected location. run_cmd.step.dependOn(b.getInstallStep()); + + // This allows the user to pass arguments to the application in the build + // command itself, like this: `zig build run -- arg1 arg2 etc` if (b.args) |args| { run_cmd.addArgs(args); } + // This creates a build step. It will be visible in the `zig build --help` menu, + // and can be selected like this: `zig build run` + // This will evaluate the `run` step rather than the default, which is "install". const run_step = b.step("run", "Run the app"); run_step.dependOn(&run_cmd.step); - const exe_tests = b.addTest("src/main.zig"); - exe_tests.setTarget(target); - exe_tests.setBuildMode(mode); + // Creates a step for unit testing. This only builds the test executable + // but does not run it. + const unit_tests = b.addTest(.{ + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = optimize, + }); + + const run_unit_tests = b.addRunArtifact(unit_tests); + // Similar to creating the run step earlier, this exposes a `test` step to + // the `zig build --help` menu, providing a way for the user to request + // running the unit tests. const test_step = b.step("test", "Run unit tests"); - test_step.dependOn(&exe_tests.step); + test_step.dependOn(&run_unit_tests.step); } diff --git a/examples/zig/src/main.zig b/examples/zig/src/main.zig index 7b990cb96..ae016d7ae 100644 --- a/examples/zig/src/main.zig +++ b/examples/zig/src/main.zig @@ -1,10 +1,13 @@ const std = @import("std"); -pub fn main() anyerror!void { +pub fn main() !void { const stdout = std.io.getStdOut().writer(); - nosuspend stdout.print("Hello from Zig\n", .{}) catch return; + try stdout.print("Hello from {s}!\n", .{"Zig"}); } -test "basic test" { - try std.testing.expectEqual(10, 3 + 7); +test "simple test" { + var list = std.ArrayList(i32).init(std.testing.allocator); + defer list.deinit(); // try commenting this out and see if zig detects the memory leak! + try list.append(42); + try std.testing.expectEqual(@as(i32, 42), list.pop()); } diff --git a/src/nixpacks/nix/mod.rs b/src/nixpacks/nix/mod.rs index 376a66629..1cebca81f 100644 --- a/src/nixpacks/nix/mod.rs +++ b/src/nixpacks/nix/mod.rs @@ -6,9 +6,9 @@ use crate::nixpacks::plan::phase::{Phase, Phases}; pub mod pkg; // This line is automatically updated. -// Last Modified: 2023-01-02 17:04:24 UTC+0000 -// https://github.com/NixOS/nixpkgs/commit/293a28df6d7ff3dec1e61e37cc4ee6e6c0fb0847 -pub const NIXPKGS_ARCHIVE: &str = "293a28df6d7ff3dec1e61e37cc4ee6e6c0fb0847"; +// Last Modified: 2023-09-17 17:13:39 UTC+0000 +// https://github.com/NixOS/nixpkgs/commit/5148520bfab61f99fd25fb9ff7bfbb50dad3c9db +pub const NIXPKGS_ARCHIVE: &str = "5148520bfab61f99fd25fb9ff7bfbb50dad3c9db"; // Version of the Nix archive that uses OpenSSL 1.1 pub const NIXPACKS_ARCHIVE_LEGACY_OPENSSL: &str = "a0b7e70db7a55088d3de0cc370a59f9fbcc906c3"; diff --git a/src/providers/clojure.rs b/src/providers/clojure.rs index 3a2c2c52b..a107fe746 100644 --- a/src/providers/clojure.rs +++ b/src/providers/clojure.rs @@ -47,7 +47,7 @@ impl Provider for ClojureProvider { let mut build = Phase::build(Some(format!("{build_cmd}; {move_file_cmd}"))); build.depends_on_phase("setup"); - let start = StartPhase::new("bash -c \"java $JAVA_OPTS -jar /app/target/*standalone.jar\""); + let start = StartPhase::new("JAR_FILE=$(find ./target -name \"*standalone.jar\"); bash -c \"java $JAVA_OPTS -jar $JAR_FILE\""); let plan = BuildPlan::new(&vec![setup, build], Some(start)); Ok(Some(plan)) diff --git a/src/providers/zig.rs b/src/providers/zig.rs index 5b71466ca..8a46e00b2 100644 --- a/src/providers/zig.rs +++ b/src/providers/zig.rs @@ -9,44 +9,28 @@ use crate::nixpacks::{ }, }; use anyhow::Result; -use std::{env::consts::ARCH, ffi::OsStr}; +use std::ffi::OsStr; pub struct ZigProvider; -//TODO: CHANGE THIS WHEN ZIG IS UPDATED OR EVERYTHING WILL BREAK! -const GYRO_VERSION: &str = "0.6.0"; - impl Provider for ZigProvider { fn name(&self) -> &str { "zig" } fn detect(&self, app: &App, _env: &Environment) -> Result { - Ok(app.has_match("*.zig") || app.has_match("**/*.zig") || app.has_match("gyro.zzz")) + Ok(app.has_match("*.zig") || app.has_match("**/*.zig")) } fn get_build_plan(&self, app: &App, _env: &Environment) -> Result> { - let mut setup = Phase::setup(Some(vec![Pkg::new("zig")])); - - if app.includes_file("gyro.zzz") { - setup.add_nix_pkgs(&[Pkg::new("wget")]); - } + let setup = Phase::setup(Some(vec![Pkg::new("zig")])); let mut install = Phase::install(None); if app.includes_file(".gitmodules") { install.add_cmd("git submodule update --init".to_string()); } - if app.includes_file("gyro.zzz") { - let gyro_exe_path = format!("/gyro/gyro-{GYRO_VERSION}-linux-{ARCH}/bin/gyro"); - install.add_cmd(format!( - "mkdir /gyro && (wget -O- {} | tar -C /gyro -xzf -)", - ZigProvider::get_gyro_download_url() - )); - install.add_cmd(format!("chmod +x {gyro_exe_path}")); - install.add_cmd(format!("{gyro_exe_path} fetch")); - } - let build = Phase::build(Some("zig build -Drelease-safe=true".to_string())); + let build = Phase::build(Some("zig build -Doptimize=ReleaseSafe".to_string())); let start = StartPhase::new(format!( "./zig-out/bin/{}", @@ -60,16 +44,3 @@ impl Provider for ZigProvider { Ok(Some(plan)) } } - -impl ZigProvider { - pub fn get_gyro_download_url() -> String { - let gyro_supported_archs: Vec<&str> = vec!["x86_64", "aarch64", "i386"]; - if gyro_supported_archs.contains(&ARCH) { - format!( - "https://github.com/mattnite/gyro/releases/download/{GYRO_VERSION}/gyro-{GYRO_VERSION}-linux-{ARCH}.tar.gz" - ) - } else { - panic!("Gyro is not supported on your architecture ({ARCH}).") - } - } -} diff --git a/tests/docker_run_tests.rs b/tests/docker_run_tests.rs index d276001e2..b3643e93a 100644 --- a/tests/docker_run_tests.rs +++ b/tests/docker_run_tests.rs @@ -551,7 +551,7 @@ async fn test_prisma_postgres_npm_v9() { async fn test_yarn_custom_version() { let name = simple_build("./examples/node-yarn-custom-node-version").await; let output = run_image(&name, None).await; - assert!(output.contains("Node version: v14")); + assert!(output.contains("Node version: v16")); } #[tokio::test] diff --git a/tests/snapshots/generate_plan_tests__clojure.snap b/tests/snapshots/generate_plan_tests__clojure.snap index 70e267c02..2b0a48ce9 100644 --- a/tests/snapshots/generate_plan_tests__clojure.snap +++ b/tests/snapshots/generate_plan_tests__clojure.snap @@ -30,6 +30,6 @@ expression: plan } }, "start": { - "cmd": "bash -c \"java $JAVA_OPTS -jar /app/target/*standalone.jar\"" + "cmd": "JAR_FILE=$(find ./target -name \"*standalone.jar\"); bash -c \"java $JAVA_OPTS -jar $JAR_FILE\"" } } diff --git a/tests/snapshots/generate_plan_tests__clojure_jdk11.snap b/tests/snapshots/generate_plan_tests__clojure_jdk11.snap index de854bb64..6e0cb3356 100644 --- a/tests/snapshots/generate_plan_tests__clojure_jdk11.snap +++ b/tests/snapshots/generate_plan_tests__clojure_jdk11.snap @@ -30,6 +30,6 @@ expression: plan } }, "start": { - "cmd": "bash -c \"java $JAVA_OPTS -jar /app/target/*standalone.jar\"" + "cmd": "JAR_FILE=$(find ./target -name \"*standalone.jar\"); bash -c \"java $JAVA_OPTS -jar $JAR_FILE\"" } } diff --git a/tests/snapshots/generate_plan_tests__clojure_jdk_latest.snap b/tests/snapshots/generate_plan_tests__clojure_jdk_latest.snap index 3106e97bf..fb066b256 100644 --- a/tests/snapshots/generate_plan_tests__clojure_jdk_latest.snap +++ b/tests/snapshots/generate_plan_tests__clojure_jdk_latest.snap @@ -30,6 +30,6 @@ expression: plan } }, "start": { - "cmd": "bash -c \"java $JAVA_OPTS -jar /app/target/*standalone.jar\"" + "cmd": "JAR_FILE=$(find ./target -name \"*standalone.jar\"); bash -c \"java $JAVA_OPTS -jar $JAR_FILE\"" } } diff --git a/tests/snapshots/generate_plan_tests__clojure_ring_app.snap b/tests/snapshots/generate_plan_tests__clojure_ring_app.snap index 801bc5316..327154681 100644 --- a/tests/snapshots/generate_plan_tests__clojure_ring_app.snap +++ b/tests/snapshots/generate_plan_tests__clojure_ring_app.snap @@ -30,6 +30,6 @@ expression: plan } }, "start": { - "cmd": "bash -c \"java $JAVA_OPTS -jar /app/target/*standalone.jar\"" + "cmd": "JAR_FILE=$(find ./target -name \"*standalone.jar\"); bash -c \"java $JAVA_OPTS -jar $JAR_FILE\"" } } diff --git a/tests/snapshots/generate_plan_tests__clojure_tools_build.snap b/tests/snapshots/generate_plan_tests__clojure_tools_build.snap index 141dc98a8..d92b81d03 100644 --- a/tests/snapshots/generate_plan_tests__clojure_tools_build.snap +++ b/tests/snapshots/generate_plan_tests__clojure_tools_build.snap @@ -30,6 +30,6 @@ expression: plan } }, "start": { - "cmd": "bash -c \"java $JAVA_OPTS -jar /app/target/*standalone.jar\"" + "cmd": "JAR_FILE=$(find ./target -name \"*standalone.jar\"); bash -c \"java $JAVA_OPTS -jar $JAR_FILE\"" } } diff --git a/tests/snapshots/generate_plan_tests__node_pnpm_custom_node_version.snap b/tests/snapshots/generate_plan_tests__node_pnpm_custom_node_version.snap index db9041192..022137f04 100644 --- a/tests/snapshots/generate_plan_tests__node_pnpm_custom_node_version.snap +++ b/tests/snapshots/generate_plan_tests__node_pnpm_custom_node_version.snap @@ -42,7 +42,7 @@ expression: plan "setup": { "name": "setup", "nixPkgs": [ - "nodejs-14_x", + "nodejs-18_x", "pnpm-6_x" ], "nixOverlays": [ diff --git a/tests/snapshots/generate_plan_tests__node_yarn_custom_node_version.snap b/tests/snapshots/generate_plan_tests__node_yarn_custom_node_version.snap index a9a6dbb6b..b9a115ee1 100644 --- a/tests/snapshots/generate_plan_tests__node_yarn_custom_node_version.snap +++ b/tests/snapshots/generate_plan_tests__node_yarn_custom_node_version.snap @@ -39,7 +39,7 @@ expression: plan "setup": { "name": "setup", "nixPkgs": [ - "nodejs-14_x", + "nodejs-16_x", "yarn-1_x" ], "nixOverlays": [ diff --git a/tests/snapshots/generate_plan_tests__zig.snap b/tests/snapshots/generate_plan_tests__zig.snap index a78911d44..cb26b5b86 100644 --- a/tests/snapshots/generate_plan_tests__zig.snap +++ b/tests/snapshots/generate_plan_tests__zig.snap @@ -15,7 +15,7 @@ expression: plan "install" ], "cmds": [ - "zig build -Drelease-safe=true" + "zig build -Doptimize=ReleaseSafe" ] }, "install": {