From db9f4e40bfa393f3a879c20be9f40a9dec6f69ec Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jeremy@system76.com>
Date: Thu, 21 May 2020 21:13:39 -0600
Subject: [PATCH] Add curl recipe

---
 recipes/curl/recipe.toml | 39 +++++++++++++++++++++++++++++++++++++++
 src/bin/cook.rs          |  5 +++++
 2 files changed, 44 insertions(+)
 create mode 100644 recipes/curl/recipe.toml

diff --git a/recipes/curl/recipe.toml b/recipes/curl/recipe.toml
new file mode 100644
index 000000000..39af949ff
--- /dev/null
+++ b/recipes/curl/recipe.toml
@@ -0,0 +1,39 @@
+[source]
+git = "https://gitlab.redox-os.org/redox-os/curl.git"
+branch = "redox"
+
+[build]
+template = "custom"
+dependencies = [
+    "nghttp2",
+    "openssl",
+    "zlib"
+]
+script = """
+rsync -av --delete "${COOKBOOK_SOURCE}/" ./
+wget -O config.sub http://git.savannah.gnu.org/cgit/config.git/plain/config.sub
+autoreconf -i
+COOKBOOK_CONFIGURE="./configure"
+COOKBOOK_CONFIGURE_FLAGS=(
+    --build="$(cc -dumpmachine)"
+    --host="${TARGET}"
+    --prefix=""
+    --disable-ftp
+    --disable-ipv6
+    --disable-ntlm-wb
+    --disable-shared
+    --disable-tftp
+    --disable-threaded-resolver
+    --enable-static
+    --with-ca-path=/ssl/certs
+    --with-nghttp2="${COOKBOOK_SYSROOT}"
+    --with-ssl="${COOKBOOK_SYSROOT}"
+    --with-zlib="${COOKBOOK_SYSROOT}"
+)
+cookbook_configure
+"""
+
+[package]
+dependencies = [
+    "ca-certificates"
+]
diff --git a/src/bin/cook.rs b/src/bin/cook.rs
index 303579421..585d1b811 100644
--- a/src/bin/cook.rs
+++ b/src/bin/cook.rs
@@ -339,6 +339,9 @@ fn build(recipe_dir: &Path, source_dir: &Path, build: &BuildRecipe) -> Result<Pa
         }
 
         let pre_script = r#"# Common pre script
+# Add cookbook bins to path
+export PATH="${COOKBOOK_ROOT}/bin:${PATH}"
+
 # This puts cargo build artifacts in the build directory
 export CARGO_TARGET_DIR="${COOKBOOK_BUILD}/target"
 
@@ -414,12 +417,14 @@ fi
             //TODO: remove unwraps
             let cookbook_build = build_dir.canonicalize().unwrap();
             let cookbook_recipe = recipe_dir.canonicalize().unwrap();
+            let cookbook_root = Path::new(".").canonicalize().unwrap();
             let cookbook_stage = stage_dir_tmp.canonicalize().unwrap();
             let cookbook_source = source_dir.canonicalize().unwrap();
             let cookbook_sysroot = sysroot_dir.canonicalize().unwrap();
             command.current_dir(&cookbook_build);
             command.env("COOKBOOK_BUILD", &cookbook_build);
             command.env("COOKBOOK_RECIPE", &cookbook_recipe);
+            command.env("COOKBOOK_ROOT", &cookbook_root);
             command.env("COOKBOOK_STAGE", &cookbook_stage);
             command.env("COOKBOOK_SOURCE", &cookbook_source);
             command.env("COOKBOOK_SYSROOT", &cookbook_sysroot);
-- 
GitLab