Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update global nixpkgs archive #970

Merged
merged 11 commits into from
Sep 19, 2023
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
2 changes: 1 addition & 1 deletion examples/node-pnpm-custom-node-version/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"typescript": "^4.2.4"
},
"engines": {
"node": ">=14.2 <16"
"node": ">=16"
}
}
2 changes: 1 addition & 1 deletion examples/node-yarn-custom-node-version/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"start": "echo Node version: $(node --version) && node index.js"
},
"engines": {
"node": ">=14.2 <16"
"node": "16.x"
}
}
14 changes: 13 additions & 1 deletion examples/zig/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
zig-*/
# 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
62 changes: 49 additions & 13 deletions examples/zig/build.zig
Original file line number Diff line number Diff line change
@@ -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);
}
11 changes: 7 additions & 4 deletions examples/zig/src/main.zig
Original file line number Diff line number Diff line change
@@ -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());
}
6 changes: 3 additions & 3 deletions src/nixpacks/nix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/providers/clojure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
37 changes: 4 additions & 33 deletions src/providers/zig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> {
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<Option<BuildPlan>> {
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/{}",
Expand All @@ -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}).")
}
}
}
2 changes: 1 addition & 1 deletion tests/docker_run_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/generate_plan_tests__clojure.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
}
}
2 changes: 1 addition & 1 deletion tests/snapshots/generate_plan_tests__clojure_jdk11.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
}
}
2 changes: 1 addition & 1 deletion tests/snapshots/generate_plan_tests__clojure_ring_app.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ expression: plan
"setup": {
"name": "setup",
"nixPkgs": [
"nodejs-14_x",
"nodejs-18_x",
"pnpm-6_x"
],
"nixOverlays": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ expression: plan
"setup": {
"name": "setup",
"nixPkgs": [
"nodejs-14_x",
"nodejs-16_x",
"yarn-1_x"
],
"nixOverlays": [
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/generate_plan_tests__zig.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ expression: plan
"install"
],
"cmds": [
"zig build -Drelease-safe=true"
"zig build -Doptimize=ReleaseSafe"
]
},
"install": {
Expand Down