cdylib: Clap not accepting arguments on Ubuntu (still works on Windows10)
caesarchad opened this issue · 5 comments
codes in cdlylib is an sample to test cross calling of rust/go
System information
bus version: pre mainnet launch
OS & Version:
Windows 10 /Ubuntu 18.04
Commit hash :09126b14cd401e3e07053a3a97f8facc90ec8112
hardware :
Expected behaviour
run main -xiudre, should print
Hello Hello Dummy!
This is a simple CLI created by Clap
error: Found argument '-s' which wasn't expected, or isn't valid in this context
USAGE:
main.exe [OPTIONS]
For more information try --help
Actual behaviour
on Windows10 works,
on Ubuntu 18.04, print nothing
Steps to reproduce the behaviour
cd cdylib
python build.py
cd lib
main -xurhfe
Backtrace
[backtrace]
title: 'cdylib: Clap not accepting argument on Ubuntu (still works on Windows10)'
labels: bug
assignees: caesarchad,ben
need to investigate reason not working on ubuntu 18.04?
possible workaround:
-
use urfave cli to parse the argument, then send the parameters to rust code
-
use another cli parser to replace Clap.
-
tweek the env and go build (possible different go compiler)
possible workaround:
created a new branch fixissue85
1 - modify sources accept argument from go side.
2 - string passed to rust code like
#[no_mangle]
pub extern "C" fn hello(parm1: *const libc::c_char, parm2: *const libc::c_char) {
let buf_parm1 = unsafe { CStr::from_ptr(parm1).to_bytes() };
let str_parm1 = String::from_utf8(buf_parm1.to_vec()).unwrap();
if !str_parm1.is_empty(){
//pass the value from str_parm1}else{
//pass the default value}
}
3 - modify c header file
void void hello(char *parm1, char *parm2);
4 - modfiy go file
func AGoFunction(parm1 string, parm2 string ){
cStr_1 := C.CString(parm1)
cStr_2 := C.CString(parm2)
C.hello(cStr_1,cStr_2)
}
possible workaround
1 - replace gccgo/gc with llgo
building in progress...
2 - use gccgo
as for commit adc878c,
this issue has been fixed: implementing urfave to accept arguments
Close