Skip to content

Commit

Permalink
Add Haunt for Scheme as a provider (#1198)
Browse files Browse the repository at this point in the history
* draft

* register provider

* simplification

* fix registration

* incorporate feedback

* start command quirk

* lint fix

* add scheme snapshot test

---------

Co-authored-by: Jake Runzer <[email protected]>
  • Loading branch information
Siarune and coffee-cup authored Nov 13, 2024
1 parent 2015b25 commit 6b61023
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 2 deletions.
26 changes: 26 additions & 0 deletions docs/pages/docs/providers/scheme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
title: Scheme
---

# {% $markdoc.frontmatter.title %}

Scheme via [Haunt](https://dthompson.us/projects/haunt.html) is detected is there is a `haunt.scm` file found.

## Setup

Installs the basic dependencies

## Build

Build the project based on your `haunt.scm`.

## Start

Haunt wasn't made for this, so our entrypoint is actually a Guile script.
Make sure it is in the root directory with your `haunt.scm`.
Note: This is only necessary in production. You can use the `haunt` command normally in dev.

```scheme
;; init.scm
(system "haunt serve")
```
1 change: 1 addition & 0 deletions docs/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const sidebarItems: ISidebarSection[] = [
{ href: "/docs/providers/python", text: "Python" },
{ href: "/docs/providers/ruby", text: "Ruby" },
{ href: "/docs/providers/rust", text: "Rust" },
{ href: "/docs/providers/scheme", text: "Scheme" },
{ href: "/docs/providers/staticfile", text: "Staticfile" },
{ href: "/docs/providers/swift", text: "Swift" },
{ href: "/docs/providers/scala", text: "Scala" },
Expand Down
14 changes: 14 additions & 0 deletions examples/scheme/haunt.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(use-modules (haunt asset)
(haunt builder blog)
(haunt builder assets)
(haunt reader commonmark)
(haunt site))

(site #:title "Built with Guile"
#:domain "example.com"
#:default-metadata
'((author . "John Doe")
(email . "[email protected]"))
#:readers (list)
#:builders (list)
)
1 change: 1 addition & 0 deletions examples/scheme/init.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(display "Hello from Scheme!")
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ use providers::{
fsharp::FSharpProvider, gleam::GleamProvider, go::GolangProvider,
haskell::HaskellStackProvider, java::JavaProvider, lunatic::LunaticProvider,
node::NodeProvider, php::PhpProvider, python::PythonProvider, ruby::RubyProvider,
rust::RustProvider, scala::ScalaProvider, staticfile::StaticfileProvider, swift::SwiftProvider,
zig::ZigProvider, Provider,
rust::RustProvider, scala::ScalaProvider, scheme::HauntProvider,
staticfile::StaticfileProvider, swift::SwiftProvider, zig::ZigProvider, Provider,
};
use std::process::Command;

Expand All @@ -62,6 +62,7 @@ pub fn get_providers() -> &'static [&'static (dyn Provider)] {
&GleamProvider {},
&GolangProvider {},
&HaskellStackProvider {},
&HauntProvider {},
&JavaProvider {},
&LunaticProvider {},
&ScalaProvider {},
Expand Down
1 change: 1 addition & 0 deletions src/providers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub mod python;
pub mod ruby;
pub mod rust;
pub mod scala;
pub mod scheme;
pub mod staticfile;
pub mod swift;
pub mod zig;
Expand Down
36 changes: 36 additions & 0 deletions src/providers/scheme.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use super::Provider;
use crate::nixpacks::{
app::App,
environment::Environment,
nix::pkg::Pkg,
plan::{
phase::{Phase, StartPhase},
BuildPlan,
},
};
use anyhow::Result;

pub struct HauntProvider {}

impl Provider for HauntProvider {
fn name(&self) -> &str {
"scheme"
}

fn detect(&self, app: &App, _env: &Environment) -> Result<bool> {
Ok(app.includes_file("haunt.scm"))
}

fn get_build_plan(&self, _app: &App, _env: &Environment) -> Result<Option<BuildPlan>> {
let setup = Phase::setup(Some(vec![Pkg::new("haunt"), Pkg::new("guile")]));
let mut build = Phase::build(Some("haunt build".to_string()));
build.depends_on_phase("setup");
// In production, init.scm should run "haunt serve"
// However, "haunt serve" doesn't terminate on its own, which the tests depend on
// So for the example, init.scm simply logs to the console
let start = StartPhase::new("guile init.scm --auto-compile".to_string());

let plan = BuildPlan::new(&vec![setup, build], Some(start));
Ok(Some(plan))
}
}
6 changes: 6 additions & 0 deletions tests/docker_run_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1480,3 +1480,9 @@ async fn test_config_toml_file() {
let output = run_image(&name, None).await;
assert!(output.contains("hey there"));
}

#[tokio::test]
async fn test_scheme() {
let name = simple_build("./examples/scheme").await.unwrap();
assert!(run_image(&name, None).await.contains("Hello from Scheme!"));
}
35 changes: 35 additions & 0 deletions tests/snapshots/generate_plan_tests__scheme.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
source: tests/generate_plan_tests.rs
expression: plan
---
{
"providers": [],
"buildImage": "[build_image]",
"variables": {
"NIXPACKS_METADATA": "scheme"
},
"phases": {
"build": {
"name": "build",
"dependsOn": [
"install",
"setup"
],
"cmds": [
"haunt build"
]
},
"setup": {
"name": "setup",
"nixPkgs": [
"haunt",
"guile"
],
"nixOverlays": [],
"nixpkgsArchive": "[archive]"
}
},
"start": {
"cmd": "guile init.scm --auto-compile"
}
}

0 comments on commit 6b61023

Please sign in to comment.