diff --git a/.github/workflows/hosted.yml b/.github/workflows/hosted.yml deleted file mode 100644 index 7b9e9f9c60..0000000000 --- a/.github/workflows/hosted.yml +++ /dev/null @@ -1,342 +0,0 @@ -name: antlr4 - -concurrency: - group: ${{ github.repository }}-${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -on: - push: - branches: [ master, dev, rust-target, hostedci ] - pull_request: - branches: [ master, dev, rust-target ] - -permissions: - contents: read - -jobs: - cpp-lib-build: - runs-on: ${{ matrix.os }} - - strategy: - fail-fast: false - matrix: - os: [ - macos-15, - ubuntu-22.04, - windows-2022 - ] - compiler: [ clang, gcc ] - unity_build: [ ON, OFF ] - exclude: - - os: windows-2022 - compiler: gcc - include: - - os: windows-2022 - compiler: cl - - steps: - - name: Install dependencies (Ubuntu) - if: startswith(matrix.os, 'ubuntu') - run: | - sudo apt-get update -qq - sudo apt install -y ninja-build - - - name: Install dependencies (MacOS) - if: startswith(matrix.os, 'macos') - run: brew install ninja - - - name: Setup Clang - if: (matrix.compiler == 'clang') && !startswith(matrix.os, 'macos') - uses: egor-tensin/setup-clang@v1 - with: - version: 13 - platform: x64 - cygwin: 0 - - - name: Check out code - uses: actions/checkout@v3 - - - name: Use ccache - if: startswith(matrix.os, 'macos') || startswith(matrix.os, 'ubuntu') - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: ${{ matrix.os }}-${{ matrix.compiler }} - - - name: Configure shell (Ubuntu) - if: startswith(matrix.os, 'ubuntu') - run: echo 'PATH=/usr/lib/ccache:'"$PATH" >> $GITHUB_ENV - - - name: Configure shell (MacOS) - if: startswith(matrix.os, 'macos') - run: echo "PATH=$(brew --prefix)/opt/ccache/libexec:$PATH" >> $GITHUB_ENV - - - name: Build (Windows) - if: startswith(matrix.os, 'windows') - shell: cmd - run: | - call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" - - if "${{ matrix.compiler }}" EQU "cl" ( - set CC=cl - set CXX=cl - echo 'CC=cl' >> $GITHUB_ENV - echo 'CXX=cl' >> $GITHUB_ENV - ) else ( - set CC=clang - set CXX=clang++ - echo 'CC=clang' >> $GITHUB_ENV - echo 'CXX=clang++' >> $GITHUB_ENV - ) - - set - where cmake && cmake --version - where ninja && ninja --version - where %CC% && %CC% -version - where %CXX% && %CXX% -version - - cd runtime/Cpp - - cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DANTLR_BUILD_CPP_TESTS=OFF -DCMAKE_UNITY_BUILD=${{ matrix.unity_build }} -DCMAKE_UNITY_BUILD_BATCH_SIZE=20 -S . -B out/Debug - if %errorlevel% neq 0 exit /b %errorlevel% - - cmake --build out/Debug -j %NUMBER_OF_PROCESSORS% - if %errorlevel% neq 0 exit /b %errorlevel% - - cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DANTLR_BUILD_CPP_TESTS=OFF -S . -B out/Release - if %errorlevel% neq 0 exit /b %errorlevel% - - cmake --build out/Release -j %NUMBER_OF_PROCESSORS% - if %errorlevel% neq 0 exit /b %errorlevel% - - - name: Build (non-Windows) - if: startswith(matrix.os, 'macos') || startswith(matrix.os, 'ubuntu') - run: | - if [ "${{matrix.compiler}}" == "clang" ]; then - export CC=clang - export CXX=clang++ - echo 'CC=clang' >> $GITHUB_ENV - echo 'CXX=clang++' >> $GITHUB_ENV - else - export CC=gcc - export CXX=g++ - echo 'CC=gcc' >> $GITHUB_ENV - echo 'CXX=g++' >> $GITHUB_ENV - fi - - env - which cmake && cmake --version - which ninja && ninja --version - which $CC && $CC --version - which $CXX && $CXX --version - - cd runtime/Cpp - - cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DANTLR_BUILD_CPP_TESTS=OFF -DCMAKE_UNITY_BUILD=${{ matrix.unity_build }} -DCMAKE_UNITY_BUILD_BATCH_SIZE=20 -S . -B out/Debug - cmake --build out/Debug --parallel - - cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DANTLR_BUILD_CPP_TESTS=OFF -S . -B out/Release - cmake --build out/Release --parallel - - - name: Prepare artifacts - if: always() - run: | - cd ${{ github.workspace }}/.. - tar czfp antlr_${{ matrix.os }}_${{ matrix.compiler }}.tgz --exclude='.git' antlr4 - mv antlr_${{ matrix.os }}_${{ matrix.compiler }}.tgz ${{ github.workspace }}/. - - - name: Archive artifacts - if: always() - continue-on-error: true - uses: actions/upload-artifact@v4 - with: - name: antlr_${{ matrix.os }}_${{ matrix.compiler }} - path: antlr_${{ matrix.os }}_${{ matrix.compiler }}.tgz - - - build: - runs-on: ${{ matrix.os }} - - strategy: - fail-fast: false - matrix: - os: [ - macos-15, - ubuntu-22.04, - windows-2022 - ] - target: [ - tool, - cpp, - csharp, - dart, - go, - java, - javascript, - typescript, - php, - python3, - # swift, - ] - exclude: - - os: windows-2022 - target: swift - - steps: - # Check out the code before setting the environment since some - # of the actions actually parse the files to figure out the - # dependencies, for instance, the setup-java actually parses - # **/pom.xml files to decide what to cache. - - name: Check out code - uses: actions/checkout@v3 - - - name: Checkout antlr PHP runtime - if: matrix.target == 'php' - uses: actions/checkout@v3 - with: - repository: antlr/antlr-php-runtime - path: runtime/PHP - - - name: Setup PHP 8.2 - if: matrix.target == 'php' - uses: shivammathur/setup-php@v2 - with: - php-version: '8.3' - extensions: mbstring - tools: composer - - - name: Install dependencies - env: - COMPOSER_CACHE_DIR: ${{ github.workspace }}/.cache - if: matrix.target == 'php' - run: |- - cd runtime/PHP - composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader - - - name: Install dependencies (Ubuntu) - if: startswith(matrix.os, 'ubuntu') - run: | - sudo apt-get update -qq - sudo apt install -y ninja-build - - - name: Install dependencies (MacOS) - if: startswith(matrix.os, 'macos') - run: brew install ninja - - - name: Set up JDK 11 - id: setup-java - uses: actions/setup-java@v3 - with: - distribution: 'zulu' - java-version: 11 - cache: 'maven' - - - name: Set up Maven - if: steps.setup-java.outputs.cache-hit != 'true' - uses: stCarolas/setup-maven@v4.5 - with: - maven-version: 3.8.5 - - - name: Add msbuild to PATH - if: startswith(matrix.os, 'windows') && (matrix.target == 'cpp') - uses: microsoft/setup-msbuild@v1.1 - - - name: Set up Python 3 - if: matrix.target == 'python3' - uses: actions/setup-python@v4 - with: - python-version: '3.x' - architecture: 'x64' - - - name: Set up Node 16 - if: (matrix.target == 'javascript') || (matrix.target == 'typescript') - uses: actions/setup-node@v3.6.0 - with: - node-version: '16' - - - name: Setup Dotnet - if: matrix.target == 'csharp' - uses: actions/setup-dotnet@v3.0.3 - with: - dotnet-version: '7.0.x' - - - name: Setup Dart 2.12.1 - if: matrix.target == 'dart' - uses: dart-lang/setup-dart@v1.3 - with: - sdk: 2.12.1 - - - name: Setup Go 1.19 - if: matrix.target == 'go' - uses: actions/setup-go@v3.3.1 - with: - go-version: '^1.19' - - - name: Setup Swift - if: matrix.target == 'swift' - uses: swift-actions/setup-swift@v1.19.0 - with: - swift-version: '5.2' - - - name: Use ccache - if: (startswith(matrix.os, 'macos') || startswith(matrix.os, 'ubuntu')) && (matrix.target == 'cpp') - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: ${{ matrix.os }}-${{ matrix.target }} - - - name: Configure shell (Ubuntu) - if: startswith(matrix.os, 'ubuntu') && (matrix.target == 'cpp') - run: echo 'PATH=/usr/lib/ccache:'"$PATH" >> $GITHUB_ENV - - - name: Configure shell (MacOS) - if: startswith(matrix.os, 'macos') && (matrix.target == 'cpp') - run: echo "PATH=$(brew --prefix)/opt/ccache/libexec:$PATH" >> $GITHUB_ENV - - - name: Build ANTLR with Maven - run: mvn install -DskipTests=true -Darguments="-Dmaven.javadoc.skip=true" -B -V - - - name: Test tool - if: matrix.target == 'tool' - run: | - cd tool-testsuite - mvn test - - - name: Test runtime (Windows) - if: startsWith(matrix.os, 'windows') && (matrix.target != 'tool') - run: | - gci env:* | sort-object name - - cd runtime-testsuite - switch ("${{ matrix.target }}") - { - python3 { mvn -X '-Dantlr-python3-exec="${{ env.pythonLocation }}\python.exe"' '-Dtest=python3.**' test } - default { mvn -X '-Dtest=${{ matrix.target }}.**' test } - } - - env: - CMAKE_GENERATOR: Ninja - - - name: Test runtime (non-Windows) - if: (startsWith(matrix.os, 'ubuntu') || startsWith(matrix.os, 'macos')) && (matrix.target != 'tool') - run: | - env - - cd runtime-testsuite - case ${{ matrix.target }} in - python3) mvn -X '-Dantlr-python3-exec=${{ env.pythonLocation }}/bin/python' '-Dtest=python3.**' test ;; - *) mvn -X '-Dtest=${{ matrix.target }}.**' test ;; - esac - - - name: Prepare artifacts - if: always() - run: | - cd ${{ github.workspace }}/.. - tar czfp antlr_${{ matrix.os }}_${{ matrix.target }}.tgz --exclude='.git' antlr4 - mv antlr_${{ matrix.os }}_${{ matrix.target }}.tgz ${{ github.workspace }}/. - - - name: Archive artifacts - if: always() - continue-on-error: true - uses: actions/upload-artifact@v4 - with: - name: antlr_${{ matrix.os }}_${{ matrix.target }} - path: antlr_${{ matrix.os }}_${{ matrix.target }}.tgz diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 0000000000..8336140e4e --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,142 @@ +name: Rust runtime + +concurrency: + group: ${{ github.repository }}-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +on: + push: + branches: [ dev ] + pull_request: + branches: [ dev ] + +permissions: + contents: read + +env: + CARGO_TERM_COLOR: always + RUST_MSRV: "1.96" + +defaults: + run: + working-directory: runtime/Rust + +jobs: + # Code quality: formatting and lints. Uses stable so clippy/rustfmt are the + # current versions. + quality: + name: fmt + clippy + runs-on: ubuntu-24.04 + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Install stable toolchain + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt, clippy + + - name: Cache cargo + uses: Swatinem/rust-cache@v2 + with: + workspaces: runtime/Rust + + - name: cargo fmt + run: cargo fmt --all -- --check + + - name: cargo clippy + run: cargo clippy --all-targets --all-features -- -D warnings + + # Rust runtime unit/integration tests against checked-in generated parsers. + # Runs on the MSRV (1.96) and current stable. + unittests: + name: cargo test (${{ matrix.rust }}) + runs-on: ubuntu-24.04 + strategy: + fail-fast: false + matrix: + rust: [ "1.96", stable ] + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Install Rust ${{ matrix.rust }} + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ matrix.rust }} + + - name: Cache cargo + uses: Swatinem/rust-cache@v2 + with: + workspaces: runtime/Rust + key: ${{ matrix.rust }} + + - name: cargo build + run: cargo build --all-targets + + - name: cargo test + run: cargo test + + - name: cargo test --all-features + run: cargo test --all-features + + # JVM-driven Maven tests. Builds the tool jar once, then runs the Rust target + # runtime testsuite (which shells out to cargo/rustc) across the Rust matrix. + # The tool's own unit tests are Rust-independent, so they run only once. + maven-tests: + name: ANTLR tool + Rust runtime testsuite + runs-on: ubuntu-24.04 + # This job drives Maven from the repo root, not runtime/Rust. + defaults: + run: + working-directory: . + strategy: + fail-fast: false + matrix: + rust: [ "1.96", stable ] + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Set up JDK 21 + id: setup-java + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: 21 + cache: 'maven' + + - name: Set up Maven + uses: stCarolas/setup-maven@v5 + with: + maven-version: 3.8.5 + + - name: Install Rust ${{ matrix.rust }} + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ matrix.rust }} + + - name: Cache cargo + uses: Swatinem/rust-cache@v2 + with: + workspaces: runtime/Rust + key: testsuite-${{ matrix.rust }} + + - name: Build ANTLR tool with Maven + run: mvn install -DskipTests=true -Darguments="-Dmaven.javadoc.skip=true" -B -V + env: + MAVEN_OPTS: -Xmx1G + + # Rust-independent: run the tool's own unit tests on a single matrix entry. + - name: Test tool + if: matrix.rust == 'stable' + working-directory: tool-testsuite + run: mvn test + env: + MAVEN_OPTS: -Xmx1G + + - name: Run Rust runtime testsuite + working-directory: runtime-testsuite + run: mvn -Dtest='rust.**' test + env: + MAVEN_OPTS: -Xmx1G diff --git a/runtime/Rust/tests/general_tests.rs b/runtime/Rust/tests/general_tests.rs index 30715fa30d..5e8bf1b3f9 100644 --- a/runtime/Rust/tests/general_tests.rs +++ b/runtime/Rust/tests/general_tests.rs @@ -9,6 +9,8 @@ #[rustfmt::skip] mod gen { + // Generated parsers/lexers: lint with the codegen template, not here. + #![allow(clippy::all)] pub mod csvlexer; pub mod csvlistener; pub mod csvparser; @@ -544,7 +546,7 @@ fn test_recursion_limit() { let mut parser = LabelsParser::new(arena, token_source); parser.set_recursion_limit(100); let result = parser.s().unwrap_err(); - eprintln!("result: {}", result.to_string()); + eprintln!("result: {}", result); assert!(result .to_string() .contains("Recursion limit of 100 exceeded")); diff --git a/runtime/Rust/tests/visitors_tests.rs b/runtime/Rust/tests/visitors_tests.rs index 7d087e1a96..80e7ff80ed 100644 --- a/runtime/Rust/tests/visitors_tests.rs +++ b/runtime/Rust/tests/visitors_tests.rs @@ -1,6 +1,8 @@ #[rustfmt::skip] mod gen { #![allow(non_snake_case)] + // Generated parsers/lexers: lint with the codegen template, not here. + #![allow(clippy::all)] pub mod csvlexer; pub mod csvlistener; pub mod csvparser; @@ -169,7 +171,7 @@ fn test_should_not_visit_eof() { } } let mut visitor_unit = TestVisitorUnit(String::new()); - let _ = visitor_unit.visit(root).unwrap(); + visitor_unit.visit(root).unwrap(); assert_eq!( visitor_unit.0, "[@0,0:0='A',<1>,1:0][@1,1:0='',<-1>,1:1]" @@ -237,15 +239,15 @@ fn test_visitor_with_return() { &mut self, ctx: &SContext<'input, 'arena, Tok>, ) -> Result { - self.visit(&*ctx.expr().unwrap()) + self.visit(ctx.expr().unwrap()) } fn visit_add( &mut self, ctx: &AddContext<'input, 'arena, Tok>, ) -> Result { - let left = self.visit(&*ctx.expr(0).unwrap())?; - let right = self.visit(&*ctx.expr(1).unwrap())?; + let left = self.visit(ctx.expr(0).unwrap())?; + let right = self.visit(ctx.expr(1).unwrap())?; if ctx.ADD().is_some() { Ok(left + right) } else { @@ -264,8 +266,8 @@ fn test_visitor_with_return() { &mut self, ctx: &MultiplyContext<'input, 'arena, Tok>, ) -> Result { - let left = self.visit(&*ctx.expr(0).unwrap())?; - let right = self.visit(&*ctx.expr(1).unwrap())?; + let left = self.visit(ctx.expr(0).unwrap())?; + let right = self.visit(ctx.expr(1).unwrap())?; if ctx.MUL().is_some() { Ok(left * right) } else { @@ -360,7 +362,7 @@ fn test_visitor_retrieve_reference() { } } - fn parse<'a>(input: &'a str) -> i32 { + fn parse(input: &str) -> i32 { Arena::with(|arena| { let lexer = CSVLexer::<_, CommonTokenFactory>::new(arena, InputStream::new(input)); let token_source = CommonTokenStream::new(lexer);