Closed yunfan closed 7 months ago
I also have a per-user installation of janet and jpm and setting that up has been working for me (see below for specific commands I use for comparison).
Looking at the stacktrace, it seems possible from these lines:
that destdir
is not nil for line 25.
Do you happen to have the DESTDIR
environment variable set? My impression is that is not typical for ordinary user setups. For example, here:
$ janet
Janet 1.18.2-dev-a20bdd33 linux/x64 - '(doc)' for help
repl:1:> (os/getenv "DESTDIR")
nil
If it is set, may be it's worth unsetting it and trying again?
On a side note, there is another way to install jpm, which is to use the following Makefile target in janet's source repository: https://github.com/janet-lang/janet/blob/a20bdd334aa082f6e8e228f32f12efcab5345098/Makefile#L291 -- see below for an example invocation.
The following are the steps I use to install janet for a per-user installation:
make clean && PREFIX=$HOME/.local make && PREFIX=$HOME/.local make install
and jpm:
PREFIX=$HOME/.local janet bootstrap.janet
In my case this has been working ok for various Linux setups.
I've also occasionally done the following to install jpm via janet's source repository:
PREFIX=$HOME/.local make install-jpm-git
A question, is there an environment variable like PREFIX, to choose libpath as well?
Not quite sure what's being asked, but according to the jpm man page, there is JANET_LIBPATH
. Possibly of interest is other JANET_*
environment variables listed there. I think these all apply post-installation.
There's also this bit in the README:
To override/set the default configuration, replace the contents of default-config.janet with a customized config file before installing. To select a configuration file to use to override the default when installing, pass in a config file argument to the bootstrap.janet script
with more details at the README.
FWIW, at least one of the sample config files has a line mentioning libpath
:
https://github.com/janet-lang/jpm/blob/master/configs/linux_config.janet#L25
May be there's a way to do what you want via one of these means?
@sogaiu Thanks, JANET_LIBPATH does the trick for me!
This was a bit confusing for me too. Looking at the bootstrap script, it appears that DESTDIR
is the new PREFIX
:
(def destdir (os/getenv "DESTDIR"))
There are various places where PREFIX
is mentioned and that may need to be updated, such as the README.md
and the jpm page in the docs.
Edit: @sogaiu's instructions worked me.
I also have a per-user installation of janet and jpm and setting that up has been working for me (see below for specific commands I use for comparison).
Looking at the stacktrace, it seems possible from these lines:
* https://github.com/janet-lang/jpm/blob/6b2173e3606dc649f8ac63cf950d2a1b49fe573d/bootstrap.janet#L25 * https://github.com/janet-lang/jpm/blob/6b2173e3606dc649f8ac63cf950d2a1b49fe573d/jpm/make-config.janet#L28
that
destdir
is not nil for line 25.Do you happen to have the
DESTDIR
environment variable set? My impression is that is not typical for ordinary user setups. For example, here:$ janet Janet 1.18.2-dev-a20bdd33 linux/x64 - '(doc)' for help repl:1:> (os/getenv "DESTDIR") nil
If it is set, may be it's worth unsetting it and trying again?
On a side note, there is another way to install jpm, which is to use the following Makefile target in janet's source repository: https://github.com/janet-lang/janet/blob/a20bdd334aa082f6e8e228f32f12efcab5345098/Makefile#L291 -- see below for an example invocation.
The following are the steps I use to install janet for a per-user installation:
make clean && PREFIX=$HOME/.local make && PREFIX=$HOME/.local make install
and jpm:
PREFIX=$HOME/.local janet bootstrap.janet
In my case this has been working ok for various Linux setups.
I've also occasionally done the following to install jpm via janet's source repository:
PREFIX=$HOME/.local make install-jpm-git
thanks for the reply, i had follow your step to build janet again, but still got issue which require sudo permission
the command i use is
make clean && PREFIX=$HOME/app/janet make && PREFIX=$HOME/app/janet make install
and the last error is
mkdir -p '/home/jyf/app/janet/lib/pkgconfig'
cp build/janet.pc '/home/jyf/app/janet/lib/pkgconfig/janet.pc'
[ -z '' ] && ldconfig "/home/jyf/app/janet/lib" || true
/sbin/ldconfig.real: Can't create temporary cache file /etc/ld.so.cache~: Permission denied
rm build/janet.pc
the janet source code is master version which i just cloned from official
@yunfan Not sure what you mean by error here, but if you mean:
/sbin/ldconfig.real: Can't create temporary cache file /etc/ld.so.cache~: Permission denied
FWIW, that happens for me usually. I think bakpakin mentioned that an error like this is not something to be concerned about.
I think it comes from here: https://github.com/janet-lang/janet/blob/94c19575b161a2ba4698446bdfd93af672c87871/Makefile#L302
thanks for the reply, according to the shell code line you mentioned, when DESTDIR hasnt been assigned, the script will try to do ldconfig, which require root permission.
i dont know why it has such behavior
May be @bakpakin knows why.
BTW, I would like janet to choose a default location if no sudo permission is given.
Using Janet on nixos or more generally on immutable distributions makes it impossible to install janet packages.
It would be nice if Janet defaulted to using the XDG directories when determining where to store packages and configurations: https://wiki.archlinux.org/title/XDG_Base_Directory
since asking for sudo to install project dependencies imperatively to a global root-owned folder with no way to specify ranges of versions other than a lockfile is just going to straight up disqualify janet for many uses.
A sensible default would be to look for a config file in XDG_CONFIG_HOME, and only fall back to system folders settings only if nothing exists in the user XDG folders
I think I see the problem with attempting to install into a system directory by default. This fix seems innocent, but since I am new to the code, all I can do is explain it for now.
If I un-tar Janet into a local directory:
$ tar -zxvf ~/Downloads/janet-v1.32.1-linux-x64.tar.gz
./janet-v1.32.1-linux/
./janet-v1.32.1-linux/LICENSE
./janet-v1.32.1-linux/include/
./janet-v1.32.1-linux/include/janet.h
./janet-v1.32.1-linux/man/
./janet-v1.32.1-linux/man/man1/
./janet-v1.32.1-linux/man/man1/janet.1
./janet-v1.32.1-linux/README.md
./janet-v1.32.1-linux/lib/
./janet-v1.32.1-linux/lib/libjanet.so
./janet-v1.32.1-linux/lib/libjanet.a
./janet-v1.32.1-linux/src/
./janet-v1.32.1-linux/src/janet.c
./janet-v1.32.1-linux/src/shell.c
./janet-v1.32.1-linux/bin/
./janet-v1.32.1-linux/bin/janet
./janet-v1.32.1-linux/CONTRIBUTING.md
then immediately try to install jpm
, I get this:
$ ~/dev/janet-v1.32.1-linux/bin/janet bootstrap.janet
PREFIX /home/bob/dev/janet-v1.32.1-linux
MANPATH /home/bob/dev/janet-v1.32.1-linux/share/man/man1
MP /usr/local/lib/janet
error: Permission denied: /usr/local/lib/janet
in os/mkdir [src/core/os.c] on line 1898
in create-dirs [jpm/shutil.janet] on line 106, column 27
in generate-config [jpm/make-config.janet] on line 59, column 7
in _thunk [bootstrap.janet] (tailcall) on line 25, column 24
where I've added a couple of (print)
statements into make-config.janet
to see where things go off the rails
you can see that if figures out PREFIX and MANPATH from the path to janet
but then when it tries to make the directory trees, MP (from modpath) defaults to a system directory:
(def fix-modpath (dyn :fix-modpath (os/getenv "JANET_STRICT_MODPATH")))
(def modpath (dyn :modpath (os/getenv "JANET_MODPATH" (if fix-modpath
(if win-prefix
(string win-prefix "/Library")
(string prefix "/lib/janet"))))))
# Generate directories
(when destdir
(let [mp (or modpath (dyn :syspath))]
(print "MP " mp)
(shutil/create-dirs (string destdir mp "/.manifests"))
(when manpath (shutil/create-dirs (string destdir manpath)))
(when binpath (shutil/create-dirs (string destdir binpath)))
(when libpath (shutil/create-dirs (string destdir libpath)))
(when headerpath (shutil/create-dirs (string destdir headerpath)))))
for some reason, modpath
doesn't get updated from PREFIX unless fix-modpath
is true. And I don't know why.
if I simply remove the conditional (if fix-modpath...
(def modpath (dyn :modpath (os/getenv "JANET_MODPATH" (if win-prefix
(string win-prefix "/Library")
(string prefix "/lib/janet")))))
then the bootstrap works as expected.
$ ~/dev/janet-v1.32.1-linux/bin/janet bootstrap.janet
PREFIX /home/bob/dev/janet-v1.32.1-linux
MANPATH /home/bob/dev/janet-v1.32.1-linux/share/man/man1
MP /home/bob/dev/janet-v1.32.1-linux/lib/janet
destdir:
Using install prefix: /home/bob/dev/janet-v1.32.1-linux
binpath: /home/bob/dev/janet-v1.32.1-linux/bin
libpath: /home/bob/dev/janet-v1.32.1-linux/lib
manpath: /home/bob/dev/janet-v1.32.1-linux/share/man/man1
headerpath: /home/bob/dev/janet-v1.32.1-linux/include/janet
modpath: /home/bob/dev/janet-v1.32.1-linux/lib/janet
Setting package listing: https://github.com/janet-lang/pkgs.git
Running jpm to self install...
generating /home/bob/dev/janet-v1.32.1-linux/lib/janet/.manifests/jpm.jdn...
Installed as 'jpm'.
copying jpm/cc.janet to /home/bob/dev/janet-v1.32.1-linux/lib/janet/jpm...
copying jpm/cli.janet to /home/bob/dev/janet-v1.32.1-linux/lib/janet/jpm...
copying jpm/commands.janet to /home/bob/dev/janet-v1.32.1-linux/lib/janet/jpm...
copying jpm/config.janet to /home/bob/dev/janet-v1.32.1-linux/lib/janet/jpm...
copying jpm/dagbuild.janet to /home/bob/dev/janet-v1.32.1-linux/lib/janet/jpm...
copying jpm/declare.janet to /home/bob/dev/janet-v1.32.1-linux/lib/janet/jpm...
copying jpm/init.janet to /home/bob/dev/janet-v1.32.1-linux/lib/janet/jpm...
copying jpm/make-config.janet to /home/bob/dev/janet-v1.32.1-linux/lib/janet/jpm...
copying jpm/pm.janet to /home/bob/dev/janet-v1.32.1-linux/lib/janet/jpm...
copying jpm/rules.janet to /home/bob/dev/janet-v1.32.1-linux/lib/janet/jpm...
copying jpm/shutil.janet to /home/bob/dev/janet-v1.32.1-linux/lib/janet/jpm...
copying jpm/scaffold.janet to /home/bob/dev/janet-v1.32.1-linux/lib/janet/jpm...
copying jpm/cgen.janet to /home/bob/dev/janet-v1.32.1-linux/lib/janet/jpm...
copying jpm.1 to /home/bob/dev/janet-v1.32.1-linux/share/man/man1...
installing jpm/jpm to /home/bob/dev/janet-v1.32.1-linux/bin/jpm
copying file ./temp-config.janet to /home/bob/dev/janet-v1.32.1-linux/lib/janet/jpm/default-config.janet...
Follow-up. Turns out that while this will install, a couple of the directories are wrong:
From the bootstrap output above:
Using install prefix: /home/bob/dev/janet-v1.32.1-linux
binpath: /home/bob/dev/janet-v1.32.1-linux/bin
libpath: /home/bob/dev/janet-v1.32.1-linux/lib
manpath: /home/bob/dev/janet-v1.32.1-linux/share/man/man1
headerpath: /home/bob/dev/janet-v1.32.1-linux/include/janet
modpath: /home/bob/dev/janet-v1.32.1-linux/lib/janet
you can see that binpath
, libpath
and manpath
are correct, but headerpath
and modpath
have an extra janet
at the end.
If I try to install a package:
$ ~/dev/janet-v1.32.1-linux/bin/jpm install spork
From https://github.com/janet-lang/spork
* branch HEAD -> FETCH_HEAD
HEAD is now at d644da0 Add option to convert :null to nil on encode.
compiling src/json.c to build/src___json.o...
compiling src/rawterm.c to build/src___rawterm.o...
compiling src/zip.c to build/src___zip.o...
compiling src/utf8.c to build/src___utf8.o...
compiling src/crc.c to build/src___crc.o...
compiling src/tarray.c to build/src___tarray.o...
compiling deps/miniz/miniz.c to build/deps___miniz___miniz.static.o...
compiling src/cmath.c to build/src___cmath.o...
src/rawterm.c:28:10: fatal error: janet.h: No such file or directory
28 | #include <janet.h>
| ^~~~~~~~~
to fix this, I have to modify the default jpm config installed above to change headerpath
and modpath
:headerpath "/home/bob/dev/janet-v1.32.1-linux/include"
:modpath "/home/bob/dev/janet-v1.32.1-linux/lib"
final comment:
Even with these changes, allowing jpm
to install and run in a local directory, janet
itself still is only looking for other modules in system directories:
$ janet
Janet 1.32.1-cc5beda linux/x64/gcc - '(doc)' for help
repl:1:> (import spork)
error: could not find module spork:
/usr/local/lib/janet/spork.jimage
/usr/local/lib/janet/spork.janet
/usr/local/lib/janet/spork/init.janet
/usr/local/lib/janet/spork.so
in require-1 [boot.janet] on line 3010, column 20
in import* [boot.janet] on line 3049, column 15
in _thunk [repl] (tailcall) on line 1, column 1
which makes me think that the only way to use add-on modules with Janet in a local directory is to build janet into that prefix instead of downloading the tar ball, then build jpm there as well, then install modules there.
Hope this helps anyone else stymied by this.
IIUC, pre-compiled versions of janet
for Linux (e.g. from here) all have /usr/local/lib/janet
hard-wired in. This can be observed by invoking:
janet -e '(print (dyn :syspath))'
I think that's part of the current design -- the "hard-wiring" happens here (see this bit for a related line and this part of boot.janet) during the build process.
Also, note this bit from a section of jpm
's README:
Generally, you will want to install to the same directory that Janet was installed to so jpm can find the required headers and libraries for compiling C libraries.
So putting those things from above together, if a non-default location setup is desired, the following might be one method (going to assume a $HOME/janet
directory as a "root" of sorts for concreteness below):
$HOME/janet
such that bin
, include
, etc. are at the top-level of $HOME/janet
.$HOME/janet/include/janet
and place a symlink in it named janet.h
that points at ../janet.h
JANET_PATH
env var to $HOME/janet/lib/janet
(to make things work beyond "installation", put a line in ~/.profile
or other appropriate shell configuration file to arrange similarly)$HOME/janet/bin
is early enough in PATH
so that the janet
in $HOME/janet/bin
is picked upJANET_PATH=$HOME/janet/lib/janet PREFIX=$HOME/janet janet bootstrap.janet
jpm
is now at $HOME/janet/bin/jpm
, e.g. via which jpm
jpm install spork
I gave those a try and the (import spork)
example from above worked for me.
If it's possible for one's setup, I think building from source is a way easier approach to achieving a similar end. FWIW, I still use the instructions from here and they've worked well in the non-immutable distributions I've used in the last few years since the instructions were posted.
@sogaiu Thanks for the detailed reply. I did read your note above, but didn't know enough about how Janet worked when I started down my path.
On Linux, it does work well.
On Windows, I didn't have any luck. Janet builds and runs ok, but I need to dig in deeper to see why jpm
won't install. Reading other issues here, I can see that Windows support is limited, so I'm trying to learn more about the internals of both Janet and jpm so I can help. (if I can)
@rwtolbert Would you mind elaborating on the following?
I can see that Windows support is limited
I haven't found Windows support in Janet itself to be that limited so I'd be interested in details that suggest this.
Libraries that other folks have written have perhaps not supported Windows as often or as fully though.
FWIW, on Windows, although I build from source, I use the .msi
that gets generated and thus don't typically configure the installation location.
(On a side note, I haven't worked with MingW enough yet to say how well that works.)
@sogaiu Sorry, I was very vague there.
In general, I was referring to several comments on issues here where folks working on jpm don't have access to Windows, Windows is different, etc.
Specifically, I got stuck by this, using a local build of janet.exe.
janet.exe .\bootstrap.janet
destdir:
Using install prefix: C:/Users/cohor/AppData/Local/Apps/Janet
binpath: C:/Users/cohor/AppData/Local/Apps/Janet/bin
libpath: C:/Users/cohor/AppData/Local/Apps/Janet/lib
manpath: C:/Users/cohor/AppData/Local/Apps/Janet/share/man/man1
headerpath: C:/Users/cohor/AppData/Local/Apps/Janet/include/janet
modpath: (default to JANET_PATH at runtime)
Setting package listing: https://github.com/janet-lang/pkgs.git
Running jpm to self install...
error: no value found for dynamic binding :modpath
in errorf [boot.janet] (tailcall) on line 159, column 3
in make-jpm-env [jpm/pm.janet] on line 51, column 21
in require-jpm [jpm/pm.janet] on line 60, column 12
in import-rules [jpm/pm.janet] on line 88, column 12
in local-rule [jpm/commands.janet] (tailcall) on line 170, column 3
in run [jpm/cli.janet] (tailcall) on line 88, column 9
in run-main [boot.janet] on line 3936, column 16
in cli-main [boot.janet] on line 4089, column 17
error: command failed with non-zero exit code 1
in os/execute [src/core/os.c] on line 1373
in do-bootstrap [.\bootstrap.janet] on line 14, column 3
in _thunk [.\bootstrap.janet] (tailcall) on line 26, column 1
I just need to dig deeper.
I'm very interested in doing more in Janet, and in helping with packaging, especially static linking and packaging. And I like making things work on Windows.
I built janet from source (and installed it) using build_win.bat all
in a x64 Native Tools Command Prompt just now. I didn't change anything in the source or set any particular values -- also I uninstalled an existing janet installation first.
Then in another x64 Native Tools Command Prompt window I first did:
C:\Users\user\Desktop\jpm>where janet
C:\Users\user\AppData\Local\Apps\Janet\bin\janet.exe
to verify that the newly installed janet.exe
would get used. Then I ran the bootstrap invocation for jpm installation like:
C:\Users\user\Desktop\jpm>janet bootstrap.janet
destdir:
Using install prefix: /usr/local
binpath: C:\Users\user\AppData\Local\Apps\Janet\bin\
libpath: C:\Users\user\AppData\Local\Apps\Janet\C\
manpath: C:\Users\user\AppData\Local\Apps\Janet\docs\
headerpath: C:\Users\user\AppData\Local\Apps\Janet\C\
modpath: (default to JANET_PATH at runtime)
Setting package listing: https://github.com/janet-lang/pkgs.git
Running jpm to self install...
removing C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm/cc.janet
removing C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm/cli.janet
removing C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm/commands.janet
removing C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm/config.janet
removing C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm/dagbuild.janet
removing C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm/declare.janet
removing C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm/init.janet
removing C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm/make-config.janet
removing C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm/pm.janet
removing C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm/rules.janet
removing C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm/shutil.janet
removing C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm/scaffold.janet
removing C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm/cgen.janet
removing C:\Users\user\AppData\Local\Apps\Janet\docs\/jpm.1
removing C:\Users\user\AppData\Local\Apps\Janet\bin\/jpm
removing C:\Users\user\AppData\Local\Apps\Janet\bin\/jpm.bat
removing C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm/default-config.janet
removing manifest C:\Users\user\AppData\Local\Apps\Janet\Library\/.manifests/jpm.jdn
Uninstalled.
generating C:\Users\user\AppData\Local\Apps\Janet\Library\/.manifests/jpm.jdn...
Installed as 'jpm'.
copying jpm/cc.janet to C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm...
jpm\cc.janet
1 File(s) copied
copying jpm/cli.janet to C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm...
jpm\cli.janet
1 File(s) copied
copying jpm/commands.janet to C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm...
jpm\commands.janet
1 File(s) copied
copying jpm/config.janet to C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm...
jpm\config.janet
1 File(s) copied
copying jpm/dagbuild.janet to C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm...
jpm\dagbuild.janet
1 File(s) copied
copying jpm/declare.janet to C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm...
jpm\declare.janet
1 File(s) copied
copying jpm/init.janet to C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm...
jpm\init.janet
1 File(s) copied
copying jpm/make-config.janet to C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm...
jpm\make-config.janet
1 File(s) copied
copying jpm/pm.janet to C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm...
jpm\pm.janet
1 File(s) copied
copying jpm/rules.janet to C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm...
jpm\rules.janet
1 File(s) copied
copying jpm/shutil.janet to C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm...
jpm\shutil.janet
1 File(s) copied
copying jpm/scaffold.janet to C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm...
jpm\scaffold.janet
1 File(s) copied
copying jpm/cgen.janet to C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm...
jpm\cgen.janet
1 File(s) copied
copying jpm.1 to C:\Users\user\AppData\Local\Apps\Janet\docs\...
C:jpm.1
1 File(s) copied
installing jpm/jpm to C:\Users\user\AppData\Local\Apps\Janet\bin\/jpm
copying file ./temp-config.janet to C:\Users\user\AppData\Local\Apps\Janet\Library\/jpm/default-config.janet...
So here it seems to be working.
I did find the line:
Using install prefix: /usr/local
to be curious. Also, that seems to differ from the output you posted.
FWIW, once janet.exe
is installed, I think JANET_*
env vars should be in effect in subsequent command prompts. All of the ones I see start with C:\Users\user\AppData\Local\Apps\Janet
and only vary at the tail end.
I don't know that it would make a difference, but the tests here were done with Windows 10.
Thanks. After work, I'll get back on my Windows machine and see if I can figure out why we get different results.
On a side note, at this point though, perhaps we are investigating a different issue from the original as sudo
does not seem relevant for the Windows situation we appear to be discussing.
If you agree, may be it's better to start another issue.
@sogaiu Starting from a clean slate, I get the result you do, following your Windows' steps above. No idea what caused my previous issue but if anything new comes up, I'll start a new issue.
One thing that tripped me up when trying to get the MingW version to work was that the Windows version had arranged for JANET_*
env vars to be in place.
I had assumed that I could have both a MingW and a Windows version available at the same time without extra arrangements (e.g. unsetting env vars before starting a build process and explicitly setting certain env vars in shell initialization files for subsequent use of MingW's janet
/ jpm
).
IIUC, the MingW version's build process ended up referencing the env var info that the Windows version installation process set up.
Perhaps it's possible that a previous installation attempt had left some traces or a command prompt that still had such info in its associated environment got reused?
Anyway, good to hear things are working now :)
I am fighting similar problems right now on sr.ht builds. I found a possible culprit; I will let you know if I am right later.
finally it works correctly both at my PC and termux
hi by checking the README
i had tried
my janet is located at
~/app/janet/bin
so my purpose is to installing jpm also to this but i got the errorwhich i guess indicate
PREFIX
not work as expected