Skip to content
This repository was archived by the owner on Nov 5, 2024. It is now read-only.

Commit 88a52d2

Browse files
committed
use precompiled cpp bindings
1 parent d59eb8f commit 88a52d2

File tree

8 files changed

+63
-32
lines changed

8 files changed

+63
-32
lines changed

.github/workflows/test.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,15 @@ jobs:
5151
which node-gyp
5252
5353
- name: npm install
54-
run: npm install
54+
run: npm install --ignore-scripts
55+
56+
- name: configure
57+
run: |
58+
make update-cpp-bindings
59+
make generate-bindings
60+
make configure
5561
5662
- name: Run tests
57-
run: make test-debug
63+
run: |
64+
make build
65+
make test

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ package-lock.json
44
build-convert/target
55
build-convert/Cargo.lock
66
convert_gen.h
7+
8+
lib-ruby-parser.a
9+
lib-ruby-parser.h

Makefile

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,49 @@
1-
test-all: test-debug test-release
2-
3-
test-debug: build-debug
4-
./test.js ./build/Debug/ruby_parser.node
5-
6-
test-release: build-release
7-
./test.js ./build/Release/ruby_parser.node
8-
9-
build-debug: build-deps configure
10-
node-gyp build -d
11-
12-
build-release: build-deps configure
13-
node-gyp build
1+
UNAME_S := $(shell uname -s)
2+
ifeq ($(UNAME_S),Linux)
3+
PLATFORM = linux-x86_64
4+
endif
5+
ifeq ($(UNAME_S),Darwin)
6+
PLATFORM = darwin-x86_64
7+
endif
8+
9+
VERSION = 3.0.0-3
10+
11+
ifndef BUILD_ENV
12+
BUILD_ENV = debug
13+
endif
14+
15+
ifeq ($(BUILD_ENV), debug)
16+
NODE_GYP_FLAGS = -d
17+
GYP_ENV = Debug
18+
else
19+
NODE_GYP_FLAGS =
20+
GYP_ENV = Release
21+
endif
22+
23+
ASSET_PREFIX = https://github.com/lib-ruby-parser/cpp-bindings/releases/download/v$(VERSION)
24+
LIB_RUBY_PARSER_H_URL = $(ASSET_PREFIX)/lib-ruby-parser.h
25+
LIB_RUBY_PARSER_A_URL = $(ASSET_PREFIX)/$(PLATFORM).a
1426

1527
configure:
1628
node-gyp configure
1729

18-
build-deps: run-build-convert build-cpp-bindings-shared
19-
20-
run-build-convert:
30+
generate-bindings:
2131
cd build-convert && cargo build
2232

23-
build-cpp-bindings-shared:
24-
cd lib-ruby-parser-cpp-bindings && make cargo-build-release
33+
.PHONY: build
34+
build:
35+
node-gyp build $(NODE_GYP_FLAGS)
36+
37+
GYP_OUTPUT = ./build/$(GYP_ENV)/ruby_parser.node
38+
test:
39+
./test.js $(GYP_OUTPUT)
2540

2641
clean:
27-
rm -rf build
28-
rm -rf node_modules
42+
rm -f $(GYP_OUTPUT)
2943
rm -f convert_gen.h
30-
rm -rf lib-ruby-parser-cpp-bindings/target
31-
cd build-convert && cargo clean
44+
45+
# // cpp bindings files
46+
47+
update-cpp-bindings:
48+
wget $(LIB_RUBY_PARSER_H_URL) -O lib-ruby-parser.h
49+
wget $(LIB_RUBY_PARSER_A_URL) -O lib-ruby-parser.a

binding.gyp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"targets": [
33
{
44
"target_name": "ruby_parser",
5-
"sources": [ "lib-ruby-parser.cc" ],
5+
"sources": [ "node_bindings.cc" ],
66
"include_dirs": [
77
"<!@(node -p \"require('node-addon-api').include\")",
8-
"lib-ruby-parser-cpp-bindings/includes"
8+
"."
99
],
10-
"libraries": [ "../lib-ruby-parser-cpp-bindings/target/lib-ruby-parser-static-release" ],
10+
"libraries": [ "../lib-ruby-parser.a" ],
1111
"cflags_cc": [ "-std=c++17" ],
1212
"xcode_settings": {
1313
"OTHER_CFLAGS": [ "-std=c++17"],

build-convert/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ version = "0.1.0"
77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[build-dependencies]
10-
lib-ruby-parser-nodes = "0.5.0"
10+
lib-ruby-parser-nodes = "0.8.0"

convert.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ namespace lib_ruby_parser_node
203203
case MagicCommentKind::WARN_INDENT:
204204
kind = String::New(env, "warn-indent");
205205
break;
206+
case MagicCommentKind::SHAREABLE_CONSTANT_VALUE:
207+
kind = String::New(env, "shareable-constant-value");
208+
break;
206209
}
207210
return MagicCommentCtor.New({
208211
kind,
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ namespace lib_ruby_parser_node
2828
}
2929

3030
std::string source = arg.As<String>().Utf8Value();
31-
auto result = ParserResult::from_source(source);
31+
ParserOptions options;
32+
options.record_tokens = true;
33+
auto result = ParserResult::from_source(source, std::move(options));
3234
return convert(std::move(result), env);
3335
}
3436

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,5 @@
44
"description": "bindings to lib-ruby-parser",
55
"dependencies": {
66
"node-addon-api": "^1.5.0"
7-
},
8-
"scripts": {
9-
"preinstall": "make build-deps"
107
}
118
}

0 commit comments

Comments
 (0)