1
0
mirror of https://github.com/janet-lang/janet synced 2025-05-07 01:44:15 +00:00

Add experimental meson build.

Should help with IDE integration.
This commit is contained in:
Calvin Rose 2019-03-22 18:07:10 -04:00
parent cb2caecbb3
commit 25aa7a26c5
8 changed files with 163 additions and 6 deletions

1
.gitignore vendored
View File

@ -4,6 +4,7 @@ dst
janet janet
!*/**/janet !*/**/janet
/build /build
/builddir
/Build /Build
/Release /Release
/Debug /Debug

View File

@ -77,7 +77,7 @@ build/janet_boot: $(JANET_BOOT_OBJECTS)
# Now the reason we bootstrap in the first place # Now the reason we bootstrap in the first place
build/core_image.c: build/janet_boot build/core_image.c: build/janet_boot
JANET_PATH=$(JANET_PATH) build/janet_boot build/janet_boot $@ JANET_PATH $(JANET_PATH)
########################################################## ##########################################################
##### The main interpreter program and shared object ##### ##### The main interpreter program and shared object #####

View File

@ -125,6 +125,7 @@ copy README.md dist\README.md
copy janet.lib dist\janet.lib copy janet.lib dist\janet.lib
copy janet.exp dist\janet.exp copy janet.exp dist\janet.exp
copy src\include\janet.h dist\janet.h copy src\include\janet.h dist\janet.h
copy src\include\janetconf.h dist\janetconf.h
copy tools\cook.janet dist\cook.janet copy tools\cook.janet dist\cook.janet
copy tools\highlight.janet dist\highlight.janet copy tools\highlight.janet dist\highlight.janet
exit /b 0 exit /b 0

142
meson.build Normal file
View File

@ -0,0 +1,142 @@
# Copyright (c) 2019 Calvin Rose and contributors
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
project('janet', 'c', default_options : ['c_std=c99'])
# Link math library on all systems
cc = meson.get_compiler('c')
m_dep = cc.find_library('m', required : false)
dl_dep = cc.find_library('dl', required : false)
# Some options
add_project_arguments('-DJANET_BUILD="meson"', language : 'c')
# Include directories
incdir = include_directories('src/include')
# Building generated sources
xxd = executable('xxd', 'tools/xxd.c')
gen = generator(xxd,
output : '@BASENAME@.gen.c',
arguments : ['@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@'])
core_gen = gen.process('src/core/core.janet', extra_args: 'janet_gen_core')
boot_gen = gen.process('src/boot/boot.janet', extra_args: 'janet_gen_boot')
init_gen = gen.process('src/mainclient/init.janet', extra_args: 'janet_gen_init')
core_src = [
'src/core/abstract.c',
'src/core/array.c',
'src/core/asm.c',
'src/core/buffer.c',
'src/core/bytecode.c',
'src/core/capi.c',
'src/core/cfuns.c',
'src/core/compile.c',
'src/core/corelib.c',
'src/core/debug.c',
'src/core/emit.c',
'src/core/fiber.c',
'src/core/gc.c',
'src/core/inttypes.c',
'src/core/io.c',
'src/core/marsh.c',
'src/core/math.c',
'src/core/os.c',
'src/core/parse.c',
'src/core/peg.c',
'src/core/pp.c',
'src/core/regalloc.c',
'src/core/run.c',
'src/core/specials.c',
'src/core/string.c',
'src/core/strtod.c',
'src/core/struct.c',
'src/core/symcache.c',
'src/core/table.c',
'src/core/tuple.c',
'src/core/typedarray.c',
'src/core/util.c',
'src/core/value.c',
'src/core/vector.c',
'src/core/vm.c',
'src/core/wrap.c'
]
boot_src = [
'src/boot/array_test.c',
'src/boot/boot.c',
'src/boot/buffer_test.c',
'src/boot/number_test.c',
'src/boot/system_test.c',
'src/boot/table_test.c',
]
mainclient_src = [
'src/mainclient/line.c',
'src/mainclient/main.c'
]
# Build boot binary
janet_boot = executable('janet_boot', core_src, boot_src, core_gen, boot_gen,
c_args : '-DJANET_BOOTSTRAP',
dependencies : [m_dep, dl_dep])
# Build core image
core_image = custom_target('core_image',
input : [janet_boot],
output : 'core_image.gen.c',
command : [janet_boot, '@OUTPUT@',
'JANET_PATH', join_paths(get_option('libdir'), 'janet')])
libjanet = shared_library('janet', core_src, core_image,
dependencies : [m_dep, dl_dep],
install : true)
janet_mainclient = executable('janet', core_src, core_image, init_gen, mainclient_src,
dependencies : [m_dep, dl_dep],
install : true)
# Tests
test_files = [
'test/suite0.janet',
'test/suite1.janet',
'test/suite2.janet',
'test/suite3.janet',
'test/suite4.janet',
'test/suite5.janet',
'test/suite6.janet'
]
foreach t : test_files
test(t, janet_mainclient, args : files([t]), workdir : meson.current_source_dir())
endforeach
# Repl
run_target('repl', command : [janet_mainclient])
# Installation
install_man('janet.1')
install_headers('src/include/janet.h', 'src/include/janetconf.h')
janet_libs = [
'src/include/janet.h',
'src/include/janetconf.h'
'tools/bars.janet',
'tools/cook.janet',
'tools/highlight.janet'
]
install_data(sources : janet_libs)

View File

@ -26,7 +26,7 @@
extern const unsigned char *janet_gen_boot; extern const unsigned char *janet_gen_boot;
extern int32_t janet_gen_boot_size; extern int32_t janet_gen_boot_size;
int main() { int main(int argc, const char **argv) {
/* Init janet */ /* Init janet */
janet_init(); janet_init();
@ -46,6 +46,12 @@ int main() {
env = janet_core_env(NULL); env = janet_core_env(NULL);
/* Create args tuple */
JanetArray *args = janet_array(argc);
for (int i = 0; i < argc; i++)
janet_array_push(args, janet_cstringv(argv[i]));
janet_def(env, "process/args", janet_wrap_array(args), "Command line arguments.");
/* Run bootstrap script to generate core image */ /* Run bootstrap script to generate core image */
status = janet_dobytes(env, janet_gen_boot, janet_gen_boot_size, "boot.janet", NULL); status = janet_dobytes(env, janet_gen_boot, janet_gen_boot_size, "boot.janet", NULL);

View File

@ -16,6 +16,15 @@
# everything else goes. Cfunctions and abstracts will be referenced from a registry # everything else goes. Cfunctions and abstracts will be referenced from a registry
# table which will be generated on janet startup. # table which will be generated on janet startup.
(do (do
# Get process options
(def- process/opts @{})
(each [k v] (partition 2 (tuple/slice process/args 2))
(put process/opts k v))
# Set up default config from arguments
(set module/*syspath* (or (process/opts "JANET_PATH") ""))
(def image (let [env-pairs (pairs (env-lookup *env*)) (def image (let [env-pairs (pairs (env-lookup *env*))
essential-pairs (filter (fn [[k v]] (or (cfunction? v) (abstract? v))) env-pairs) essential-pairs (filter (fn [[k v]] (or (cfunction? v) (abstract? v))) env-pairs)
lookup (table ;(mapcat identity essential-pairs)) lookup (table ;(mapcat identity essential-pairs))
@ -26,7 +35,7 @@
# can be compiled and linked statically into the main janet library # can be compiled and linked statically into the main janet library
# and example client. # and example client.
(def chunks (string/bytes image)) (def chunks (string/bytes image))
(def image-file (file/open "build/core_image.c" :w)) (def image-file (file/open (process/args 1) :w))
(file/write image-file (file/write image-file
"#ifndef JANET_AMALG\n" "#ifndef JANET_AMALG\n"
"#include <janet.h>\n" "#include <janet.h>\n"

View File

@ -1584,7 +1584,7 @@
"The path where globally installed libraries are located. "The path where globally installed libraries are located.
The default is set at build time and is /usr/local/lib/janet on linux/posix, and The default is set at build time and is /usr/local/lib/janet on linux/posix, and
on Windows is C:/Janet/Library." on Windows is C:/Janet/Library."
(or (os/getenv "JANET_PATH") "")) "")
(defn- fexists [path] (defn- fexists [path]
(def f (file/open path)) (def f (file/open path))

View File

@ -831,12 +831,10 @@ JanetTable *janet_core_env(JanetTable *replacements) {
janet_lib_inttypes(env); janet_lib_inttypes(env);
#endif #endif
#ifdef JANET_BOOTSTRAP #ifdef JANET_BOOTSTRAP
/* Run bootstrap source */ /* Run bootstrap source */
janet_dobytes(env, janet_gen_core, janet_gen_core_size, "core.janet", NULL); janet_dobytes(env, janet_gen_core, janet_gen_core_size, "core.janet", NULL);
#else #else
/* Unmarshal from core image */ /* Unmarshal from core image */
Janet marsh_out = janet_unmarshal( Janet marsh_out = janet_unmarshal(
janet_core_image, janet_core_image,