mirror of
https://github.com/gechandesu/v-cross-compilation-example.git
synced 2026-01-02 14:39:35 +03:00
make.vsh, readme: minor fixes
This commit is contained in:
@@ -29,7 +29,7 @@ Build:
|
|||||||
docker build . -t vlang-cross:latest-trixie
|
docker build . -t vlang-cross:latest-trixie
|
||||||
```
|
```
|
||||||
|
|
||||||
The container image is large (a little over 2GiB) due to the number of libraries
|
The container image is large (almost 3GiB) due to the number of libraries
|
||||||
required for cross-compilation. The size could actually be reduced, but that's
|
required for cross-compilation. The size could actually be reduced, but that's
|
||||||
what Debian provides by default in the `crossbuild-essential-*` packages. For
|
what Debian provides by default in the `crossbuild-essential-*` packages. For
|
||||||
the same reason, building the image isn't very fast (up to ~3 minutes for me).
|
the same reason, building the image isn't very fast (up to ~3 minutes for me).
|
||||||
|
|||||||
46
make.vsh
46
make.vsh
@@ -11,7 +11,7 @@ const program_version = os.getenv_opt('BUILD_PROG_VERSION') or { vmod_version()
|
|||||||
const program_entrypoint = os.getenv_opt('BUILD_PROG_ENTRYPOINT') or { '.' }
|
const program_entrypoint = os.getenv_opt('BUILD_PROG_ENTRYPOINT') or { '.' }
|
||||||
const output_dir = os.abs_path(os.norm_path(os.getenv_opt('BUILD_OUTPUT_DIR') or { 'release' }))
|
const output_dir = os.abs_path(os.norm_path(os.getenv_opt('BUILD_OUTPUT_DIR') or { 'release' }))
|
||||||
const skip_targets = os.getenv('BUILD_SKIP_TARGETS')
|
const skip_targets = os.getenv('BUILD_SKIP_TARGETS')
|
||||||
const common_vflags = os.getenv_opt('BUILD_COMMON_VFLAGS') or { '-prod,-cross' }
|
const common_vflags = os.getenv_opt('BUILD_COMMON_VFLAGS') or { '-prod' }
|
||||||
const common_cflags = os.getenv_opt('BUILD_COMMON_CFLAGS') or { '-static' }
|
const common_cflags = os.getenv_opt('BUILD_COMMON_CFLAGS') or { '-static' }
|
||||||
const debug = os.getenv('DEBUG')
|
const debug = os.getenv('DEBUG')
|
||||||
const vexe = @VEXE
|
const vexe = @VEXE
|
||||||
@@ -60,6 +60,11 @@ const vexe = @VEXE
|
|||||||
is the same as Linux `sha256sum` utility output. Is true by default.
|
is the same as Linux `sha256sum` utility output. Is true by default.
|
||||||
|
|
||||||
See also Target sttruct definition in bottom of this file.
|
See also Target sttruct definition in bottom of this file.
|
||||||
|
|
||||||
|
V'S SPECIAL ENVIRONMENT VARIABLES
|
||||||
|
|
||||||
|
VCROSS_COMPILER_NAME See vcross_compiler_name() in v.pref module.
|
||||||
|
VCROSS_LINKER_NAME See vcross_linker_name() in v.pref module.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const build_targets = [
|
const build_targets = [
|
||||||
@@ -95,7 +100,8 @@ const build_targets = [
|
|||||||
},
|
},
|
||||||
Target{
|
Target{
|
||||||
// FreeBSD build for now is dynamically linked even if -cflags -static is passed.
|
// FreeBSD build for now is dynamically linked even if -cflags -static is passed.
|
||||||
// Also V forces the use of clang here, so -cc value doesn't matter.
|
// Also V forces the use of clang here (unless VCROSS_COMPILER_NAME envvar is set),
|
||||||
|
// so -cc value doesn't matter.
|
||||||
name: 'freebsd-amd64'
|
name: 'freebsd-amd64'
|
||||||
cc: 'clang'
|
cc: 'clang'
|
||||||
vflags: ['-os', 'freebsd']
|
vflags: ['-os', 'freebsd']
|
||||||
@@ -130,15 +136,11 @@ fn main() {
|
|||||||
println(help_text)
|
println(help_text)
|
||||||
exit(0)
|
exit(0)
|
||||||
}
|
}
|
||||||
mut context := build.context(default: 'release')
|
mut context := build.context(default: 'all')
|
||||||
mut targets := []string{}
|
mut targets := []string{}
|
||||||
for build_target in build_targets {
|
for build_target in build_targets {
|
||||||
if build_target.disabled {
|
|
||||||
printdbg('Build target ${build_target.name} is disabled in build script')
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
targets << build_target.name
|
targets << build_target.name
|
||||||
context.artifact(
|
context.task(
|
||||||
name: build_target.name
|
name: build_target.name
|
||||||
help: 'Make release build for ${build_target.name} target'
|
help: 'Make release build for ${build_target.name} target'
|
||||||
run: fn [build_target] (t build.Task) ! {
|
run: fn [build_target] (t build.Task) ! {
|
||||||
@@ -151,7 +153,7 @@ fn main() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
context.task(
|
context.task(
|
||||||
name: 'release'
|
name: 'all'
|
||||||
help: 'Make release builds for all target systems'
|
help: 'Make release builds for all target systems'
|
||||||
depends: targets
|
depends: targets
|
||||||
run: |self| true
|
run: |self| true
|
||||||
@@ -160,7 +162,6 @@ fn main() {
|
|||||||
name: 'clean'
|
name: 'clean'
|
||||||
help: 'Cleanup the output dir (${output_dir})'
|
help: 'Cleanup the output dir (${output_dir})'
|
||||||
run: |self| cleanup()!
|
run: |self| cleanup()!
|
||||||
should_run: |self| true
|
|
||||||
)
|
)
|
||||||
context.run()
|
context.run()
|
||||||
}
|
}
|
||||||
@@ -208,7 +209,7 @@ fn make_build(build_target Target) ! {
|
|||||||
vargs << ['-o', artifact]
|
vargs << ['-o', artifact]
|
||||||
vargs << program_entrypoint
|
vargs << program_entrypoint
|
||||||
|
|
||||||
execute_command(vexe, vargs)!
|
execute_command(vexe, vargs, env: build_target.env)!
|
||||||
|
|
||||||
if build_target.calculate_sha256 {
|
if build_target.calculate_sha256 {
|
||||||
sha256sum_file := artifact + '.sha256'
|
sha256sum_file := artifact + '.sha256'
|
||||||
@@ -222,15 +223,16 @@ fn make_build(build_target Target) ! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn cleanup() ! {
|
fn cleanup() ! {
|
||||||
path := output_dir
|
printdbg('Try to delete ${output_dir} recursively...')
|
||||||
if os.is_dir(path) {
|
os.rmdir_all(output_dir) or {
|
||||||
printdbg('Deleting the ${path} dir recursively...')
|
if err.code() == 2 {
|
||||||
os.rmdir_all(path)!
|
printdbg('${output_dir} does not exists')
|
||||||
printdbg('${path} is deleted')
|
|
||||||
} else {
|
} else {
|
||||||
printdbg('${path} does not exists or is not directory')
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
printdbg('Cleanup done')
|
||||||
|
}
|
||||||
|
|
||||||
// Helper functions
|
// Helper functions
|
||||||
|
|
||||||
@@ -259,11 +261,17 @@ fn is_command_present(cmd string) !bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn execute_command(executable string, args []string) ! {
|
@[params]
|
||||||
|
struct CommandOptions {
|
||||||
|
env map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
fn execute_command(executable string, args []string, opts CommandOptions) ! {
|
||||||
path := os.find_abs_path_of_executable(executable) or { os.norm_path(executable) }
|
path := os.find_abs_path_of_executable(executable) or { os.norm_path(executable) }
|
||||||
printdbg("Run '${path}' with arguments: ${args}")
|
printdbg("Run '${path}' with arguments: ${args}")
|
||||||
mut proc := os.new_process(path)
|
mut proc := os.new_process(path)
|
||||||
proc.set_args(args)
|
proc.set_args(args)
|
||||||
|
proc.set_environment(opts.env)
|
||||||
proc.set_work_folder(os.getwd())
|
proc.set_work_folder(os.getwd())
|
||||||
proc.run()
|
proc.run()
|
||||||
proc.wait()
|
proc.wait()
|
||||||
@@ -289,8 +297,8 @@ struct Target {
|
|||||||
cflags []string
|
cflags []string
|
||||||
ldflags []string
|
ldflags []string
|
||||||
file_ext string
|
file_ext string
|
||||||
|
env map[string]string
|
||||||
|
|
||||||
disabled bool
|
|
||||||
common_vflags bool = true
|
common_vflags bool = true
|
||||||
common_cflags bool = true
|
common_cflags bool = true
|
||||||
calculate_sha256 bool = true
|
calculate_sha256 bool = true
|
||||||
|
|||||||
Reference in New Issue
Block a user