diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 13c4c8beab..a0912f3cd8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -153,6 +153,7 @@ jobs: brew install postgresql brew install glfw ## brew install sdl2 sdl2_ttf sdl2_mixer sdl2_image + brew install mingw-w64 export LIBRARY_PATH="$LIBRARY_PATH:/usr/local/opt/openssl/lib/" - name: Build V run: make -j4 && ./v -cg -cflags -Werror -o v cmd/v @@ -189,7 +190,13 @@ jobs: run: | ./v doctor - name: Cross-compilation to Linux - run: ./v -os linux cmd/v + run: | + ./v -os linux cmd/v + # TODO: fix this: ./v -os linux examples/2048/2048.v + - name: Cross-compilation to Windows + run: | + ./v -os windows cmd/v + ./v -os windows examples/2048/2048.v # - name: Test vsh # run: ./v examples/v_script.vsh - name: Test ved @@ -576,6 +583,10 @@ jobs: ./v -os windows examples/hello_world.v ls -lart examples/hello_world.exe wine examples/hello_world.exe + - name: 2048.v can be cross compiled to 2048.exe + run: | + ./v -os windows examples/2048/2048.v + ls -lart examples/2048/2048.exe ubuntu-c-plus-plus: runs-on: ubuntu-18.04 diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index 51ec4cb0b2..5e7b4b1296 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -703,6 +703,9 @@ fn (mut v Builder) cc() { } fn (mut b Builder) cc_linux_cross() { + b.setup_ccompiler_options(b.pref.ccompiler) + b.build_thirdparty_obj_files() + b.setup_output_name() parent_dir := os.vmodules_dir() if !os.exists(parent_dir) { os.mkdir(parent_dir) @@ -763,6 +766,9 @@ fn (mut b Builder) cc_linux_cross() { fn (mut c Builder) cc_windows_cross() { println('Cross compiling for Windows...') + c.setup_ccompiler_options(c.pref.ccompiler) + c.build_thirdparty_obj_files() + c.setup_output_name() if !c.pref.out_name.ends_with('.exe') { c.pref.out_name += '.exe' } @@ -865,12 +871,6 @@ fn (mut v Builder) build_thirdparty_obj_files() { fn (mut v Builder) build_thirdparty_obj_file(path string, moduleflags []cflag.CFlag) { obj_path := os.real_path(path) - if v.pref.os == .windows { - // Cross compiling for Windows - $if !windows { - v.pref.ccompiler = mingw_cc - } - } cfile := '${obj_path[..obj_path.len - 2]}.c' btarget := moduleflags.c_options_before_target() atarget := moduleflags.c_options_after_target() diff --git a/vlib/v/parser/comptime.v b/vlib/v/parser/comptime.v index af1dec5e85..507c3423aa 100644 --- a/vlib/v/parser/comptime.v +++ b/vlib/v/parser/comptime.v @@ -10,13 +10,6 @@ import v.table import v.token import vweb.tmpl -// #flag darwin -I. -const ( - supported_platforms = ['windows', 'macos', 'darwin', 'linux', 'freebsd', 'openbsd', 'netbsd', - 'dragonfly', 'android', 'js', 'solaris', 'haiku', 'linux_or_macos'] - supported_ccompilers = ['tinyc', 'clang', 'mingw', 'msvc', 'gcc'] -) - // // #include, #flag, #v fn (mut p Parser) hash() ast.HashStmt { mut pos := p.prev_tok.position() diff --git a/vlib/v/pref/default.v b/vlib/v/pref/default.v index baca496560..96ef123f2c 100644 --- a/vlib/v/pref/default.v +++ b/vlib/v/pref/default.v @@ -68,6 +68,7 @@ pub fn (mut p Preferences) fill_with_defaults() { if p.ccompiler == '' { p.ccompiler = default_c_compiler() } + p.find_cc_if_cross_compiling() p.ccompiler_type = cc_from_string(p.ccompiler) p.is_test = p.path.ends_with('_test.v') p.is_vsh = p.path.ends_with('.vsh') @@ -98,6 +99,21 @@ pub fn (mut p Preferences) fill_with_defaults() { // p.use_cache = os.user_os() != 'windows' } +fn (mut p Preferences) find_cc_if_cross_compiling() { + if p.os == .windows { + $if !windows { + // Cross compiling to Windows + p.ccompiler = 'x86_64-w64-mingw32-gcc' + } + } + if p.os == .linux { + $if !linux { + // Cross compiling to Linux + p.ccompiler = 'clang' + } + } +} + fn (mut p Preferences) try_to_use_tcc_by_default() { if p.ccompiler == 'tcc' { p.ccompiler = default_tcc_compiler()