diff --git a/cmd/v/help/build.txt b/cmd/v/help/build.txt index cd66a8d6f5..69b104fafa 100644 --- a/cmd/v/help/build.txt +++ b/cmd/v/help/build.txt @@ -34,15 +34,16 @@ If you have not set it, a suitable platform specific folder (like /tmp) will be NB: the build flags are shared with the run command too: -b , -backend - Specify the backend to use while building the executable. + Specifies the backend that will be used for building the executable. Current list of supported backends: - * `c` (default) - V outputs C source code which is passed to a C compiler to be compiled. - * `interpret` - Same as `v interpret` to run the V program + * `c` (default) - V outputs C source code, which is then passed to a C compiler. + * `go` - V outputs Go source code, which is then passed to a Go compiler. + * `interpret` - V will interpret the V program directly, instead of compiling it first. Same as `v interpret file.v`. * `js` - V outputs JS source code which can be passed to NodeJS to be ran. * `js_browser` - V outputs JS source code ready for the browser. * `js_node` - V outputs JS source code to run with nodejs. * `js_freestanding` - V outputs JS source code with no hard runtime dependency. - * `native` - V outputs native executable (see -arch x64|arm64 and -os linux|macos) (EXPERIMENTAL). + * `native` - V outputs a native executable directly (see -arch x64|arm64 and -os linux|macos) (EXPERIMENTAL). -d [=], -define [=] Define the provided flag. diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index 91dc3df8df..206a1781fa 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -47,12 +47,12 @@ pub enum ColorOutput { pub enum Backend { c // The (default) C backend + golang // Go backend + interpret // Interpret the ast js_node // The JavaScript NodeJS backend js_browser // The JavaScript browser backend js_freestanding // The JavaScript freestanding backend native // The Native backend - interpret // Interpret the ast - golang // Go backend } pub fn (b Backend) is_js() bool { @@ -687,7 +687,11 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin '-b', '-backend' { sbackend := cmdline.option(current_args, arg, 'c') res.build_options << '${arg} ${sbackend}' - b := backend_from_string(sbackend) or { continue } + b := backend_from_string(sbackend) or { + eprintln('Unknown V backend: ${sbackend}') + eprintln('Valid -backend choices are: c, go, interpret, js, js_node, js_browser, js_freestanding, native') + exit(1) + } if b.is_js() { res.output_cross_c = true } @@ -960,15 +964,17 @@ fn is_source_file(path string) bool { } pub fn backend_from_string(s string) !Backend { + // TODO: unify the "different js backend" options into a single `-b js` + // + a separate option, to choose the wanted JS output. match s { 'c' { return .c } - 'js' { return .js_node } 'go' { return .golang } + 'interpret' { return .interpret } + 'js' { return .js_node } 'js_node' { return .js_node } 'js_browser' { return .js_browser } 'js_freestanding' { return .js_freestanding } 'native' { return .native } - 'interpret' { return .interpret } else { return error('Unknown backend type ${s}') } } }