Vmob is CLI tool that cross compiles V written module for use in iOS/Android architectures through C layer. Android is still not supported, please refer to support-android
Vmob is used to cross-compile originally written V modules(lib) into iOS-compatible .a files. Static library can be compiled with enabled-bitcode
, unlike Rust. For full explonation how vmob works read this document.
Please note that vmob
is in a really early stage of development.
Vmob is a pretty simple CLI app that works by translating the V module to raw C code. C file is then cross-compiled with gcc
to supported architectures.
Supported architectures:
- iOS
- iPhone arm64
- iOS Simulator (x86_64)
- Android
- Android aarch64-linux-android
- Android armv7-linux-androideabi
- Android i686-linux-android
- Android x86_64-linux-android
Android is not supported yet, we are working to support it see support-android to contribute
- OS: MacOS (because it relies on lipo and otool checks)
- Tools: Installed Xcode
The easiest way is to just download binary
You can build vmob from source using V.
git clone https://github.com/nedimf/vmob.git
v vmob.v
- Run:
./vmob
Step by step guide
- Write your V module
Be sure to use [export: ] followed by module name
module vex
import math
[export: vex_absolute_value]
pub fn vex_absolute_value(a f64) f64{
return math.abs(a)
}
fn init(){
println("Vex module has been called")
}
- Build static library (.a file) targeting iPhone (arm64)
./vmob apple-ios-iphone -s false path/to/module
- Build static library (.a file) targeting iOS Simulator (x86_64)
./vmob apple-ios-simulator -s false path/to/module
- Combine two targets into universal target
./vmob combine -o modulename-ios path/to/module-arm64.a path/to/module-x86_64.a
- Generate header file that you will use as bridge between your library and Xcode
./vmob header-gen -a arm64 -mp vex path/to/module
- Open Xcode
- Create new folder called
your-ios-module-name
- Drag and drop your universal
modulename-ios.a
and.h
file - New File -> C -> Enable Bridging Header
- add line
#include "modulename_header.h
file
- add line
- Call method from your Swift code
override func viewDidLoad() {
super.viewDidLoad()
println(vex_absolute_value(-1)) // 1
}
Have in mind this all this be automated in Xcode build script
Not yet supported
Fast version:
- locate v written module
Build static library (.a) for arm64
./vmob apple-ios-iphone -s false lib/module/module
Build static library (.a) for x86_64 simulator
./vmob apple-ios-iphone -s false lib/module/module
Combine two different architectures arm64
& x86_64
./vmob combine -o module-ios lib/module/module-arm64.a lib/module/module-x86-64.a
Xcode part:
Insert .a file into your Xcode project, and don't forget to add a bridging header. Vmob can generate it for you.
./vmob header-gen -a arm64 lib/module/module
import made module into your Xcode project, configure bridge header file and call V module from your iOS app
For a full tutorial on how to use vmob
look at this sample project or click down on drop down menu.
Usage: vmob [flags] [commands]
Vmob is CLI tool that cross-compiles V module for use in iOS/Android architectures through C layer.
Flags:
-help Prints help information.
-version Prints version information.
Commands:
apple-ios-iphone Build V module into arm64 static librvary
apple-ios-simulator Build V module into x86_64 static library
combine Combine two architectures into one by making it universal
header-gen Generate header.h to be inserted in Xcode project
help Prints help information.
version Prints version information.
- @nedimf If you would like to support my work: