aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorCalvin Rose <calsrose@gmail.com>2025-11-16 10:12:57 -0600
committerCalvin Rose <calsrose@gmail.com>2025-11-21 21:08:19 -0600
commit19631a42310a5f6cf58b0abf38badaa571f7dfb2 (patch)
treee3c7fc717acc7b2b596b845b52d8742e4ad0518f
parent`spork/date`: Cache original strings in output of `from-string` (diff)
Add janet-pm `full-env` command.
Same as env, but copies over installed files. First implementation only copies over posix files.
-rwxr-xr-xbin/janet-pm13
-rw-r--r--spork/pm.janet74
2 files changed, 86 insertions, 1 deletions
diff --git a/bin/janet-pm b/bin/janet-pm
index 2f66430..5106f46 100755
--- a/bin/janet-pm
+++ b/bin/janet-pm
@@ -52,6 +52,11 @@
Create an environment with which one can install Janet
dependencies and scripts in an isolated manner.
+ full-env name
+ Similar to `env name`, but also copies a snapshot of the Janet
+ interpreter, headers, pkgconfig, and shared objects. Useful when
+ using multiple Janet versions.
+
new-project name
Create a new Janet project in a directory `name`.
@@ -121,6 +126,7 @@
JANET_BUILD_TYPE
What kind of build to make when building a bundle that has a
project.janet. Should be "develop", "release", or "debug".
+ Defaults to "release".
JANET_CURL
Where to get the "curl" command when handling project.janet.
@@ -269,6 +275,12 @@
[path]
(pm/scaffold-pm-shell path))
+(defn new-full-venv
+ "Create a new virtual environment, capturing snapshots of the janet interpreter and shared libraries as well."
+ [path]
+ (pm/scaffold-pm-shell path)
+ (pm/vendor-binaries-pm-shell path))
+
(defn quickbin
"Create an executable file"
[entry output]
@@ -297,6 +309,7 @@
"deps" deps
"hook" do-hook
"env" new-venv
+ "full-env" new-full-venv
"new-project" new-project
"new-simple-project" new-simple-project
"new-c-project" new-c-project
diff --git a/spork/pm.janet b/spork/pm.janet
index 12e7532..ce13f00 100644
--- a/spork/pm.janet
+++ b/spork/pm.janet
@@ -9,6 +9,7 @@
(import ./sh)
(import ./path)
(import ./pm-config)
+(import ./cc)
(defdyn *gitpath* "What git command to use to fetch dependencies")
(defdyn *tarpath* "What tar command to use to fetch dependencies")
@@ -748,11 +749,15 @@
````)
(defn scaffold-pm-shell
- "Generate a pm shell with configuration already setup."
+ "Generate a pm shell with configuration already setup. If `copy-janet` is truthy, the Janet executable file
+ will be bundled in the new environment"
[path]
(os/mkdir path)
(os/mkdir (path/join path "bin"))
(os/mkdir (path/join path "man"))
+ (os/mkdir (path/join path "include"))
+ (os/mkdir (path/join path "pkgconfig"))
+ (os/mkdir (path/join path "lib"))
(def opts {:path path :abspath (path/abspath path) :name (path/basename path)})
(spit (path/join path "bin" "activate") (enter-shell-template opts))
(spit (path/join path "bin" "activate.ps1") (enter-ps-template opts))
@@ -762,3 +767,70 @@
(print "(PowerShell) run `. " path "/bin/activate.ps1` to enter the new environment, then `deactivate` to exit.")
(print "(CMD) run `" path "\\bin\\activate` to enter the new environment, then `deactivate` to exit.")
(print "(Unix sh) run `. " path "/bin/activate` to enter the new environment, then `deactivate` to exit."))
+
+(defn- try-copy
+ [src dest]
+ (unless (sh/exists? src) (break false))
+ (sh/copy src dest)
+ true)
+
+(defn vendor-binaries-pm-shell
+ ```
+ Copy the Janet interpreter, shared libraries, and other installation files directly into the new shell environment. This allows
+ updates and changes to the system configuration without breaking the shell.
+ ```
+ [path]
+ (def is-win (= :windows (os/which)))
+ (def exec-name (dyn *executable* "janet"))
+ (def executable (sh/which exec-name))
+ (assert (sh/exists? executable) "unable to resolve location of the janet binary. Is it on your path?")
+ (def exe-ext (if is-win ".exe" ""))
+ (def dest (string (path/join path "bin" "janet") exe-ext))
+ (sh/copy executable dest)
+
+ # Copy shared objects, DLLs, static archives, and janet.h into path
+ (def [has-prefix prefix] (protect (cc/get-unix-prefix)))
+ (when has-prefix
+ (def lib (string prefix "/lib"))
+ (def include (string prefix "/include"))
+ (def parts (string/split "." janet/version))
+ (def majorminor (string (in parts 0) "." (in parts 1)))
+
+ # Copy libjanet.so (with correct symlinks and versions)
+ (def libjanet-so-with-version (string "libjanet.so." majorminor))
+ (def libjanet-so-with-full-version (string "libjanet.so." janet/version))
+ (when (try-copy (path/join lib libjanet-so-with-full-version) (path/join path "lib" libjanet-so-with-full-version))
+ (os/link libjanet-so-with-full-version (path/join path "lib" libjanet-so-with-version) true)
+ (os/link libjanet-so-with-full-version (path/join path "lib" "libjanet.so") true))
+
+ # Copy libjanet.dylib (with correct symlinks and versions)
+ (def libjanet-dylib-with-version (string "libjanet.dylib." majorminor))
+ (def libjanet-dylib-with-full-version (string "libjanet.dylib." janet/version))
+ (when (try-copy (path/join lib libjanet-dylib-with-full-version) (path/join path "lib" libjanet-dylib-with-full-version))
+ (os/link libjanet-dylib-with-full-version (path/join path "lib" libjanet-dylib-with-version) true)
+ (os/link libjanet-dylib-with-full-version (path/join path "lib" "libjanet.dylib") true))
+
+ # Copy libjanet.a (try versioned file first)
+ (def libjanet-static-full (string "libjanet.a." janet/version))
+ (if
+ (try-copy (path/join lib libjanet-static-full) (path/join path "lib" libjanet-static-full))
+ (os/link (path/join path libjanet-static-full) (path/join path "lib" "libjanet.a") true)
+ (try-copy (path/join lib "libjanet.a") (path/join path "lib" "libjanet.a")))
+
+ # Copy janet.h
+ (os/mkdir (path/join path "include" "janet"))
+ (try-copy (path/join include "janet" "janet.h") (path/join path "include" "janet" "janet.h"))
+ (try-copy (path/join include "janet.h") (path/join path "include" "janet.h"))
+
+ # pkgconfig TODO
+ nil)
+
+ # Copy shared objects, DLLs, static archives, and janet.h into path
+ (def [has-winprefix win-prefix] (protect (cc/get-msvc-prefix)))
+ (when has-winprefix
+ (os/mkdir (path/join path "C"))
+ (each name ["janet.lib" "janet.h" "janet.exp" "janet.c" "libjanet.lib"]
+ (try-copy (path/win32/join win-prefix "C" name) (path/win32/join path "C" name))))
+
+ (print "Copied janet binaries and shared libraries into " path)
+ nil)