-
Hi, I recently discovered Ian Henry's Janet for Mortals and am checking it out casually but with great interest. In it he writes "You can compile Janet programs into statically-linked native binaries and give them to people who have never even heard of Janet before", which I am very interested in trying, but didn't find a thorough treatment in the book. In the discussion at #818 @fjan77's reply makes it look easy, but I don't have the background knowledge to connect the dots, so I'd greatly appreciate some guidance and hopefully it will help someone else with the same objectives. I am on ubuntu 22.04 and I run the nix package manager, so I have 2 ways of setting up janet / jpm. The first is via nix flake, which I'll leave out of scope for now, except that in the flake, the least requirements to get started are to declare nixpkgs.janet and nixpkgs.jpm. Without the flake, I compile janet and jpm from the github source. I don't do global install but I specify environment variables and flags where necessary. (side comment for completeness) : I cloned janet to Following another github thread, I test a dynamically linked executable with # temp.janet
(defn main
[&]
(print "hello")) I have this Makefile; the contrived paths resolve the funny structure from my janet build from github -- for now this is just to verify reproducibility temp: temp.janet
C_INCLUDE_PATH=/tmp/janet/build /tmp/janet/build/jpm/usr/local/bin/jpm --libpath=/tmp/janet/build -v quickbin $< $@ this is successful. $ make
$ ./temp
hello similarly, within the flake devShell, this creates a working executable: # jpm looks in jpm's store path by default; the correct janet libpath is in ${nixpkgs.janet}/lib
$ jpm --libpath=/nix/store/ib2sqi3rfk2pr9kbdvb7q50np9mq0zd4-janet-1.32.1/lib quickbin temp.janet temp
$ ./temp
hello from here, how can I get to a statically linked binary? To verify a working $ nix-shell musl
$ cat > main.c <<EOF
#include <stdio.h>
int main(int argc, char *argv[]) { printf("hello \n"); }
EOF
$ musl-gcc -static main.c
$ ./a.out
hello following discussion #818 I create such a project.janet (declare-project
:name "probably-unimportant")
(declare-executable
:name "project-temp"
:entry "temp.janet"
:lflags ["-static"]) running
so this is at the edge of my knowledge of working with |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I used qemu to setup an Alpine environment temporarily and carried out similar steps successfully. Below is a summary of what I tried. Setup and start Alpine system
After it starts up, login as root (no / blank password), then use fdisk to create a partition:
I used Prepare filesystem, mount, and start setup:
Answered (mostly defaults):
Update apk repository indexes
Install some packages
Tweak PATH things:
Fetch janet source:
Build and install janet and jpm:
Make static executable sample dir:
Create sample file
Create sample file
Build:
Check result:
N.B. I didn't try to persist this enivornment. Possibly using Update: I tried References |
Beta Was this translation helpful? Give feedback.
I used qemu to setup an Alpine environment temporarily and carried out similar steps successfully.
Below is a summary of what I tried.
Setup and start Alpine system
After it starts up, login as root (no / blank password), then use fdisk to create a partition:
I used
n
to add a new primary partition a…