Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions recipes/recipes_emscripten/antlr4-runtime/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
set -exuo pipefail

# Set default values for potentially unset variables
EM_FORGE_SIDE_MODULE_CFLAGS="${EM_FORGE_SIDE_MODULE_CFLAGS:-}"
EM_FORGE_SIDE_MODULE_LDFLAGS="${EM_FORGE_SIDE_MODULE_LDFLAGS:-}"
CFLAGS="${CFLAGS:-}"
CXXFLAGS="${CXXFLAGS:-}"
LDFLAGS="${LDFLAGS:-}"

export CFLAGS="$CFLAGS $EM_FORGE_SIDE_MODULE_CFLAGS"
export CXXFLAGS="$CXXFLAGS $EM_FORGE_SIDE_MODULE_CFLAGS"
export LDFLAGS="$LDFLAGS $EM_FORGE_SIDE_MODULE_LDFLAGS"

# ANTLR4 C++ runtime lives in runtime/Cpp/ subdirectory
cd runtime/Cpp

mkdir -p build
cd build

emcmake cmake -GNinja \
${CMAKE_ARGS} \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_STANDARD=17 \
-DCMAKE_INSTALL_PREFIX="${PREFIX}" \
-DCMAKE_INSTALL_LIBDIR=lib \
-DCMAKE_PREFIX_PATH="${PREFIX}" \
-DANTLR_BUILD_CPP_TESTS=OFF \
-DANTLR_BUILD_SHARED=OFF \
-DANTLR_BUILD_STATIC=ON \
-DANTLR4_INSTALL=ON \
-DWITH_DEMO=OFF \
..

ninja install
16 changes: 16 additions & 0 deletions recipes/recipes_emscripten/antlr4-runtime/build_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -e

export CFLAGS="${CFLAGS:-}"
export CXXFLAGS="${CXXFLAGS:-}"

emcmake cmake -S tests -B build_tests \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH="${PREFIX}" \
-DCMAKE_FIND_ROOT_PATH="${PREFIX}" \
-DCMAKE_CXX_STANDARD=17

emmake make -C build_tests -j"${CPU_COUNT:-1}"

echo "Running test..."
node build_tests/test_antlr4_runtime.js
57 changes: 57 additions & 0 deletions recipes/recipes_emscripten/antlr4-runtime/recipe.yaml
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename the directory as well, please.

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
context:
name: antlr-cpp-runtime
version: 4.13.2

package:
name: ${{ name }}
version: ${{ version }}

source:
url: https://github.com/antlr/antlr4/archive/refs/tags/${{ version }}.tar.gz
sha256: 9f18272a9b32b622835a3365f850dd1063d60f5045fb1e12ce475ae6e18a35bb

build:
number: 0
script: build.sh

requirements:
build:
- ${{ compiler('c') }}
- ${{ compiler('cxx') }}
- cmake
- ninja

tests:
- package_contents:
lib:
- libantlr4-runtime.a
include:
- antlr4-runtime/antlr4-runtime.h
- script:
- build_tests.sh
requirements:
build:
- ${{ compiler('cxx') }}
- cmake
- ninja
files:
recipe:
- build_tests.sh
- tests/

about:
homepage: https://www.antlr.org/
license: BSD-3-Clause
license_family: BSD
license_file: LICENSE.txt
summary: ANTLR (ANother Tool for Language Recognition) C++ runtime library
description: |
ANTLR is a powerful parser generator for reading, processing, executing,
or translating structured text or binary files. This package provides
the C++ runtime library required to run parsers generated by ANTLR 4.
documentation: https://github.com/antlr/antlr4/blob/master/doc/index.md
repository: https://github.com/antlr/antlr4

extra:
recipe-maintainers:
- Alex-PLACET
21 changes: 21 additions & 0 deletions recipes/recipes_emscripten/antlr4-runtime/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.16)
project(test_antlr4_runtime CXX)
set(CMAKE_CXX_STANDARD 17)

find_path(ANTLR4_INCLUDE_DIR antlr4-runtime.h
PATHS "${PREFIX}/include/antlr4-runtime"
NO_DEFAULT_PATH)

find_library(ANTLR4_LIBRARY antlr4-runtime
PATHS "${PREFIX}/lib"
NO_DEFAULT_PATH)

if(NOT ANTLR4_INCLUDE_DIR OR NOT ANTLR4_LIBRARY)
message(FATAL_ERROR "Could not find antlr4-runtime library or headers")
endif()

add_executable(test_antlr4_runtime test_antlr4.cpp)
target_include_directories(test_antlr4_runtime PRIVATE
"${PREFIX}/include"
"${ANTLR4_INCLUDE_DIR}")
target_link_libraries(test_antlr4_runtime PRIVATE ${ANTLR4_LIBRARY})
33 changes: 33 additions & 0 deletions recipes/recipes_emscripten/antlr4-runtime/tests/test_antlr4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <antlr4-runtime.h>
#include <iostream>

int main() {
// Create an ANTLR input stream from a string
antlr4::ANTLRInputStream input("hello world");

// Verify basic properties
if (input.size() != 11) {
std::cerr << "FAIL: expected size 11, got " << input.size() << std::endl;
return 1;
}

// Check that we can read characters
std::string consumed;
for (size_t i = 0; i < input.size(); ++i) {
consumed += input.LA(static_cast<ssize_t>(i + 1));
}
if (consumed != "hello world") {
std::cerr << "FAIL: expected 'hello world', got '" << consumed << "'" << std::endl;
return 1;
}

// Test reset and index tracking
input.reset();
if (input.index() != 0) {
std::cerr << "FAIL: expected index 0 after reset, got " << input.index() << std::endl;
return 1;
}

std::cout << "ANTLR4 runtime test passed!" << std::endl;
return 0;
}