diff --git a/.github/workflows/linux_ci.yml b/.github/workflows/linux_ci.yml index ee657f815e6418..fb6862e18d6971 100644 --- a/.github/workflows/linux_ci.yml +++ b/.github/workflows/linux_ci.yml @@ -32,85 +32,53 @@ jobs: - name: Build v run: make -j4 && ./v symlink - name: Build v with -prealloc - run: | - v -d debug_malloc -d debug_realloc -o v cmd/v - v -cg -cstrict -o v cmd/v - # Test v -realloc arena allocation - v -o vrealloc -prealloc cmd/v && ./vrealloc -o v3 cmd/v && ./v3 -o v4 cmd/v + run: v run ci/linux_ci.vsh build_v_with_prealloc - name: All code is formatted - run: v test-cleancode + run: v run ci/linux_ci.vsh all_code_is_formatted_tcc - name: Install dependencies for examples and tools - run: | - v retry -- sudo apt update - v retry -- sudo apt install --quiet -y libssl-dev sqlite3 libsqlite3-dev valgrind - v retry -- sudo apt install --quiet -y libfreetype6-dev libxi-dev libxcursor-dev libgl-dev libasound2-dev - # The following is needed for examples/wkhtmltopdf.v - v retry -- wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb - v retry -- sudo apt install --quiet -y xfonts-75dpi xfonts-base - v retry -- sudo apt install --quiet -y expect - v retry -- sudo dpkg -i wkhtmltox_0.12.6-1.focal_amd64.deb + run: v run ci/linux_ci.vsh install_dependencies_for_examples_and_tools_tcc - name: Test v->c - run: | - thirdparty/tcc/tcc.exe -version - v -cg -o v cmd/v # Make sure vtcc can build itself twice - # v test-all + run: v run ci/linux_ci.vsh test_v_to_c_tcc - name: v self compilation - run: v -o v2 cmd/v && ./v2 -o v3 cmd/v && ./v3 -o v4 cmd/v + run: v run ci/linux_ci.vsh v_self_compilation_tcc - name: v self compilation with -skip-unused - run: v -skip-unused -o v2 cmd/v && ./v2 -skip-unused -o v3 cmd/v && ./v3 -skip-unused -o v4 cmd/v + run: v run ci/linux_ci.vsh v_self_compilation_skip_unused_tcc - name: Test vlib modules with -skip-unused - run: v -skip-unused test vlib/builtin/ vlib/math vlib/flag/ vlib/os/ vlib/strconv/ + run: v run ci/linux_ci.vsh test_vlib_skip_unused_tcc - name: v doctor - run: v doctor + run: v run ci/linux_ci.vsh v_doctor_tcc - name: Verify `v test` works - run: | - echo $VFLAGS - v cmd/tools/test_if_v_test_system_works.v - ./cmd/tools/test_if_v_test_system_works + run: v run ci/linux_ci.vsh verify_v_test_works_tcc - name: Test pure V math module - run: v -exclude @vlib/math/*.c.v test vlib/math/ + run: v run ci/linux_ci.vsh test_pure_v_math_module_tcc - name: Self tests - run: v test-self vlib - # - name: Self tests (-cstrict) - # run: V_CI_CSTRICT=1 v -cstrict test-self vlib + run: v run ci/linux_ci.vsh self_tests_tcc - name: Build examples - run: v -N -W build-examples + run: v run ci/linux_ci.vsh build_examples_tcc - name: Run the submodule example, using a relative path - run: v -W run examples/submodule + run: v run ci/linux_ci.vsh run_submodule_example_tcc - name: Build v tools - run: v -N -W build-tools + run: v run ci/linux_ci.vsh build_tools_tcc - name: Build v binaries - run: v -N -W build-vbinaries + run: v run ci/linux_ci.vsh build_vbinaries_tcc - name: Build benches - run: v should-compile-all vlib/v/tests/bench/ + run: v run ci/linux_ci.vsh build_benches_tcc - name: Run a VSH script - run: v run examples/v_script.vsh + run: v run ci/linux_ci.vsh run_vsh_script_tcc - name: Test v tutorials - run: v tutorials/building_a_simple_web_blog_with_vweb/code/blog + run: v run ci/linux_ci.vsh test_v_tutorials_tcc - name: Build cmd/tools/fast - run: cd cmd/tools/fast && v fast.v && ./fast + run: v run ci/linux_ci.vsh build_fast_tcc - name: V self compilation with -usecache - run: | - unset VFLAGS - v -usecache examples/hello_world.v && examples/hello_world - v -o v2 -usecache cmd/v - ./v2 -o v3 -usecache cmd/v - ./v3 version - ./v3 -o tetris -usecache examples/tetris/tetris.v + run: v run ci/linux_ci.vsh v_self_compilation_usecache_tcc - name: Test password input - run: v test examples/password/ + run: v run ci/linux_ci.vsh test_password_input_tcc - name: Test readline - run: v test examples/readline/ + run: v run ci/linux_ci.vsh test_readline_tcc - name: Test leak detector - run: | - v -gc boehm_leak -o testcase_leak vlib/v/tests/testcase_leak.vv - ./testcase_leak 2>leaks.txt - grep "Found 1 leaked object" leaks.txt && grep -P ", sz=\s?1000," leaks.txt + run: v run ci/linux_ci.vsh test_leak_detector_tcc - name: Test leak detector not being active for normal compile - run: | - v -o testcase_leak vlib/v/tests/testcase_leak.vv - ./testcase_leak 2>leaks.txt - [ "$(stat -c %s leaks.txt)" = "0" ] + run: v run ci/linux_ci.vsh test_leak_detector_not_active_tcc gcc: runs-on: ubuntu-20.04 @@ -120,107 +88,51 @@ jobs: - name: Build V run: make -j4 && ./v symlink - name: All code is formatted - run: v test-cleancode + run: v run ci/linux_ci.vsh all_code_is_formatted_gcc - name: Install dependencies for examples and tools - run: | - v retry -- sudo apt update - v retry -- sudo apt install --quiet -y postgresql libpq-dev libssl-dev sqlite3 libsqlite3-dev valgrind - v retry -- sudo apt install --quiet -y libfreetype6-dev libxi-dev libxcursor-dev libgl-dev libasound2-dev + run: v run ci/linux_ci.vsh install_dependencies_for_examples_and_tools_gcc - name: Recompile V with -cstrict and gcc - run: v -cc gcc -cg -cstrict -o v cmd/v + run: v run ci/linux_ci.vsh recompile_v_with_cstrict_gcc - name: Valgrind v.c - run: valgrind --error-exitcode=1 v -o v.c cmd/v + run: v run ci/linux_ci.vsh valgrind_v_c_gcc - name: Run sanitizers - run: | - v -o v2 cmd/v -cflags -fsanitize=thread - v -o v3 cmd/v -cflags "-fsanitize=undefined -fno-sanitize=alignment" - UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./v2 -o v.c cmd/v - UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./v3 -o v.c cmd/v - # - name: Test V - # run: v test-all - # - name: Test v binaries - # run: v -N -W build-vbinaries - # - name: Test v->js - # run: v -o hi.js examples/js_hello_world.v && node hi.js - # - name: Build Vorum - # run: v retry -- git clone --depth 1 https://github.com/vlang/vorum && cd vorum && v . && cd .. - - name: Freestanding - run: v -freestanding run vlib/os/bare/bare_example_linux.v - - name: V self compilation - run: v -o v2 cmd/v && ./v2 -o v3 cmd/v && ./v3 -o v4 cmd/v - - name: V self compilation with -usecache - run: | - unset VFLAGS - v -usecache examples/hello_world.v && examples/hello_world - v -o v2 -usecache cmd/v - ./v2 -o v3 -usecache cmd/v - ./v3 version - ./v3 -o tetris -usecache examples/tetris/tetris.v + run: v run ci/linux_ci.vsh run_sanitizers_gcc + - name: v self compilation + run: v run ci/linux_ci.vsh v_self_compilation_gcc + - name: v self compilation with -usecache + run: v run ci/linux_ci.vsh v_self_compilation_usecache_gcc - name: Verify `v test` works - run: | - echo $VFLAGS - v cmd/tools/test_if_v_test_system_works.v - ./cmd/tools/test_if_v_test_system_works + run: v run ci/linux_ci.vsh verify_v_test_works_gcc - name: Test pure V math module - run: v -exclude @vlib/math/*.c.v test vlib/math/ + run: v run ci/linux_ci.vsh test_pure_v_math_module_gcc - name: Self tests - run: v test-self vlib + run: v run ci/linux_ci.vsh self_tests_gcc - name: Self tests (-prod) - run: v -o vprod -prod cmd/v && ./vprod test-self vlib + run: v run ci/linux_ci.vsh self_tests_prod_gcc - name: Self tests (-cstrict) - run: VTEST_JUST_ESSENTIAL=1 V_CI_CSTRICT=1 v -cc gcc -cstrict test-self vlib + run: v run ci/linux_ci.vsh self_tests_cstrict_gcc - name: Build examples - run: v -N -W build-examples + run: v run ci/linux_ci.vsh build_examples_gcc - name: Build tetris with -autofree - run: v -autofree -o tetris examples/tetris/tetris.v + run: v run ci/linux_ci.vsh build_tetris_autofree_gcc - name: Build blog tutorial with -autofree - run: v -autofree -o blog tutorials/building_a_simple_web_blog_with_vweb/code/blog + run: v run ci/linux_ci.vsh build_blog_autofree_gcc - name: Build option_test.c.v with -autofree - run: v -autofree vlib/v/tests/options/option_test.c.v + run: v run ci/linux_ci.vsh build_option_test_autofree_gcc - name: V self compilation with -parallel-cc - run: | - v -o v2 -parallel-cc cmd/v + run: v run ci/linux_ci.vsh v_self_compilation_parallel_cc_gcc - name: Test vlib modules with -skip-unused - run: v -skip-unused test vlib/builtin/ vlib/math vlib/flag/ vlib/os/ vlib/strconv/ + run: v run ci/linux_ci.vsh test_vlib_skip_unused_gcc - name: Build modules - run: | - v build-module vlib/os - v build-module vlib/builtin - v build-module vlib/strconv - v build-module vlib/time - v build-module vlib/term - v build-module vlib/math - v build-module vlib/strings - v build-module vlib/v/token - v build-module vlib/v/ast - v build-module vlib/v/parser - v build-module vlib/v/gen/c - v build-module vlib/v/depgraph - v build-module vlib/os/cmdline + run: v run ci/linux_ci.vsh build_modules_gcc - name: native machine code generation - run: | - v -o vprod -prod cmd/v - cd cmd/tools - echo "Generating a 1m line V file..." - ../../vprod gen1m.v - ./gen1m > 1m.v - echo "Building it..." - ../../vprod -backend native -o 1m 1m.v - echo "Running it..." - ./1m - ls + run: v run ci/linux_ci.vsh native_machine_code_generation_gcc - name: compile vdoctor.v with -skip-unused and -prod - run: v -showcc -skip-unused -cc gcc -prod cmd/tools/vdoctor.v + run: v run ci/linux_ci.vsh compile_vdoctor_skip_unused_prod_gcc - name: compile vup.v with -skip-unused and -prod - run: v -showcc -skip-unused -cc gcc -prod cmd/tools/vup.v - - # - run: cd examples/native && v -native hello_world.v && ./hello_world - # - name: Coveralls GitHub Action - # uses: coverallsapp/github-action@v1.0.1 - # with: - # github-token: ${{ secrets.GITHUB_TOKEN }} + run: v run ci/linux_ci.vsh compile_vup_skip_unused_prod_gcc - name: Test vlib modules with -skip-unused - run: v -skip-unused test vlib/builtin/ vlib/math vlib/flag/ vlib/os/ vlib/strconv/ + run: v run ci/linux_ci.vsh test_vlib_skip_unused_gcc clang: runs-on: ubuntu-20.04 @@ -232,112 +144,37 @@ jobs: - name: Build V run: make -j4 && ./v symlink - name: All code is formatted - run: v test-cleancode + run: v run ci/linux_ci.vsh all_code_is_formatted_clang - name: Install dependencies for examples and tools - run: | - v retry -- sudo apt update - v retry -- sudo apt install --quiet -y postgresql libpq-dev libssl-dev sqlite3 libsqlite3-dev valgrind - v retry -- sudo apt install --quiet -y libfreetype6-dev libxi-dev libxcursor-dev libgl-dev libasound2-dev - v retry -- sudo apt install --quiet -y clang + run: v run ci/linux_ci.vsh install_dependencies_for_examples_and_tools_clang - name: Recompile V with -cstrict and clang - run: v -cc clang -cg -cstrict -o v cmd/v + run: v run ci/linux_ci.vsh recompile_v_with_cstrict_clang - name: Valgrind - run: valgrind --error-exitcode=1 v -o v.c cmd/v + run: v run ci/linux_ci.vsh valgrind_clang - name: Run sanitizers - run: .github/workflows/run_sanitizers.sh + run: v run ci/linux_ci.vsh run_sanitizers_clang - name: v self compilation - run: v -o v2 cmd/v && ./v2 -o v3 cmd/v && ./v3 -o v4 cmd/v + run: v run ci/linux_ci.vsh v_self_compilation_clang - name: v self compilation with -usecache - run: | - unset VFLAGS - v -usecache examples/hello_world.v && examples/hello_world - v -o v2 -usecache cmd/v - ./v2 -o v3 -usecache cmd/v - ./v3 version - ./v3 -o tetris -usecache examples/tetris/tetris.v + run: v run ci/linux_ci.vsh v_self_compilation_usecache_clang - name: Verify `v test` works - run: | - echo $VFLAGS - v cmd/tools/test_if_v_test_system_works.v - ./cmd/tools/test_if_v_test_system_works - + run: v run ci/linux_ci.vsh verify_v_test_works_clang - name: Test pure V math module - run: v -exclude @vlib/math/*.c.v test vlib/math/ + run: v run ci/linux_ci.vsh test_pure_v_math_module_clang - name: Self tests - run: v test-self vlib + run: v run ci/linux_ci.vsh self_tests_clang - name: Self tests (vprod) - run: v -o vprod -prod cmd/v && ./vprod test-self vlib + run: v run ci/linux_ci.vsh self_tests_vprod_clang - name: Self tests (-cstrict) - run: VTEST_JUST_ESSENTIAL=1 V_CI_CSTRICT=1 ./vprod -cstrict test-self vlib - + run: v run ci/linux_ci.vsh self_tests_cstrict_clang - name: Build examples - run: v -N -W build-examples + run: v run ci/linux_ci.vsh build_examples_clang - name: Build examples with -autofree - run: | - v -autofree -experimental -o tetris examples/tetris/tetris.v + run: v run ci/linux_ci.vsh build_examples_autofree_clang - name: Test vlib modules with -skip-unused - run: v -skip-unused test vlib/builtin/ vlib/math vlib/flag/ vlib/os/ vlib/strconv/ + run: v run ci/linux_ci.vsh test_vlib_skip_unused_clang - name: Build modules - run: | - v build-module vlib/os - v build-module vlib/builtin - v build-module vlib/strconv - v build-module vlib/time - v build-module vlib/term - v build-module vlib/math - v build-module vlib/strings - v build-module vlib/v/token - v build-module vlib/v/ast - v build-module vlib/v/parser - v build-module vlib/v/gen/c - v build-module vlib/v/depgraph - v build-module vlib/os/cmdline + run: v run ci/linux_ci.vsh build_modules_clang - name: native machine code generation - run: | - v -o vprod -prod cmd/v - cd cmd/tools - echo "Generating a 1m line V file..." - ../../vprod gen1m.v - ./gen1m > 1m.v - echo "Building it..." - ../../vprod -backend native -o 1m 1m.v - echo "Running it..." - ./1m - ls - - # autofree-selfcompile: - # runs-on: ubuntu-20.04 - # if: github.event_name != 'push' || github.ref == 'refs/heads/master' || github.repository != 'vlang/v' - # timeout-minutes: 121 - # env: - # VFLAGS: -cc gcc - # steps: - # - uses: actions/checkout@v4 - # - name: Build V - # run: make -j4 - # - name: V self compilation with -autofree - # run: v -o v2 -autofree cmd/v && ./v2 -o v3 -autofree cmd/v && ./v3 -o v4 -autofree cmd/v + run: v run ci/linux_ci.vsh native_machine_code_generation_clang - # musl: - # runs-on: ubuntu-20.04 - # if: github.event_name != 'push' || github.ref == 'refs/heads/master' || github.repository != 'vlang/v' - # timeout-minutes: 121 - # env: - # VFLAGS: -cc musl-gcc - # V_CI_MUSL: 1 - # steps: - # - name: Build v - # run: echo $VFLAGS && make -j4 && ./v symlink - # - uses: actions/checkout@v4 - # - name: Install dependencies for examples and tools - # run: v retry -- sudo apt install --quiet -y musl musl-tools libssl-dev sqlite3 libsqlite3-dev valgrind - # - name: Recompile V with -cg - # run: v -cg -o v cmd/v - # # - name: Test v binaries - # # run: v -N -W build-vbinaries - # # - name: Test v->js - # # run: v -o hi.js examples/js_hello_world.v && node hi.js - # - name: quick debug - # run: v -stats vlib/strconv/format_test.v - # - name: Self tests - # run: v test-self vlib diff --git a/ci/linux_ci.vsh b/ci/linux_ci.vsh new file mode 100644 index 00000000000000..1974b969bf0742 --- /dev/null +++ b/ci/linux_ci.vsh @@ -0,0 +1,445 @@ +import common { Task, exec } + +// +// Shared tasks/helpers +// +fn all_code_is_formatted() { + if common.is_github_job { + exec('VJOBS=1 v test-cleancode') + } else { + exec('v -progress test-cleancode') + } +} + +fn verify_v_test_works() { + exec('echo \$VFLAGS') + exec('v cmd/tools/test_if_v_test_system_works.v') + exec('./cmd/tools/test_if_v_test_system_works') +} + +fn test_pure_v_math_module() { + exec('v -exclude @vlib/math/*.c.v test vlib/math/') +} + +fn self_tests() { + if common.is_github_job { + exec('VJOBS=1 v test-self vlib') + } else { + exec('v -progress test-self vlib') + } +} + +fn test_vlib_skip_unused() { + exec('v -skip-unused test vlib/builtin/ vlib/math vlib/flag/ vlib/os/ vlib/strconv/') +} + +fn build_examples() { + if common.is_github_job { + exec('v build-examples') + } else { + exec('v -progress build-examples') + } +} + +fn v_doctor() { + exec('v doctor') +} + +// +// TCC job tasks +// + +fn build_v_with_prealloc() { + exec('v -d debug_malloc -d debug_realloc -o v cmd/v') + exec('v -cg -cstrict -o v cmd/v') + exec('v -o vrealloc -prealloc cmd/v && ./vrealloc -o v3 cmd/v && ./v3 -o v4 cmd/v') +} + +fn install_dependencies_for_examples_and_tools_tcc() { + exec('v retry -- sudo apt update') + exec('v retry -- sudo apt install --quiet -y libssl-dev sqlite3 libsqlite3-dev valgrind') + exec('v retry -- sudo apt install --quiet -y libfreetype6-dev libxi-dev libxcursor-dev libgl-dev libasound2-dev') + // The following is needed for examples/wkhtmltopdf.v + exec('v retry -- wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb') + exec('v retry -- sudo apt install --quiet -y xfonts-75dpi xfonts-base') + exec('v retry -- sudo apt install --quiet -y expect') + exec('v retry -- sudo dpkg -i wkhtmltox_0.12.6-1.focal_amd64.deb') +} + +fn test_v_to_c_tcc() { + exec('thirdparty/tcc/tcc.exe -version') + exec('v -cg -o v cmd/v') // ensure vtcc can build itself twice +} + +fn v_self_compilation_tcc() { + exec('v -o v2 cmd/v && ./v2 -o v3 cmd/v && ./v3 -o v4 cmd/v') +} + +fn v_self_compilation_skip_unused_tcc() { + exec('v -skip-unused -o v2 cmd/v && ./v2 -skip-unused -o v3 cmd/v && ./v3 -skip-unused -o v4 cmd/v') +} + +fn test_vlib_skip_unused_tcc() { + test_vlib_skip_unused() +} + +fn v_doctor_tcc() { + v_doctor() +} + +fn verify_v_test_works_tcc() { + verify_v_test_works() +} + +fn test_pure_v_math_module_tcc() { + test_pure_v_math_module() +} + +fn self_tests_tcc() { + self_tests() +} + +fn build_examples_tcc() { + build_examples() +} + +fn run_submodule_example_tcc() { + exec('v -W run examples/submodule') +} + +fn build_tools_tcc() { + exec('v -N -W build-tools') +} + +fn build_vbinaries_tcc() { + exec('v -N -W build-vbinaries') +} + +fn build_benches_tcc() { + exec('v should-compile-all vlib/v/tests/bench/') +} + +fn run_vsh_script_tcc() { + exec('v run examples/v_script.vsh') +} + +fn test_v_tutorials_tcc() { + exec('v tutorials/building_a_simple_web_blog_with_vweb/code/blog') +} + +fn build_fast_tcc() { + exec('cd cmd/tools/fast && v fast.v && ./fast') +} + +fn v_self_compilation_usecache_tcc() { + exec('unset VFLAGS') + exec('v -usecache examples/hello_world.v && examples/hello_world') + exec('v -o v2 -usecache cmd/v') + exec('./v2 -o v3 -usecache cmd/v') + exec('./v3 version') + exec('./v3 -o tetris -usecache examples/tetris/tetris.v') +} + +fn test_password_input_tcc() { + exec('v test examples/password/') +} + +fn test_readline_tcc() { + exec('v test examples/readline/') +} + +fn test_leak_detector_tcc() { + exec('v -gc boehm_leak -o testcase_leak vlib/v/tests/testcase_leak.vv') + exec('./testcase_leak 2>leaks.txt') + exec('grep "Found 1 leaked object" leaks.txt && grep -P ", sz=\\s?1000," leaks.txt') +} + +fn test_leak_detector_not_active_tcc() { + exec('v -o testcase_leak vlib/v/tests/testcase_leak.vv') + exec('./testcase_leak 2>leaks.txt') + exec('[ "$(stat -c %s leaks.txt)" = "0" ]') +} + +// +// GCC job tasks +// + +fn all_code_is_formatted_gcc() { + all_code_is_formatted() +} + +fn install_dependencies_for_examples_and_tools_gcc() { + exec('v retry -- sudo apt update') + exec('v retry -- sudo apt install --quiet -y postgresql libpq-dev libssl-dev sqlite3 libsqlite3-dev valgrind') + exec('v retry -- sudo apt install --quiet -y libfreetype6-dev libxi-dev libxcursor-dev libgl-dev libasound2-dev') +} + +fn recompile_v_with_cstrict_gcc() { + exec('v -cc gcc -cg -cstrict -o v cmd/v') +} + +fn valgrind_v_c_gcc() { + exec('valgrind --error-exitcode=1 v -o v.c cmd/v') +} + +fn run_sanitizers_gcc() { + exec('v -o v2 cmd/v -cflags -fsanitize=thread') + exec('v -o v3 cmd/v -cflags "-fsanitize=undefined -fno-sanitize=alignment"') + exec('UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./v2 -o v.c cmd/v') + exec('UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./v3 -o v.c cmd/v') +} + +fn v_self_compilation_gcc() { + exec('v -o v2 cmd/v && ./v2 -o v3 cmd/v && ./v3 -o v4 cmd/v') +} + +fn v_self_compilation_usecache_gcc() { + exec('unset VFLAGS') + exec('v -usecache examples/hello_world.v && examples/hello_world') + exec('v -o v2 -usecache cmd/v') + exec('./v2 -o v3 -usecache cmd/v') + exec('./v3 version') + exec('./v3 -o tetris -usecache examples/tetris/tetris.v') +} + +fn verify_v_test_works_gcc() { + verify_v_test_works() +} + +fn test_pure_v_math_module_gcc() { + test_pure_v_math_module() +} + +fn self_tests_gcc() { + self_tests() +} + +fn self_tests_prod_gcc() { + exec('v -o vprod -prod cmd/v && ./vprod test-self vlib') +} + +fn self_tests_cstrict_gcc() { + exec('VTEST_JUST_ESSENTIAL=1 V_CI_CSTRICT=1 v -cc gcc -cstrict test-self vlib') +} + +fn build_examples_gcc() { + build_examples() +} + +fn build_tetris_autofree_gcc() { + exec('v -autofree -o tetris examples/tetris/tetris.v') +} + +fn build_blog_autofree_gcc() { + exec('v -autofree -o blog tutorials/building_a_simple_web_blog_with_vweb/code/blog') +} + +fn build_option_test_autofree_gcc() { + exec('v -autofree vlib/v/tests/options/option_test.c.v') +} + +fn v_self_compilation_parallel_cc_gcc() { + exec('v -o v2 -parallel-cc cmd/v') +} + +fn test_vlib_skip_unused_gcc() { + test_vlib_skip_unused() +} + +fn build_modules_gcc() { + exec('v build-module vlib/os') + exec('v build-module vlib/builtin') + exec('v build-module vlib/strconv') + exec('v build-module vlib/time') + exec('v build-module vlib/term') + exec('v build-module vlib/math') + exec('v build-module vlib/strings') + exec('v build-module vlib/v/token') + exec('v build-module vlib/v/ast') + exec('v build-module vlib/v/parser') + exec('v build-module vlib/v/gen/c') + exec('v build-module vlib/v/depgraph') + exec('v build-module vlib/os/cmdline') +} + +fn native_machine_code_generation_gcc() { + exec('v -o vprod -prod cmd/v') + exec('cd cmd/tools && ../../vprod gen1m.v && ./gen1m > 1m.v') + exec('cd cmd/tools && ../../vprod -backend native -o 1m 1m.v && ./1m && ls') +} + +fn compile_vdoctor_skip_unused_prod_gcc() { + exec('v -showcc -skip-unused -cc gcc -prod cmd/tools/vdoctor.v') +} + +fn compile_vup_skip_unused_prod_gcc() { + exec('v -showcc -skip-unused -cc gcc -prod cmd/tools/vup.v') +} + +// +// Clang job tasks +// + +fn all_code_is_formatted_clang() { + all_code_is_formatted() +} + +fn install_dependencies_for_examples_and_tools_clang() { + exec('v retry -- sudo apt update') + exec('v retry -- sudo apt install --quiet -y postgresql libpq-dev libssl-dev sqlite3 libsqlite3-dev valgrind') + exec('v retry -- sudo apt install --quiet -y libfreetype6-dev libxi-dev libxcursor-dev libgl-dev libasound2-dev') + exec('v retry -- sudo apt install --quiet -y clang') +} + +fn recompile_v_with_cstrict_clang() { + exec('v -cc clang -cg -cstrict -o v cmd/v') +} + +fn valgrind_clang() { + exec('valgrind --error-exitcode=1 v -o v.c cmd/v') +} + +fn run_sanitizers_clang() { + exec('.github/workflows/run_sanitizers.sh') +} + +fn v_self_compilation_clang() { + exec('v -o v2 cmd/v && ./v2 -o v3 cmd/v && ./v3 -o v4 cmd/v') +} + +fn v_self_compilation_usecache_clang() { + exec('unset VFLAGS') + exec('v -usecache examples/hello_world.v && examples/hello_world') + exec('v -o v2 -usecache cmd/v') + exec('./v2 -o v3 -usecache cmd/v') + exec('./v3 version') + exec('./v3 -o tetris -usecache examples/tetris/tetris.v') +} + +fn verify_v_test_works_clang() { + verify_v_test_works() +} + +fn test_pure_v_math_module_clang() { + test_pure_v_math_module() +} + +fn self_tests_clang() { + self_tests() +} + +fn self_tests_vprod_clang() { + exec('v -o vprod -prod cmd/v && ./vprod test-self vlib') +} + +fn self_tests_cstrict_clang() { + exec('VTEST_JUST_ESSENTIAL=1 V_CI_CSTRICT=1 ./vprod -cstrict test-self vlib') +} + +fn build_examples_clang() { + build_examples() +} + +fn build_examples_autofree_clang() { + exec('v -autofree -experimental -o tetris examples/tetris/tetris.v') +} + +fn test_vlib_skip_unused_clang() { + test_vlib_skip_unused() +} + +fn build_modules_clang() { + exec('v build-module vlib/os') + exec('v build-module vlib/builtin') + exec('v build-module vlib/strconv') + exec('v build-module vlib/time') + exec('v build-module vlib/term') + exec('v build-module vlib/math') + exec('v build-module vlib/strings') + exec('v build-module vlib/v/token') + exec('v build-module vlib/v/ast') + exec('v build-module vlib/v/parser') + exec('v build-module vlib/v/gen/c') + exec('v build-module vlib/v/depgraph') + exec('v build-module vlib/os/cmdline') +} + +fn native_machine_code_generation_clang() { + exec('v -o vprod -prod cmd/v') + exec('cd cmd/tools && ../../vprod gen1m.v && ./gen1m > 1m.v') + exec('cd cmd/tools && ../../vprod -backend native -o 1m 1m.v && ./1m && ls') +} + +// +// Collect all tasks +// +const all_tasks = { + // tcc tasks + 'build_v_with_prealloc': Task{build_v_with_prealloc, 'Build V with prealloc'} + 'all_code_is_formatted_tcc': Task{all_code_is_formatted, 'All code is formatted (tcc)'} + 'install_dependencies_for_examples_and_tools_tcc': Task{install_dependencies_for_examples_and_tools_tcc, 'Install deps for examples/tools (tcc)'} + 'test_v_to_c_tcc': Task{test_v_to_c_tcc, 'Test v->c with tcc'} + 'v_self_compilation_tcc': Task{v_self_compilation_tcc, 'V self compilation (tcc)'} + 'v_self_compilation_skip_unused_tcc': Task{v_self_compilation_skip_unused_tcc, 'V self compilation with -skip-unused (tcc)'} + 'test_vlib_skip_unused_tcc': Task{test_vlib_skip_unused_tcc, 'Test vlib modules with -skip-unused (tcc)'} + 'v_doctor_tcc': Task{v_doctor_tcc, 'v doctor (tcc)'} + 'verify_v_test_works_tcc': Task{verify_v_test_works_tcc, 'Verify `v test` works (tcc)'} + 'test_pure_v_math_module_tcc': Task{test_pure_v_math_module_tcc, 'Test pure V math module (tcc)'} + 'self_tests_tcc': Task{self_tests_tcc, 'Self tests (tcc)'} + 'build_examples_tcc': Task{build_examples_tcc, 'Build examples (tcc)'} + 'run_submodule_example_tcc': Task{run_submodule_example_tcc, 'Run submodule example (tcc)'} + 'build_tools_tcc': Task{build_tools_tcc, 'Build V tools (tcc)'} + 'build_vbinaries_tcc': Task{build_vbinaries_tcc, 'Build V binaries (tcc)'} + 'build_benches_tcc': Task{build_benches_tcc, 'Build benches (tcc)'} + 'run_vsh_script_tcc': Task{run_vsh_script_tcc, 'Run a VSH script (tcc)'} + 'test_v_tutorials_tcc': Task{test_v_tutorials_tcc, 'Test V tutorials (tcc)'} + 'build_fast_tcc': Task{build_fast_tcc, 'Build cmd/tools/fast (tcc)'} + 'v_self_compilation_usecache_tcc': Task{v_self_compilation_usecache_tcc, 'V self compilation with -usecache (tcc)'} + 'test_password_input_tcc': Task{test_password_input_tcc, 'Test password input (tcc)'} + 'test_readline_tcc': Task{test_readline_tcc, 'Test readline (tcc)'} + 'test_leak_detector_tcc': Task{test_leak_detector_tcc, 'Test leak detector (tcc)'} + 'test_leak_detector_not_active_tcc': Task{test_leak_detector_not_active_tcc, 'Test leak detector not active (tcc)'} + // gcc tasks + 'all_code_is_formatted_gcc': Task{all_code_is_formatted_gcc, 'All code is formatted (gcc)'} + 'install_dependencies_for_examples_and_tools_gcc': Task{install_dependencies_for_examples_and_tools_gcc, 'Install deps for examples/tools (gcc)'} + 'recompile_v_with_cstrict_gcc': Task{recompile_v_with_cstrict_gcc, 'Recompile V with -cstrict and gcc'} + 'valgrind_v_c_gcc': Task{valgrind_v_c_gcc, 'Valgrind v.c (gcc)'} + 'run_sanitizers_gcc': Task{run_sanitizers_gcc, 'Run sanitizers (gcc)'} + 'v_self_compilation_gcc': Task{v_self_compilation_gcc, 'V self compilation (gcc)'} + 'v_self_compilation_usecache_gcc': Task{v_self_compilation_usecache_gcc, 'V self compilation with -usecache (gcc)'} + 'verify_v_test_works_gcc': Task{verify_v_test_works_gcc, 'Verify `v test` works (gcc)'} + 'test_pure_v_math_module_gcc': Task{test_pure_v_math_module_gcc, 'Test pure V math module (gcc)'} + 'self_tests_gcc': Task{self_tests_gcc, 'Self tests (gcc)'} + 'self_tests_prod_gcc': Task{self_tests_prod_gcc, 'Self tests (-prod) (gcc)'} + 'self_tests_cstrict_gcc': Task{self_tests_cstrict_gcc, 'Self tests (-cstrict) (gcc)'} + 'build_examples_gcc': Task{build_examples_gcc, 'Build examples (gcc)'} + 'build_tetris_autofree_gcc': Task{build_tetris_autofree_gcc, 'Build tetris with -autofree (gcc)'} + 'build_blog_autofree_gcc': Task{build_blog_autofree_gcc, 'Build blog tutorial with -autofree (gcc)'} + 'build_option_test_autofree_gcc': Task{build_option_test_autofree_gcc, 'Build option_test.c.v with -autofree (gcc)'} + 'v_self_compilation_parallel_cc_gcc': Task{v_self_compilation_parallel_cc_gcc, 'V self compilation with -parallel-cc (gcc)'} + 'test_vlib_skip_unused_gcc': Task{test_vlib_skip_unused_gcc, 'Test vlib modules with -skip-unused (gcc)'} + 'build_modules_gcc': Task{build_modules_gcc, 'Build modules (gcc)'} + 'native_machine_code_generation_gcc': Task{native_machine_code_generation_gcc, 'native machine code generation (gcc)'} + 'compile_vdoctor_skip_unused_prod_gcc': Task{compile_vdoctor_skip_unused_prod_gcc, 'compile vdoctor with -skip-unused -prod (gcc)'} + 'compile_vup_skip_unused_prod_gcc': Task{compile_vup_skip_unused_prod_gcc, 'compile vup with -skip-unused -prod (gcc)'} + // clang tasks + 'all_code_is_formatted_clang': Task{all_code_is_formatted_clang, 'All code is formatted (clang)'} + 'install_dependencies_for_examples_and_tools_clang': Task{install_dependencies_for_examples_and_tools_clang, 'Install deps for examples/tools (clang)'} + 'recompile_v_with_cstrict_clang': Task{recompile_v_with_cstrict_clang, 'Recompile V with -cstrict and clang'} + 'valgrind_clang': Task{valgrind_clang, 'Valgrind (clang)'} + 'run_sanitizers_clang': Task{run_sanitizers_clang, 'Run sanitizers (clang)'} + 'v_self_compilation_clang': Task{v_self_compilation_clang, 'V self compilation (clang)'} + 'v_self_compilation_usecache_clang': Task{v_self_compilation_usecache_clang, 'V self compilation with -usecache (clang)'} + 'verify_v_test_works_clang': Task{verify_v_test_works_clang, 'Verify `v test` works (clang)'} + 'test_pure_v_math_module_clang': Task{test_pure_v_math_module_clang, 'Test pure V math module (clang)'} + 'self_tests_clang': Task{self_tests_clang, 'Self tests (clang)'} + 'self_tests_vprod_clang': Task{self_tests_vprod_clang, 'Self tests (vprod) (clang)'} + 'self_tests_cstrict_clang': Task{self_tests_cstrict_clang, 'Self tests (-cstrict) (clang)'} + 'build_examples_clang': Task{build_examples_clang, 'Build examples (clang)'} + 'build_examples_autofree_clang': Task{build_examples_autofree_clang, 'Build examples with -autofree (clang)'} + 'test_vlib_skip_unused_clang': Task{test_vlib_skip_unused_clang, 'Test vlib modules with -skip-unused (clang)'} + 'build_modules_clang': Task{build_modules_clang, 'Build modules (clang)'} + 'native_machine_code_generation_clang': Task{native_machine_code_generation_clang, 'native machine code generation (clang)'} +} + +common.run(all_tasks) diff --git a/ci/macos_ci.vsh b/ci/macos_ci.vsh index 7515661be0066a..ddb6d8bd6e8d8d 100644 --- a/ci/macos_ci.vsh +++ b/ci/macos_ci.vsh @@ -98,6 +98,9 @@ fn v_self_compilation_usecache() { fn v_self_compilation_parallel_cc() { exec('v -o v2 -parallel-cc cmd/v') + // exec('./v2 -o v3 -usecache cmd/v') + exec('./v2 version') + exec('./v2 -o tetris examples/tetris/tetris.v') } fn test_password_input() { diff --git a/vlib/v/builder/builder.v b/vlib/v/builder/builder.v index a897d4046495aa..59a19cd698d2a0 100644 --- a/vlib/v/builder/builder.v +++ b/vlib/v/builder/builder.v @@ -43,6 +43,7 @@ pub mut: path_invalidates_mods map[string][]string // changes in a .v file from `os`, invalidates `os` crun_cache_keys []string // target executable + top level source files; filled in by Builder.should_rebuild executable_exists bool // if the executable already exists, don't remove new executable after `v run` + str_args string // for parallel_cc mode only, to know which cc args to use (like -I etc) } pub fn new_builder(pref_ &pref.Preferences) Builder { diff --git a/vlib/v/builder/cbuilder/cbuilder.v b/vlib/v/builder/cbuilder/cbuilder.v index 2cdd14c0f4cb72..2c5c8cd462408d 100644 --- a/vlib/v/builder/cbuilder/cbuilder.v +++ b/vlib/v/builder/cbuilder/cbuilder.v @@ -80,6 +80,7 @@ pub fn gen_c(mut b builder.Builder, v_files []string) string { util.timing_measure('C GEN') if b.pref.parallel_cc { + b.cc() // Call it just to gen b.str_args util.timing_start('Parallel C compilation') parallel_cc(mut b, result) util.timing_measure('Parallel C compilation') diff --git a/vlib/v/builder/cbuilder/parallel_cc.v b/vlib/v/builder/cbuilder/parallel_cc.v index 45a4eda4a56a55..8fd5dac6561c64 100644 --- a/vlib/v/builder/cbuilder/parallel_cc.v +++ b/vlib/v/builder/cbuilder/parallel_cc.v @@ -11,7 +11,7 @@ const cc_compiler = os.getenv_opt('CC') or { 'cc' } const cc = os.quoted_path(cc_compiler) const cc_ldflags = os.getenv_opt('LDFLAGS') or { '' } const cc_cflags = os.getenv_opt('CFLAGS') or { '' } -const cc_cflags_opt = os.getenv_opt('CFLAGS_OPT') or { '-O3' } +const cc_cflags_opt = os.getenv_opt('CFLAGS_OPT') or { '' } // '-O3' } fn parallel_cc(mut b builder.Builder, result c.GenOutput) { sw_total := time.new_stopwatch() @@ -76,7 +76,7 @@ fn parallel_cc(mut b builder.Builder, result c.GenOutput) { o_postfixes << (i + 1).str() } for postfix in o_postfixes { - cmds << '${cc} ${cc_cflags} ${cc_cflags_opt} -c -w -o out_${postfix}.o out_${postfix}.c' + cmds << '${cc} ${cc_cflags} ${cc_cflags_opt} ${b.str_args} -c -w -o out_${postfix}.o out_${postfix}.c' } sw := time.new_stopwatch() mut pp := pool.new_pool_processor(callback: build_parallel_o_cb) diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index 093e9f691fc35d..644aa286b46b40 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -365,7 +365,9 @@ fn (mut v Builder) setup_ccompiler_options(ccompiler string) { } } // The C file we are compiling - ccoptions.source_args << '"${v.out_name_c}"' + if !v.pref.parallel_cc { // parallel_cc uses its own split up c files + ccoptions.source_args << '"${v.out_name_c}"' + } // Min macos version is mandatory I think? if v.pref.os == .macos { if v.pref.macosx_version_min != '0' { @@ -569,7 +571,10 @@ fn (mut v Builder) setup_output_name() { if os.is_dir(v.pref.out_name) { verror("'${v.pref.out_name}' is a directory") } - v.ccoptions.o_args << '-o "${v.pref.out_name}"' + if !v.pref.parallel_cc { + // parallel_cc sets its own `-o out_n.o` + v.ccoptions.o_args << '-o "${v.pref.out_name}"' + } } pub fn (mut v Builder) cc() { @@ -682,6 +687,12 @@ pub fn (mut v Builder) cc() { all_args.join(' ') } mut cmd := '${v.quote_compiler_name(ccompiler)} ${str_args}' + if v.pref.parallel_cc { + // In parallel cc mode, all we want in cc() is build the str_args. + // Actual cc logic then happens in `parallel_cc()` + v.str_args = str_args + return + } mut response_file := '' mut response_file_content := str_args if !v.pref.no_rsp {