From ec4dc48b76e17cb97774e2b5ae230bb75360b9e4 Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jackpot51@gmail.com>
Date: Wed, 28 Dec 2016 19:32:39 -0700
Subject: [PATCH] Update to use new Xargo, add netutils

---
 .gitmodules                       | 3 +++
 Xargo.toml                        | 2 ++
 cook.sh                           | 4 +++-
 libc-artifacts                    | 1 +
 recipes/netutils/recipe.sh        | 1 +
 setup.sh                          | 6 ------
 targets/x86_64-unknown-redox.json | 9 ++++++---
 7 files changed, 16 insertions(+), 10 deletions(-)
 create mode 100644 .gitmodules
 create mode 100644 Xargo.toml
 create mode 160000 libc-artifacts
 create mode 100644 recipes/netutils/recipe.sh

diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 000000000..39b409c6d
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "libc-artifacts"]
+	path = libc-artifacts
+	url = https://github.com/redox-os/libc-artifacts.git
diff --git a/Xargo.toml b/Xargo.toml
new file mode 100644
index 000000000..4cd054db0
--- /dev/null
+++ b/Xargo.toml
@@ -0,0 +1,2 @@
+[target.x86_64-unknown-redox.dependencies.std]
+features = []
diff --git a/cook.sh b/cook.sh
index 45a78038d..645615a64 100755
--- a/cook.sh
+++ b/cook.sh
@@ -1,9 +1,10 @@
 #!/bin/bash
 
 export RUST_TARGET_PATH="$PWD/targets"
-export RUSTFLAGS="--cfg redox"
 export CARGOFLAGS=
+export CFLAGS="-fno-stack-protector -U_FORTIFY_SOURCE"
 TARGET=x86_64-unknown-redox
+ROOT="$PWD"
 REPO="$PWD/repo/$TARGET"
 
 set -e
@@ -33,6 +34,7 @@ function op {
             ;;
         build)
             pushd build > /dev/null
+            cp -r "$ROOT/Xargo.toml" "$ROOT/libc-artifacts" .
             xargo build --target "$TARGET" --release $CARGOFLAGS
             popd > /dev/null
             ;;
diff --git a/libc-artifacts b/libc-artifacts
new file mode 160000
index 000000000..b0e2a74a5
--- /dev/null
+++ b/libc-artifacts
@@ -0,0 +1 @@
+Subproject commit b0e2a74a505d0bc6ffea05d81fe239b1beb5c246
diff --git a/recipes/netutils/recipe.sh b/recipes/netutils/recipe.sh
new file mode 100644
index 000000000..5992a5e2f
--- /dev/null
+++ b/recipes/netutils/recipe.sh
@@ -0,0 +1 @@
+GIT=https://github.com/redox-os/netutils.git
diff --git a/setup.sh b/setup.sh
index e33761713..376aef197 100755
--- a/setup.sh
+++ b/setup.sh
@@ -12,10 +12,4 @@ then
     cargo install -f xargo
 fi
 
-echo "Building libstd"
-./cook.sh libstd unfetch
-./cook.sh libstd fetch
-./cook.sh libstd build
-cp recipes/libstd/build/target/x86_64-unknown-redox/release/deps/*.rlib ~/.xargo/lib/rustlib/x86_64-unknown-redox/lib/
-
 echo "cook.sh is ready to use"
diff --git a/targets/x86_64-unknown-redox.json b/targets/x86_64-unknown-redox.json
index d981254ef..362ef9ccc 100644
--- a/targets/x86_64-unknown-redox.json
+++ b/targets/x86_64-unknown-redox.json
@@ -8,8 +8,8 @@
     "env": "",
     "vendor": "unknown",
     "target-family": "redox",
-    "pre-link-args": ["-m64", "-nostdlib", "-static"],
-    "post-link-args": [],
+    "pre-link-args": ["-m64", "-Wl,--as-needed", "-Wl,-z,noexecstack", "-nostartfiles", "-nostdlib", "-static"],
+    "late-link-args": ["libc-artifacts/lib/crt0.o", "libc-artifacts/lib/libm.a", "libc-artifacts/lib/libc.a", "libc-artifacts/lib/libgcc.a"],
     "features": "",
     "dynamic-linking": false,
     "executables": true,
@@ -22,5 +22,8 @@
     "no-compiler-rt": true,
     "no-default-libraries": true,
     "position-independent-executables": false,
-    "has-elf-tls": true
+    "lib-allocation-crate": "alloc_system",
+    "exe-allocation-crate": "alloc_system",
+    "has-elf-tls": true,
+    "panic-strategy": "abort"
 }
-- 
GitLab