v icon indicating copy to clipboard operation
v copied to clipboard

A solution to the ~/code problem. What do you think?

Open medvednikov opened this issue 7 years ago • 26 comments

Hey,

Right now V must be installed in ~/code/v, because it needs to know the location of the vlib modules.

One way to fix this is introduce an environment variable, like Go's GOROOT. But I really don't like this.

I came up with the following idea. You git clone v.git in any directory, cd compiler/, build V. When building for the first time, V will look for the modules in the parent directory, and write down that directory in ~/.config/v.

Now it can be used anywhere, and the V installation can also be anywhere.

What do you think?

medvednikov avatar Jun 23 '19 14:06 medvednikov

I wouldn't really regard keeping track of the modules a configuration, more so metadata than anything. Personally I think ~/.v would be a viable decision, and any subsequent child directories such as modules, build data, output, etc, would get placed within there. Having a defuncto place where everything is located keeps things much simpler, having explicit control via environmental variables seems more hassle than it's worth - but still maybe a consideration.

ghost avatar Jun 23 '19 14:06 ghost

How about instead installing libraries in /usr/lib?

LouCle avatar Jun 23 '19 14:06 LouCle

How about instead installing libraries in /usr/lib?

As much as it sounds nice, libraries shouldn't be system wide imo. But confined within the users home directory which also helps with versioning and libs potentially conflicting. Seems to be a much more simplistic route than placing libs globally.

ghost avatar Jun 23 '19 14:06 ghost

I remember most time we don't need explicit set GOROOT var, but go depend on it's install directory structure. So once you know go's path, it can automatically populate lib path.

Another, not think save a config file is good. just dynamically calculate.

kitech avatar Jun 23 '19 14:06 kitech

I would like to have ~/.vlang as V config directory.

threeid avatar Jun 23 '19 14:06 threeid

I suggest using /usr/share/vlang/ for compiler source files and vlib; compiled modules should be stored and automatically looked for in project directories, e.g. ./modules, ./.modules, etc.

Undumendil avatar Jun 23 '19 14:06 Undumendil

A GOPATH or PYTHONPATH like solution is the cleanest in my opinion. It doesn't clutter the system path with libraries of different versions.

MoAlyousef avatar Jun 23 '19 15:06 MoAlyousef

We should consider multi-versions of vlang coexists on a system.

kvinwang avatar Jun 23 '19 15:06 kvinwang

I like the GOPATH way better. If a config file is used,

  • how do you use different v versions? with an environment variable for the configuration path?
  • how do you use a version you haven't built yourself (e.g. a packaged binary)?

The default path could also be specified at build time and embedded in the binary, which would help for distributions and local development builds.

McKael avatar Jun 23 '19 16:06 McKael

We should consider multi-versions of vlang coexists on a system.

A great approach could be involving a solution like rustup/nvm, by using it we can updating/choosing the compiler version (for example: "v use v0.0.*, v use stable or v use devel).

ghost avatar Jun 23 '19 16:06 ghost

And what should Linux package maintainers do? In Linux, the right place where vlib should be is /usr/lib/(v|vlang)/(lib|vlib)

For example in ArchLinux For Rust /usr/lib/rustlib/

For Go:

$ echo $GOPATH
/home/user/.go
$ \ls -1 ~/.go/
bin
pkg
src
$ readlink -f /usr/bin/go
/usr/lib/go/bin/go
$ \ls -1 /usr/lib/go/
api
bin
doc
lib
misc
pkg
src
test
VERSION

whoizit avatar Jun 23 '19 16:06 whoizit

Please do not clutter home with hidden folders, use ~/.config/.v or ~/.config/v Thank you for you awesome work.

aguspiza avatar Jun 23 '19 16:06 aguspiza

A great approach could be involving a solution like rustup/nvm, by using it we can updating/choosing the compiler version (for example v0.0.*, stable and devel).

I like rustup too. but:

  • rustup is a outband tool. It is not in the rustc.
  • it is difficult to make this approach work well. rustup have 23k loc (even more than the whole vlang project). using GOPATH way just keep it simple.

kvinwang avatar Jun 23 '19 16:06 kvinwang

@aguspiza should be $XDG_CONFIG_HOME/(v|vlang)

whoizit avatar Jun 23 '19 16:06 whoizit

I used to be less than fond of the GOPATH way myself. Once you get used to it, you really don't want to miss it though.

It's really not that bad. I think you should consider it.

Happy-Ferret avatar Jun 23 '19 17:06 Happy-Ferret

Personally I would also put my voice behind following the freedesktop specification. Using $XDG_DATA_HOME for libraries / compilers and maybe even global modules (if that would be added) and $XDG_CONFIG_HOME for a config file managing the information about versions/libraries. Sure that would be more effort to implement, but it would be a clean solution.

JonnyCodewalker avatar Jun 23 '19 17:06 JonnyCodewalker

A temprorary work around is something like this:

cd v

wget https://vlang.io/v.c

curren_lib="$(pwd)"

sed \
    "s|os__home_dir(), tos2(\"/code/v/\")|tos2(\"${curren_lib}\"), tos2(\"/\")|g" \
    v.c \
    > compiler/v.c

cd compiler
clang -w -o vc v.c

sed -i \
    "s|mut lang_dir = os.home_dir() + '/code/v/'|mut lang_dir = '/usr/lib/v/'|g" \
    main.v

./vc -o v .

Maybe the makefile can be modified to make those changes on the fly and compile and even support a PREFIX flag to be able to change the /usr/lib value...

jgmdev avatar Jun 23 '19 18:06 jgmdev

I implemented it experimentally. Screenshot from 2019-06-24 22-25-22

It uses V_PATH env-var and use ~/code/v/ if not defined. I think a great point of this way is

  • we can even introduce config file later
  • developer can choose the path according to preference

musou1500 avatar Jun 24 '19 13:06 musou1500

+1 for considering Linux package managers. /usr/lib, or /usr/share should be fine.

ghost avatar Jun 24 '19 15:06 ghost

A bit off, but I made a asdf version manager plugin for V, and I seemed to achieve multiple v installs by recreating symlinks.

$ asdf plugin-add v https://github.com/ndac-todoroki/asdf-v.git
$ asdf install v master
$ asdf install v ref:c32c02b
$ asdf global v master

$ v
V 0.1.0

$ asdf global v ref:c32c02b

$ v
V 0.0.12

This still requires ~/code/v to be untouched by the user. (The plugin simply does rm ~/code/v and ln -s ~/.asdf/installs/v/{version}/v ~/code/v everytime v is called) If the installation directory could be given as a argument as compile options, I think these kind of things could be implemented more cleaner.

ndac-todoroki avatar Jun 24 '19 18:06 ndac-todoroki