Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Adam committed Sep 19, 2015
0 parents commit f9bb5d8
Show file tree
Hide file tree
Showing 78 changed files with 10,404 additions and 0 deletions.
1 change: 1 addition & 0 deletions Ast.cpp
1 change: 1 addition & 0 deletions GraphQLParser.cpp
1 change: 1 addition & 0 deletions JsonVisitor.cpp
17 changes: 17 additions & 0 deletions README.md
@@ -0,0 +1,17 @@
# c-graphqlparser

This is a go-gettable version of the [libgraphqlparser](https://github.com/graphql/libgraphqlparser) C library for use in Go code that needs to link against the libgraphqlparser C library but wants to integrate with `go get` and `go build`.

To use in your project you need to import the package and set appropriate cgo flag directives:

```
import _ "github.com/tecbot/c-graphqlparser"
// #cgo CXXFLAGS: -std=c++11
// #cgo CPPFLAGS: -I <relative-path>/c-graphqlparser/internal
// #cgo darwin LDFLAGS: -Wl,-undefined -Wl,dynamic_lookup
// #cgo !darwin LDFLAGS: -Wl,-unresolved-symbols=ignore-all
import "C"
```

To update the upstream version of libgraphqlparser you'll want to run `./import.sh`.
1 change: 1 addition & 0 deletions c_GraphQLAst.cpp
1 change: 1 addition & 0 deletions c_GraphQLAstNode.cpp
1 change: 1 addition & 0 deletions c_GraphQLAstToJSON.cpp
1 change: 1 addition & 0 deletions c_GraphQLAstVisitor.cpp
1 change: 1 addition & 0 deletions c_GraphQLParser.cpp
8 changes: 8 additions & 0 deletions cgo_flags.go
@@ -0,0 +1,8 @@
// Package graphqlparser uses the cgo compilation facilities to build the
// GraphQL C++ parser.
package graphqlparser

// #cgo CPPFLAGS: -Iinternal
// #cgo CXXFLAGS: -std=c++11 -fPIC -fno-omit-frame-pointer -momit-leaf-frame-pointer
// #cgo CXXFLAGS: -W -Wextra -Wno-deprecated-register -Wno-unused-parameter -Wno-sign-compare
import "C"
8 changes: 8 additions & 0 deletions docker/Dockerfile
@@ -0,0 +1,8 @@
FROM alpine:latest

# Install base requirements
RUN apk add --update alpine-sdk flex bison cmake python

COPY build.sh /data/build.sh

CMD ["/data/build.sh"]
14 changes: 14 additions & 0 deletions docker/build.sh
@@ -0,0 +1,14 @@
#!/bin/sh

set -eu

URL=${LIBGRAPHQLPARSER_URL:-"https://github.com/graphql/libgraphqlparser/archive/master.tar.gz"}

# Build libgraphqlparser
mkdir -p /data/libgraphqlparser
curl -sSL ${URL} \
| tar -v -C /data/libgraphqlparser -xz --strip-components=1 \
&& cd /data/libgraphqlparser \
&& cmake . \
&& make \
&& make install
24 changes: 24 additions & 0 deletions gitignore.patch
@@ -0,0 +1,24 @@
diff --git 1/internal/.gitignore 2/internal/.gitignore
index 0173588..7036933 100644
--- 1/internal/.gitignore
+++ 2/internal/.gitignore
@@ -3,9 +3,6 @@ bison.tab.hpp
*.o
parser.output
dump_json_ast
-Ast.h
-Ast.cpp
-AstVisitor.h
*.dSYM
CMakeCache.txt
CMakeFiles

diff --git 1/internal/c/.gitignore 2/internal/c/.gitignore
deleted file mode 100644
index 02f06d2..e69de29 100644
--- 1/internal/c/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-GraphQLAst.h
-GraphQLAst.cpp
-GraphQLAstForEachConcreteType.h
43 changes: 43 additions & 0 deletions import.sh
@@ -0,0 +1,43 @@
#!/usr/bin/env sh

set -eu

URL="https://github.com/graphql/libgraphqlparser/archive/master.tar.gz"

rm -rf *.cpp internal/*
docker run --rm \
-v $PWD/internal:/data/libgraphqlparser \
-e LIBGRAPHQLPARSER_URL=$URL \
tecbot/libgraphqlparser

# apply patches
patch -p1 < includes.patch
patch -p1 < gitignore.patch

# stuff we need to compile.
SOURCES='
Ast.cpp
GraphQLParser.cpp
JsonVisitor.cpp
lexer.cpp
parser.tab.cpp
'

# symlink so cgo compiles them
for file in $SOURCES; do
ln -sf internal/$file .
done

# stuff we need to compile.
SOURCES='
GraphQLAst.cpp
GraphQLAstNode.cpp
GraphQLAstToJSON.cpp
GraphQLAstVisitor.cpp
GraphQLParser.cpp
'

# symlink so cgo compiles them
for file in $SOURCES; do
ln -sf internal/c/$file ./c_$file
done
45 changes: 45 additions & 0 deletions includes.patch
@@ -0,0 +1,45 @@
diff --git 1/internal/c/GraphQLAst.cpp 2/internal/c/GraphQLAst.cpp
index 3996c9a..cf39d4b 100644
--- 1/internal/c/GraphQLAst.cpp
+++ 2/internal/c/GraphQLAst.cpp
@@ -8,8 +8,8 @@
*/
/** @generated */

-#include "GraphQLAst.h"
-#include "../Ast.h"
+#include "c/GraphQLAst.h"
+#include "Ast.h"

using namespace facebook::graphql::ast;

diff --git a/internal/c/GraphQLAstNode.cpp b/internal/c/GraphQLAstNode.cpp
index a7947b3..9eb2f17 100644
--- a/internal/c/GraphQLAstNode.cpp
+++ b/internal/c/GraphQLAstNode.cpp
@@ -7,8 +7,8 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

-#include "GraphQLAstNode.h"
-#include "../AstNode.h"
+#include "c/GraphQLAstNode.h"
+#include "AstNode.h"

using facebook::graphql::ast::Node;

diff --git a/internal/c/GraphQLParser.cpp b/internal/c/GraphQLParser.cpp
index 871a5f9..5f8aa5a 100644
--- a/internal/c/GraphQLParser.cpp
+++ b/internal/c/GraphQLParser.cpp
@@ -7,9 +7,9 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

+#include "c/GraphQLParser.h"
#include "GraphQLParser.h"
-#include "../GraphQLParser.h"
-#include "../AstNode.h"
+#include "AstNode.h"

#include <cstdlib>
15 changes: 15 additions & 0 deletions internal/.gitignore
@@ -0,0 +1,15 @@
bison.tab.cpp
bison.tab.hpp
*.o
parser.output
dump_json_ast
*.dSYM
CMakeCache.txt
CMakeFiles
CMakeScripts
Makefile
cmake_install.cmake
*.a
*.dylib
*.so
GraphQLParser.py
22 changes: 22 additions & 0 deletions internal/.travis.yml
@@ -0,0 +1,22 @@
language: cpp

compiler:
- clang
- gcc

before_install:
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
- sudo apt-get update -qq
# bison and flex are not installed in CI because
# 1) the versions in Travis are too old, and
# 2) up-to-date bison and flex output should be checked in.
# Versions of g++ prior to 4.8 don't have very good C++11 support.
- sudo apt-get install -y g++-4.8
&& sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 90
- wget https://googletest.googlecode.com/files/gtest-1.7.0.zip
&& cd test
&& unzip ../gtest-1.7.0.zip
&& cd ..
&& rm gtest-1.7.0.zip

script: mkdir build && cd build && cmake .. -Dtest=ON && make && test/runTests

0 comments on commit f9bb5d8

Please sign in to comment.