千呼万唤始出来:V语言终于开源上线啦

  V语言中文网  |   3720 |    2019-06-23 21:06:00

V语言正式开源啦!

经过漫长的等待,Vlang终于开源,当前开源的版本是0.0.12。

目前还没有提供已经编译好的二进制版本供大家下载,只能通过源码编译的方式(其实作者在6月18号短暂上线了一会macos平台的vlang二进制文件?)。

Vlang源码编译地址及编译方法可访问:https://github.com/vlang/v#installing-v-from-source

现摘抄编译步骤如下(P.S:如果有的同学https://vlang.io/v.c 访问超时,可以替换为https://assets.v-lang.cn/downloads/v.c):

Linux and macOS

mkdir ~/code && cd ~/code  # ~/code directory has to be used (it's a temporary limitation)
git clone https://github.com/vlang/v
cd v/compiler
make

# Or build without make:
wget https://vlang.io/v.c # Download the V compiler's source translated to C // 下载C实现的V编译器源码
cc -std=c11 -w -o vc v.c  # Build it with Clang or GCC  // 用Clang编译C实现的V编译器
./vc -o v . && rm vc      # Use the resulting V binary to build V from V source, delete the old compiler // 用C实现的V编译器编译V实现的V编译器

That's it! Now you have a V executable at ~/code/v/compiler/v.

Bootstrap the compiler to make sure it works:

./v -o v .   # 用V实现的V编译器编译V编译器源码,所谓的语言自举

You can create a symlink so that it's globally available:

sudo ln -s ~/code/v/compiler/v /usr/local/bin/v

Windows

V works great on Windows Subsystem for Linux. The instructions are the same as above.

If you want to build v.exe on Windows without WSL, you will need Visual Studio. Microsoft doesn't make it easy for developers. Mingw-w64 could suffice, but if you plan to develop UI and graphical apps, VS is your only option.

V temporarily can't be compiled with Visual Studio. This will be fixed asap.

Testing

$ v

V 0.0.12
Use Ctrl-D to exit

>>> println('hello world')
hello world
>>>

Now if you want, you can start tinkering with the compiler. If you introduce a breaking change and rebuild V, you will no longer be able to use V to build itself. So it's a good idea to make a backup copy of a working compiler executable.

Running the examples

v hello_world.v && ./hello_world # or simply
v run hello_world.v              # This builds the program and runs it right away

v word_counter.v && ./word_counter cinderella.txt
v news_fetcher.v && ./news_fetcher
v tetris.v && ./tetris

In order to build Tetris and anything else using the graphics module, you will need to install glfw and freetype.

If you plan to use the http package, you also need to install libcurl.

glfw and libcurl dependencies will be removed soon.

Ubuntu:
sudo apt install glfw libglfw3-dev libfreetype6-dev libcurl3-dev

macOS:
brew install glfw freetype curl

登陆后可发表评论


热门评论

暂无评论


最新评论

暂无评论