From 8f15af6adc043d596614ffe7718221359418ff0d Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Sun, 29 Nov 2020 13:53:49 +0000 Subject: [PATCH] pref: add -m32, -m64 command-line options (#7011) --- cmd/v/help/build-c.txt | 3 +++ vlib/v/pref/pref.v | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/cmd/v/help/build-c.txt b/cmd/v/help/build-c.txt index d04e1e492e..94a103efb8 100644 --- a/cmd/v/help/build-c.txt +++ b/cmd/v/help/build-c.txt @@ -44,6 +44,9 @@ These build flags are enabled on `build` and `run` as long as the backend is set List of OS supported by V: `linux`, `windows`, `ios`, `mac`, `freebsd`, `openbsd`, `netbsd`, `dragonfly`, `solaris`, `android` and `haiku`. + -m32, -m64 + Specify whether 32-bit or 64-bit machine code is generated. + -sanitize Pass flags related to sanitization to the C compiler. diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index 02288e3c3c..6f128de65a 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -85,6 +85,7 @@ pub mut: // For example, passing -cflags -Os will cause the C compiler to optimize the generated binaries for size. // You could pass several -cflags XXX arguments. They will be merged with each other. // You can also quote several options at the same time: -cflags '-Os -fno-inline-small-functions'. + m64 bool // true = generate 64-bit code, defaults to x64 ccompiler string // the name of the C compiler used ccompiler_type CompilerType // the type of the C compiler used third_party_option string @@ -138,6 +139,9 @@ pub mut: pub fn parse_args(args []string) (&Preferences, string) { mut res := &Preferences{} + $if x64 { + res.m64 = true // follow V model by default + } mut command := '' mut command_pos := 0 // for i, arg in args { @@ -239,6 +243,10 @@ pub fn parse_args(args []string) (&Preferences, string) { '-color' { res.use_color = .always } + '-m32', '-m64' { + res.m64 = arg[2] == `6` + res.cflags += ' $arg' + } '-nocolor' { res.use_color = .never }