mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-30 23:23:07 +00:00 
			
		
		
		
	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.
			
			
This commit is contained in:
		| @@ -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); | ||||
|  | ||||
|   | ||||
| @@ -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)) | ||||
|   | ||||
| @@ -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 */ | ||||
|   | ||||
| @@ -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) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Calvin Rose
					Calvin Rose