janet-lang / janet

A dynamic language and bytecode vm
https://janet-lang.org
MIT License
3.45k stars 223 forks source link

Is there a common way to distribute software written in Janet? #34

Closed ryukinix closed 5 years ago

ryukinix commented 5 years ago

In Common Lisp for instance you can load your own code into your REPL and make a binary dump. After that you can use this dump binary as your own executable software and it's possible distribute in this fashion. This is common in game development for CL enthusiasts.

In Clojure there is the .jar stuff from Java, it's tied to JVM, but at least it's something.

So... There is a way to embed a janet software as a standalone executable, portable at same operating-system wise? Like Golang builds: a executable statically linked.

If don't have, is there any plan to develop something like that?

bakpakin commented 5 years ago

Currently, the best way is a source distribution.

However, I have been working on packaging code into blobs that can be loaded without parsing and compiling. The core library is actually loaded this way. I plan on adding a way to both load binary blobs (images) as modules, and also execute an image. Images are just Janet data structures marshalled with the marshal function.

bakpakin commented 5 years ago

BTW, these images could likely be portable across OSs.

ryukinix commented 5 years ago

WOW! This indeed is a nice feature! I'll be watching the janet development :)

bakpakin commented 5 years ago

As of 3b6ff3c09a6dcbe4d177f0ae07094b1aa2d31ab4, Janet can now precompile modules into images via the -c flag.

For example:

$ build/janet -c examples/colors.janet clrs.jimage
$ build/janet
janet:0:> (import clrs)
nil
janet:14:> (print (clrs/color :green "hello"))
hello # but in green
nil
janet:50:>

Or after building the image:

$ build/janet -l clrs -e '(print (color :green "hello"))'

This doesn't yet link the module to the janet binary to form a single executable file, but that should be possible

ryukinix commented 5 years ago

Nice improvement! I'll test it later. Good work!

sepisoad commented 5 years ago

keep up the good work

andrewchambers commented 5 years ago

I think a git repository that is something like 'janet-lang/pkgs' which just contains janet tables of urls and cryptographic hashes might be nice. Sort of like a registry of import paths.

Walking those tables could emit package definitions for many different operating systems, or be used to build directly.

bakpakin commented 5 years ago

I think a git repository that is something like 'janet-lang/pkgs' which just contains janet tables of urls and cryptographic hashes might be nice. Sort of like a registry of import paths.

We could definitely set something up like that, its probably a good first step towards a package ecosystem. I think each entry should contain links to source by default or janet images, as these are cross platform, as well as lots of metadata.

For packaging native code, I'm still unsure of the best way to do it that's easy and portable. The cook.janet scripts in some of the modules like JSON work very well for small, self contained projects, but are certainly a leaky abstraction for cross platform libraries that actually need to link to system specific libraries (libuv comes to mind).

bakpakin commented 5 years ago

We have been working on the jpm tool for building, and hopefully eventually managing dependencies, distributing software, and several other developer facing tasks. As of now, jpm install in a directory with a project.janet file can be used to add scripts to some PATH (see mendoza's project.janet for a simple example). jpm will be Janet's main build tool and language-level package manager.

ryukinix commented 5 years ago

Congratulations for this awesome work, @bakpakin. I see a nice future for janet and it's great to see this level of care about software distribution, where so many languages failed miserably.

sleepyfox commented 5 years ago

Please don't go down the path of npm (central package hosting), but instead normalise linking to independent github/gitlab/... repos for packages. Thanks. Keep up the good work!.

bakpakin commented 5 years ago

So jpm actually has a lot of these features already, including installing dependencies from git urls, and building executables! jpm will never do anything centralized because it’s way more work for me and for people who want to create packages. I am going to push a documentation page to Janet-Lang.org soon, but all of this functionality is in the latest master and will be in 1.2.0. installing git dependencies requires having git installed, and building an executable requires a c compiler, but should both work on most supported systems including windows.

Sent with GitHawk

sleepyfox commented 5 years ago

Thanks for the reply, I'd certainly be up for helping with the doco for new starters.

bakpakin commented 5 years ago

All of the functionality for deploying Janet code with jpm has been released in 1.2.0, and documentation on it can be found here. For updates on the docs, file a bug against https://github.com/janet-lang/janet-lang.org.