Skip to content

Commit

Permalink
Merge pull request #2762 from Shopify/emily/cpp
Browse files Browse the repository at this point in the history
Test support for C++
  • Loading branch information
kddnewton authored May 15, 2024
2 parents 741c21b + bbd8418 commit 611d599
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/cpp-bindings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: C++ bindings

on:
push:
paths:
- ".github/workflows/cpp-bindings.yml"
- "include/"
- "src/"
- "cpp/"
- "*akefile*"
branches:
- main
pull_request:

jobs:
test:
name: test
strategy:
fail-fast: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: head
bundler-cache: true
- name: Compile prism
run: bundle exec rake compile
- name: Compile C++
run: g++ -o ./cpp_test cpp/test.cpp build/static/*.o build/static/util/*.o -Iinclude
- name: Run C++
run: ./cpp_test
24 changes: 24 additions & 0 deletions cpp/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
extern "C" {
#include "prism.h"
}

#include <iostream>

int main() {
pm_parser_t parser;
pm_parser_init(&parser, reinterpret_cast<const uint8_t *>("1 + 2"), 5, NULL);

pm_node_t *root = pm_parse(&parser);
pm_buffer_t buffer = { 0 };

pm_prettyprint(&buffer, &parser, root);
pm_buffer_append_byte(&buffer, '\0');

std::cout << buffer.value << std::endl;

pm_buffer_free(&buffer);
pm_node_destroy(&parser, root);
pm_parser_free(&parser);

return 0;
}
1 change: 1 addition & 0 deletions rakelib/check_manifest.rake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ task check_manifest: :templates do
autom4te.cache
bin
build
cpp
doc
fuzz
gemfiles
Expand Down

0 comments on commit 611d599

Please sign in to comment.