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

Commit 2d31094

Browse files
authored
Merge pull request #3 from lib-ruby-parser/build-on-windows
build on windows
2 parents bd35eed + ba5ea5d commit 2d31094

File tree

4 files changed

+65
-45
lines changed

4 files changed

+65
-45
lines changed

.github/workflows/test.yml

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
env:
1010
CARGO_TERM_COLOR: always
11+
BUILD_ENV: release
1112

1213
jobs:
1314
test:
@@ -16,11 +17,12 @@ jobs:
1617
strategy:
1718
matrix:
1819
node: [ '10', '12', '14', '15' ]
19-
os: [ ubuntu-latest, macos-latest ]
20+
os: [ ubuntu-latest, macos-latest, windows-latest ]
2021
steps:
21-
- name: set NPM_CONFIG_PREFIX
22-
run: |
23-
echo "NPM_CONFIG_PREFIX=$HOME/.npm-global" >> $GITHUB_ENV
22+
- name: install wget
23+
if: runner.os == 'Windows'
24+
shell: bash
25+
run: choco install wget --no-progress
2426

2527
- name: checkout
2628
uses: actions/checkout@v2
@@ -37,29 +39,17 @@ jobs:
3739
with:
3840
node-version: ${{ matrix.node }}
3941

40-
- name: configure NPM_CONFIG_PREFIX
41-
run: |
42-
npm config set prefix $NPM_CONFIG_PREFIX
43-
mkdir -p $NPM_CONFIG_PREFIX/bin
44-
mkdir -p $NPM_CONFIG_PREFIX/lib
45-
echo "$NPM_CONFIG_PREFIX/bin" >> $GITHUB_PATH
46-
47-
- name: install node-gyp
42+
- name: build
43+
shell: bash
4844
run: |
49-
npm install -g node-gyp
50-
echo $PATH
51-
which node-gyp
52-
53-
- name: npm install
54-
run: npm install --ignore-scripts
45+
make setup
46+
make download-cpp-bindings
47+
make generate-node-bindings
5548
56-
- name: configure
57-
run: |
58-
make update-cpp-bindings
59-
make generate-bindings
6049
make configure
50+
make build
6151
6252
- name: Run tests
53+
shell: bash
6354
run: |
64-
make build
6555
make test

Makefile

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
1-
UNAME_S := $(shell uname -s)
2-
ifeq ($(UNAME_S),Linux)
3-
PLATFORM = linux-x86_64
1+
ifeq ($(OS), Windows_NT)
2+
DETECTED_OS = Windows
3+
else
4+
UNAME_S := $(shell uname -s)
5+
ifeq ($(UNAME_S), Linux)
6+
DETECTED_OS = Linux
7+
else
8+
ifeq ($(UNAME_S), Darwin)
9+
DETECTED_OS = Darwin
10+
else
11+
DETECTED_OS = Unknown
12+
endif
13+
endif
14+
endif
15+
16+
ifeq ($(DETECTED_OS), Windows)
17+
LIB_ASSET_NAME = lib-ruby-parser-x86_64-pc-windows-msvc.lib
18+
LOCAL_LIB_NAME = lib-ruby-parser.lib
419
endif
5-
ifeq ($(UNAME_S),Darwin)
6-
PLATFORM = darwin-x86_64
20+
ifeq ($(DETECTED_OS), Linux)
21+
LIB_ASSET_NAME = lib-ruby-parser-x86_64-unknown-linux-gnu.a
22+
LOCAL_LIB_NAME = lib-ruby-parser.a
23+
endif
24+
ifeq ($(UNAME_S), Darwin)
25+
LIB_ASSET_NAME = lib-ruby-parser-x86_64-apple-darwin.a
26+
LOCAL_LIB_NAME = lib-ruby-parser.a
727
endif
828

9-
VERSION = 3.0.0-3.3
29+
VERSION = 3.0.0-3.4
1030

1131
ifndef BUILD_ENV
1232
BUILD_ENV = debug
@@ -21,18 +41,22 @@ else
2141
endif
2242

2343
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
44+
HEADER_URL = $(ASSET_PREFIX)/lib-ruby-parser.h
45+
LIB_URL = $(ASSET_PREFIX)/$(LIB_ASSET_NAME)
46+
47+
setup:
48+
npm install --ignore-scripts
49+
npm install node-gyp --no-save
2650

2751
configure:
28-
node-gyp configure
52+
node ./node_modules/node-gyp/bin/node-gyp.js configure
2953

30-
generate-bindings:
54+
generate-node-bindings:
3155
cd build-convert && cargo build
3256

3357
.PHONY: build
3458
build:
35-
node-gyp build $(NODE_GYP_FLAGS)
59+
node ./node_modules/node-gyp/bin/node-gyp.js build $(NODE_GYP_FLAGS)
3660

3761
GYP_OUTPUT = ./build/$(GYP_ENV)/ruby_parser.node
3862
test:
@@ -44,6 +68,6 @@ clean:
4468

4569
# // cpp bindings files
4670

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
71+
download-cpp-bindings:
72+
wget -q $(HEADER_URL) -O lib-ruby-parser.h
73+
wget -q $(LIB_URL) -O $(LOCAL_LIB_NAME)

binding.gyp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,21 @@
77
"<!@(node -p \"require('node-addon-api').include\")",
88
"."
99
],
10-
"libraries": [ "../lib-ruby-parser.a" ],
1110
"cflags_cc": [ "-std=c++17" ],
1211
"xcode_settings": {
1312
"OTHER_CFLAGS": [ "-std=c++17"],
1413
},
14+
"msvs_settings": {
15+
"VCCLCompilerTool": {
16+
"AdditionalOptions": ["/std:c++17"]
17+
}
18+
},
1519
"defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS" ],
20+
"conditions": [
21+
['OS=="mac"', { "libraries": ["../lib-ruby-parser.a"] }],
22+
['OS=="linux"', { "libraries": ["../lib-ruby-parser.a"] }],
23+
['OS=="win"', { "libraries": ["../lib-ruby-parser.lib"] }],
24+
]
1625
}
1726
]
1827
}

build-convert/build.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ fn relative_path(path: &str) -> String {
1515

1616
fn build_comparison(node: &Node) -> String {
1717
format!(
18-
"if constexpr (std::is_same_v<T, std::unique_ptr<lib_ruby_parser::{class_name}>>)
19-
return convert(std::move(inner), env);",
18+
"if constexpr (std::is_same_v<T, std::unique_ptr<lib_ruby_parser::{class_name}>>) {{
19+
return convert(std::move(inner), env);
20+
}}",
2021
class_name = node.struct_name
2122
)
2223
}
@@ -159,8 +160,6 @@ namespace lib_ruby_parser_node
159160
return std::visit([env](auto &&inner) -> Napi::Value {{
160161
using T = std::decay_t<decltype(inner)>;
161162
{comparisons}
162-
else
163-
static_assert(always_false_v<T>, \"non-exhaustive visitor!\");
164163
}}, node->inner);
165164
}}
166165
@@ -169,8 +168,6 @@ namespace lib_ruby_parser_node
169168
return std::visit([env](auto &&inner) {{
170169
using T = std::decay_t<decltype(inner)>;
171170
{comparisons}
172-
else
173-
static_assert(always_false_v<T>, \"non-exhaustive visitor!\");
174171
}}, node.inner);
175172
}}
176173
@@ -184,7 +181,7 @@ namespace lib_ruby_parser_node
184181
#endif // LIB_RUBY_PARSER_CONVERT_GEN_H
185182
",
186183
converters = converters.join("\n "),
187-
comparisons = comparisons.join("\n else "),
184+
comparisons = comparisons.join("\n "),
188185
ctor_definitions = ctor_definitions.join("\n "),
189186
ctor_fn_definitions = ctor_fn_definitions.join("\n "),
190187
init_exports = init_exports.join("\n ")

0 commit comments

Comments
 (0)