aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorCalvin Rose <calsrose@gmail.com>2019-06-19 19:43:38 -0400
committerCalvin Rose <calsrose@gmail.com>2019-06-19 19:43:38 -0400
commitfc46030e7dcec418c96a8963dcb491cd0f0f36ef (patch)
treee79ba0208d5fef43a3ea5f6c36b0f71d6cfe202e
parentAdd some test cases for module/expand-path (diff)
Add options to not include docstrings in binary.
This lets us build a smaller binary. The minimal tested binary on x86-64 (with -Os, -s, and all options that shrink binary size turned on) is about 240 kB.
-rw-r--r--src/boot/boot.c10
-rw-r--r--src/boot/boot.janet22
-rw-r--r--src/include/janetconf.h2
-rw-r--r--test/suite6.janet4
4 files changed, 38 insertions, 0 deletions
diff --git a/src/boot/boot.c b/src/boot/boot.c
index 42bae7b7..fb1f160a 100644
--- a/src/boot/boot.c
+++ b/src/boot/boot.c
@@ -52,6 +52,16 @@ int main(int argc, const char **argv) {
janet_array_push(args, janet_cstringv(argv[i]));
janet_def(env, "process/args", janet_wrap_array(args), "Command line arguments.");
+ /* Add in options from janetconf.h so boot.janet can configure the image as needed. */
+ JanetTable *opts = janet_table(0);
+#ifdef JANET_NO_DOCSTRINGS
+ janet_table_put(opts, janet_ckeywordv("no-docstrings"), janet_wrap_true());
+#endif
+#ifdef JANET_NO_SOURCEMAPS
+ janet_table_put(opts, janet_ckeywordv("no-sourcemaps"), janet_wrap_true());
+#endif
+ janet_def(env, "process/config", janet_wrap_table(opts), "Boot options");
+
/* Run bootstrap script to generate core image */
status = janet_dobytes(env, janet_gen_boot, janet_gen_boot_size, "boot.janet", NULL);
diff --git a/src/boot/boot.janet b/src/boot/boot.janet
index 64f3fa0c..7673fd91 100644
--- a/src/boot/boot.janet
+++ b/src/boot/boot.janet
@@ -1843,7 +1843,29 @@ _fiber is bound to the suspended fiber
###
(do
+
+ (defn proto-flatten
+ "Flatten a table and it's prototypes into a single table."
+ [into x]
+ (when x
+ (proto-flatten into (table/getproto x))
+ (loop [k :keys x]
+ (put into k (x k))))
+ into)
+
(def env (fiber/getenv (fiber/current)))
+
+ # Modify env based on some options.
+ (loop [[k v] :pairs env
+ :when (symbol? k)]
+ (def flat (proto-flatten @{} v))
+ (when (process/config :no-docstrings)
+ (put flat :doc nil))
+ (when (process/config :no-sourcemaps)
+ (put flat :source-map nil))
+ (put env k flat))
+
+ (put env 'process/config nil)
(def image (let [env-pairs (pairs (env-lookup env))
essential-pairs (filter (fn [[k v]] (or (cfunction? v) (abstract? v))) env-pairs)
lookup (table ;(mapcat identity essential-pairs))
diff --git a/src/include/janetconf.h b/src/include/janetconf.h
index 5ff9e9ee..d90fe0ad 100644
--- a/src/include/janetconf.h
+++ b/src/include/janetconf.h
@@ -43,6 +43,8 @@
/* #define JANET_NO_PEG */
/* #define JANET_NO_TYPED_ARRAY */
/* #define JANET_NO_INT_TYPES */
+/* #define JANET_NO_DOCSTRINGS */
+/* #define JANET_NO_SOURCEMAPS */
/* #define JANET_REDUCED_OS */
/* #define JANET_OUT_OF_MEMORY do { printf("janet out of memory\n"); exit(1); } while (0) */
/* #define JANET_RECURSION_GUARD 1024 */
diff --git a/test/suite6.janet b/test/suite6.janet
index c3f7c502..e53ad0c8 100644
--- a/test/suite6.janet
+++ b/test/suite6.janet
@@ -157,5 +157,9 @@
(assert (= (test-expand "./abc" ":cur:/:all:") "some-dir/abc") "module/expand-path 2")
(assert (= (test-expand "abc/def.txt" ":cur:/:name:") "some-dir/def.txt") "module/expand-path 3")
(assert (= (test-expand "abc/def.txt" ":cur:/:dir:/sub/:name:") "some-dir/abc/sub/def.txt") "module/expand-path 4")
+(assert (= (test-expand "/abc/../def.txt" ":all:") "/def.txt") "module/expand-path 5")
+(assert (= (test-expand "abc/../def.txt" ":all:") "def.txt") "module/expand-path 6")
+(assert (= (test-expand "../def.txt" ":all:") "../def.txt") "module/expand-path 7")
+(assert (= (test-expand "../././././abcd/../def.txt" ":all:") "../def.txt") "module/expand-path 8")
(end-suite)