Skip to content

Commit f9bb5d8

Browse files
author
Thomas Adam
committed
initial commit
0 parents  commit f9bb5d8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+10404
-0
lines changed

Ast.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
internal/Ast.cpp

GraphQLParser.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
internal/GraphQLParser.cpp

JsonVisitor.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
internal/JsonVisitor.cpp

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# c-graphqlparser
2+
3+
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`.
4+
5+
To use in your project you need to import the package and set appropriate cgo flag directives:
6+
7+
```
8+
import _ "github.com/tecbot/c-graphqlparser"
9+
10+
// #cgo CXXFLAGS: -std=c++11
11+
// #cgo CPPFLAGS: -I <relative-path>/c-graphqlparser/internal
12+
// #cgo darwin LDFLAGS: -Wl,-undefined -Wl,dynamic_lookup
13+
// #cgo !darwin LDFLAGS: -Wl,-unresolved-symbols=ignore-all
14+
import "C"
15+
```
16+
17+
To update the upstream version of libgraphqlparser you'll want to run `./import.sh`.

c_GraphQLAst.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
internal/c/GraphQLAst.cpp

c_GraphQLAstNode.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
internal/c/GraphQLAstNode.cpp

c_GraphQLAstToJSON.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
internal/c/GraphQLAstToJSON.cpp

c_GraphQLAstVisitor.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
internal/c/GraphQLAstVisitor.cpp

c_GraphQLParser.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
internal/c/GraphQLParser.cpp

cgo_flags.go

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Package graphqlparser uses the cgo compilation facilities to build the
2+
// GraphQL C++ parser.
3+
package graphqlparser
4+
5+
// #cgo CPPFLAGS: -Iinternal
6+
// #cgo CXXFLAGS: -std=c++11 -fPIC -fno-omit-frame-pointer -momit-leaf-frame-pointer
7+
// #cgo CXXFLAGS: -W -Wextra -Wno-deprecated-register -Wno-unused-parameter -Wno-sign-compare
8+
import "C"

docker/Dockerfile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM alpine:latest
2+
3+
# Install base requirements
4+
RUN apk add --update alpine-sdk flex bison cmake python
5+
6+
COPY build.sh /data/build.sh
7+
8+
CMD ["/data/build.sh"]

docker/build.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
3+
set -eu
4+
5+
URL=${LIBGRAPHQLPARSER_URL:-"https://github.com/graphql/libgraphqlparser/archive/master.tar.gz"}
6+
7+
# Build libgraphqlparser
8+
mkdir -p /data/libgraphqlparser
9+
curl -sSL ${URL} \
10+
| tar -v -C /data/libgraphqlparser -xz --strip-components=1 \
11+
&& cd /data/libgraphqlparser \
12+
&& cmake . \
13+
&& make \
14+
&& make install

gitignore.patch

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
diff --git 1/internal/.gitignore 2/internal/.gitignore
2+
index 0173588..7036933 100644
3+
--- 1/internal/.gitignore
4+
+++ 2/internal/.gitignore
5+
@@ -3,9 +3,6 @@ bison.tab.hpp
6+
*.o
7+
parser.output
8+
dump_json_ast
9+
-Ast.h
10+
-Ast.cpp
11+
-AstVisitor.h
12+
*.dSYM
13+
CMakeCache.txt
14+
CMakeFiles
15+
16+
diff --git 1/internal/c/.gitignore 2/internal/c/.gitignore
17+
deleted file mode 100644
18+
index 02f06d2..e69de29 100644
19+
--- 1/internal/c/.gitignore
20+
+++ /dev/null
21+
@@ -1,3 +0,0 @@
22+
-GraphQLAst.h
23+
-GraphQLAst.cpp
24+
-GraphQLAstForEachConcreteType.h

import.sh

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env sh
2+
3+
set -eu
4+
5+
URL="https://github.com/graphql/libgraphqlparser/archive/master.tar.gz"
6+
7+
rm -rf *.cpp internal/*
8+
docker run --rm \
9+
-v $PWD/internal:/data/libgraphqlparser \
10+
-e LIBGRAPHQLPARSER_URL=$URL \
11+
tecbot/libgraphqlparser
12+
13+
# apply patches
14+
patch -p1 < includes.patch
15+
patch -p1 < gitignore.patch
16+
17+
# stuff we need to compile.
18+
SOURCES='
19+
Ast.cpp
20+
GraphQLParser.cpp
21+
JsonVisitor.cpp
22+
lexer.cpp
23+
parser.tab.cpp
24+
'
25+
26+
# symlink so cgo compiles them
27+
for file in $SOURCES; do
28+
ln -sf internal/$file .
29+
done
30+
31+
# stuff we need to compile.
32+
SOURCES='
33+
GraphQLAst.cpp
34+
GraphQLAstNode.cpp
35+
GraphQLAstToJSON.cpp
36+
GraphQLAstVisitor.cpp
37+
GraphQLParser.cpp
38+
'
39+
40+
# symlink so cgo compiles them
41+
for file in $SOURCES; do
42+
ln -sf internal/c/$file ./c_$file
43+
done

includes.patch

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
diff --git 1/internal/c/GraphQLAst.cpp 2/internal/c/GraphQLAst.cpp
2+
index 3996c9a..cf39d4b 100644
3+
--- 1/internal/c/GraphQLAst.cpp
4+
+++ 2/internal/c/GraphQLAst.cpp
5+
@@ -8,8 +8,8 @@
6+
*/
7+
/** @generated */
8+
9+
-#include "GraphQLAst.h"
10+
-#include "../Ast.h"
11+
+#include "c/GraphQLAst.h"
12+
+#include "Ast.h"
13+
14+
using namespace facebook::graphql::ast;
15+
16+
diff --git a/internal/c/GraphQLAstNode.cpp b/internal/c/GraphQLAstNode.cpp
17+
index a7947b3..9eb2f17 100644
18+
--- a/internal/c/GraphQLAstNode.cpp
19+
+++ b/internal/c/GraphQLAstNode.cpp
20+
@@ -7,8 +7,8 @@
21+
* of patent rights can be found in the PATENTS file in the same directory.
22+
*/
23+
24+
-#include "GraphQLAstNode.h"
25+
-#include "../AstNode.h"
26+
+#include "c/GraphQLAstNode.h"
27+
+#include "AstNode.h"
28+
29+
using facebook::graphql::ast::Node;
30+
31+
diff --git a/internal/c/GraphQLParser.cpp b/internal/c/GraphQLParser.cpp
32+
index 871a5f9..5f8aa5a 100644
33+
--- a/internal/c/GraphQLParser.cpp
34+
+++ b/internal/c/GraphQLParser.cpp
35+
@@ -7,9 +7,9 @@
36+
* of patent rights can be found in the PATENTS file in the same directory.
37+
*/
38+
39+
+#include "c/GraphQLParser.h"
40+
#include "GraphQLParser.h"
41+
-#include "../GraphQLParser.h"
42+
-#include "../AstNode.h"
43+
+#include "AstNode.h"
44+
45+
#include <cstdlib>

internal/.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
bison.tab.cpp
2+
bison.tab.hpp
3+
*.o
4+
parser.output
5+
dump_json_ast
6+
*.dSYM
7+
CMakeCache.txt
8+
CMakeFiles
9+
CMakeScripts
10+
Makefile
11+
cmake_install.cmake
12+
*.a
13+
*.dylib
14+
*.so
15+
GraphQLParser.py

internal/.travis.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
language: cpp
2+
3+
compiler:
4+
- clang
5+
- gcc
6+
7+
before_install:
8+
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
9+
- sudo apt-get update -qq
10+
# bison and flex are not installed in CI because
11+
# 1) the versions in Travis are too old, and
12+
# 2) up-to-date bison and flex output should be checked in.
13+
# Versions of g++ prior to 4.8 don't have very good C++11 support.
14+
- sudo apt-get install -y g++-4.8
15+
&& sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 90
16+
- wget https://googletest.googlecode.com/files/gtest-1.7.0.zip
17+
&& cd test
18+
&& unzip ../gtest-1.7.0.zip
19+
&& cd ..
20+
&& rm gtest-1.7.0.zip
21+
22+
script: mkdir build && cd build && cmake .. -Dtest=ON && make && test/runTests

0 commit comments

Comments
 (0)