Skip to content

Commit d087d28

Browse files
committed
CMake: allow building with host-provided third-party dependencies
quick-lint-js relies on some third-party dependencies, such as Google Benchmark and simdjson. quick-lint-js' build system currently builds a vendored copy of these dependencies from source. This is undesirable for package managers. Allow package managers to use their versions of dependencies by specifying -DQUICK_LINT_JS_USE_BUNDLED_BOOST=NO, etc. when running CMake.
1 parent f185a94 commit d087d28

File tree

7 files changed

+318
-146
lines changed

7 files changed

+318
-146
lines changed

.github/workflows/unvendored.yml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Copyright (C) 2020 Matthew Glazar
2+
# See end of file for extended copyright information.
3+
4+
name: build unvendored
5+
on:
6+
push:
7+
pull_request:
8+
types: [opened, synchronize]
9+
10+
jobs:
11+
arch-linux:
12+
name: Arch Linux
13+
runs-on: ubuntu-latest
14+
container: archlinux:base
15+
steps:
16+
- name: install dependencies
17+
run: |
18+
pacman -Syyuu --noconfirm \
19+
base-devel \
20+
benchmark \
21+
boost \
22+
cmake \
23+
git \
24+
gtest \
25+
sudo
26+
27+
# HACK(strager): Create a user so we can run makepkg. makepkg refuses
28+
# to run as root.
29+
useradd arch-builder
30+
printf 'arch-builder ALL=(ALL) NOPASSWD: ALL\n' >/etc/sudoers.d/arch-builder
31+
32+
sudo -u arch-builder sh -e -c '
33+
git clone https://aur.archlinux.org/simdjson.git /tmp/aur-simdjson
34+
cd /tmp/aur-simdjson
35+
makepkg --syncdeps --install --noconfirm
36+
'
37+
38+
- name: checkout
39+
uses: actions/checkout@v2
40+
41+
- name: configure
42+
run: |
43+
# HACK(strager): QUICK_LINT_JS_HAVE_WORKING_CHAR8_T is needed because
44+
# Arch's gmock doesn't link with -fchar8_t.
45+
cmake \
46+
-DCMAKE_BUILD_TYPE=Debug \
47+
-DBUILD_TESTING=YES \
48+
-DQUICK_LINT_JS_ENABLE_BENCHMARKS=YES \
49+
-DQUICK_LINT_JS_HAVE_WORKING_FCHAR8_T=NO \
50+
-DQUICK_LINT_JS_USE_BUNDLED_BOOST=NO \
51+
-DQUICK_LINT_JS_USE_BUNDLED_GOOGLE_BENCHMARK=NO \
52+
-DQUICK_LINT_JS_USE_BUNDLED_GOOGLE_TEST=NO \
53+
-DQUICK_LINT_JS_USE_BUNDLED_SIMDJSON=NO \
54+
-S . -B .
55+
shell: bash
56+
- name: build
57+
run: cmake --build . --config Debug
58+
- name: test
59+
run: ctest --build-config Debug --verbose
60+
61+
ubuntu:
62+
name: Ubuntu 20.04
63+
runs-on: ubuntu-20.04
64+
steps:
65+
- name: install dependencies
66+
run: |
67+
DEBIAN_FRONTEND=noninteractive sudo apt-get install -y \
68+
libgmock-dev \
69+
libgtest-dev
70+
71+
- name: checkout
72+
uses: actions/checkout@v2
73+
74+
- name: configure
75+
run: |
76+
# TODO(strager): Use host Google Benchmark after this bug is fixed:
77+
# https://bugs.launchpad.net/ubuntu/+source/benchmark/+bug/1887872
78+
# TODO(strager): Use host Boost after Ubuntu upgrades to version 1.75
79+
# or newer:
80+
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=978748#15
81+
# TODO(strager): Use host simdjson after Ubuntu imports a stable
82+
# version from Debian.
83+
cmake \
84+
-DCMAKE_EXE_LINKER_FLAGS=-ffat-lto-objects \
85+
-DCMAKE_BUILD_TYPE=Debug \
86+
-DBUILD_TESTING=YES \
87+
-DQUICK_LINT_JS_ENABLE_BENCHMARKS=YES \
88+
-DQUICK_LINT_JS_USE_BUNDLED_GOOGLE_TEST=NO \
89+
-S . -B .
90+
shell: bash
91+
- name: build
92+
run: cmake --build . --config Debug
93+
- name: test
94+
run: ctest --build-config Debug --verbose
95+
96+
# quick-lint-js finds bugs in JavaScript programs.
97+
# Copyright (C) 2020 Matthew Glazar
98+
#
99+
# This file is part of quick-lint-js.
100+
#
101+
# quick-lint-js is free software: you can redistribute it and/or modify
102+
# it under the terms of the GNU General Public License as published by
103+
# the Free Software Foundation, either version 3 of the License, or
104+
# (at your option) any later version.
105+
#
106+
# quick-lint-js is distributed in the hope that it will be useful,
107+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
108+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
109+
# GNU General Public License for more details.
110+
#
111+
# You should have received a copy of the GNU General Public License
112+
# along with quick-lint-js. If not, see <https://www.gnu.org/licenses/>.

CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,27 @@ option(
5656
OFF
5757
)
5858

59+
option(
60+
QUICK_LINT_JS_USE_BUNDLED_BOOST
61+
"Use the third-party Boost library bundled with quick-lint-js instead of using the host-installed Boost"
62+
ON
63+
)
64+
option(
65+
QUICK_LINT_JS_USE_BUNDLED_GOOGLE_BENCHMARK
66+
"Use the third-party Google Benchmark library bundled with quick-lint-js instead of using the host-installed Google Benchmark"
67+
ON
68+
)
69+
option(
70+
QUICK_LINT_JS_USE_BUNDLED_GOOGLE_TEST
71+
"Use the third-party Google Test library bundled with quick-lint-js instead of using the host-installed Google Test"
72+
ON
73+
)
74+
option(
75+
QUICK_LINT_JS_USE_BUNDLED_SIMDJSON
76+
"Use the third-party simdjson library bundled with quick-lint-js instead of using the host-installed simdjson"
77+
ON
78+
)
79+
5980
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
6081

6182
include(QuickLintJSCompiler)

src/padded-string.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <quick-lint-js/char8.h>
1010
#include <quick-lint-js/narrow-cast.h>
1111
#include <quick-lint-js/padded-string.h>
12-
#include <simdjson/common_defs.h>
12+
#include <simdjson.h>
1313
#include <string>
1414
#include <utility>
1515

vendor/benchmark.cmake

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,51 @@
11
# Copyright (C) 2020 Matthew "strager" Glazar
22
# See end of file for extended copyright information.
33

4-
set(BENCHMARK_DOWNLOAD_DEPENDENCIES FALSE CACHE INTERNAL "")
5-
set(BENCHMARK_ENABLE_ASSEMBLY_TEST FALSE CACHE INTERNAL "")
6-
set(BENCHMARK_ENABLE_GTEST_TESTS FALSE CACHE INTERNAL "")
7-
set(BENCHMARK_ENABLE_INSTALL FALSE CACHE INTERNAL "")
8-
set(BENCHMARK_ENABLE_LTO FALSE CACHE INTERNAL "")
9-
set(BENCHMARK_ENABLE_TESTING FALSE CACHE INTERNAL "")
10-
set(BENCHMARK_USE_LIBCXX FALSE CACHE INTERNAL "")
4+
if (QUICK_LINT_JS_USE_BUNDLED_GOOGLE_BENCHMARK)
5+
set(BENCHMARK_DOWNLOAD_DEPENDENCIES FALSE CACHE INTERNAL "")
6+
set(BENCHMARK_ENABLE_ASSEMBLY_TEST FALSE CACHE INTERNAL "")
7+
set(BENCHMARK_ENABLE_GTEST_TESTS FALSE CACHE INTERNAL "")
8+
set(BENCHMARK_ENABLE_INSTALL FALSE CACHE INTERNAL "")
9+
set(BENCHMARK_ENABLE_LTO FALSE CACHE INTERNAL "")
10+
set(BENCHMARK_ENABLE_TESTING FALSE CACHE INTERNAL "")
11+
set(BENCHMARK_USE_LIBCXX FALSE CACHE INTERNAL "")
1112

12-
if (MSVC)
13-
# HACK(strager): Disable MSVC warnings when compiling benchmark and
14-
# benchmark_main:
15-
# * D9025: overriding '/EHs' with '/EHs-'
16-
set(BENCHMARK_ENABLE_EXCEPTIONS TRUE CACHE INTERNAL "")
17-
else ()
18-
set(BENCHMARK_ENABLE_EXCEPTIONS FALSE CACHE INTERNAL "")
19-
endif ()
13+
if (MSVC)
14+
# HACK(strager): Disable MSVC warnings when compiling benchmark and
15+
# benchmark_main:
16+
# * D9025: overriding '/EHs' with '/EHs-'
17+
set(BENCHMARK_ENABLE_EXCEPTIONS TRUE CACHE INTERNAL "")
18+
else ()
19+
set(BENCHMARK_ENABLE_EXCEPTIONS FALSE CACHE INTERNAL "")
20+
endif ()
2021

21-
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/benchmark")
22+
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/benchmark")
2223

23-
# HACK(strager): Avoid 'function can be marked override' warnings
24-
# (-Wsuggest-override) when including <benchmark/benchmark.h>.
25-
get_property(
26-
BENCHMARK_INCLUDE_DIRECTORIES
27-
TARGET benchmark
28-
PROPERTY INTERFACE_INCLUDE_DIRECTORIES
29-
)
30-
set_property(
31-
TARGET benchmark
32-
APPEND PROPERTY
33-
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES
34-
"${BENCHMARK_INCLUDE_DIRECTORIES}"
35-
)
24+
# HACK(strager): Avoid 'function can be marked override' warnings
25+
# (-Wsuggest-override) when including <benchmark/benchmark.h>.
26+
get_property(
27+
BENCHMARK_INCLUDE_DIRECTORIES
28+
TARGET benchmark
29+
PROPERTY INTERFACE_INCLUDE_DIRECTORIES
30+
)
31+
set_property(
32+
TARGET benchmark
33+
APPEND PROPERTY
34+
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES
35+
"${BENCHMARK_INCLUDE_DIRECTORIES}"
36+
)
3637

37-
# HACK(strager): sysinfo.cc needs some Windows headers. Some headers in Windows
38-
# SDK version 10.0.17763.0 contain invalid code which causes the
39-
# standards-compliant preprocessor to generate invalid C++ code. Use the legacy
40-
# peprocessor.
41-
if (QUICK_LINT_JS_HAVE_ZC_PREPROCESSOR_CXX)
42-
target_compile_options(benchmark PRIVATE /Zc:preprocessor-)
43-
elseif (QUICK_LINT_JS_HAVE_EXPERIMENTAL_PREPROCESSOR_CXX)
44-
target_compile_options(benchmark PRIVATE /experimental:preprocessor-)
38+
# HACK(strager): sysinfo.cc needs some Windows headers. Some headers in Windows
39+
# SDK version 10.0.17763.0 contain invalid code which causes the
40+
# standards-compliant preprocessor to generate invalid C++ code. Use the legacy
41+
# peprocessor.
42+
if (QUICK_LINT_JS_HAVE_ZC_PREPROCESSOR_CXX)
43+
target_compile_options(benchmark PRIVATE /Zc:preprocessor-)
44+
elseif (QUICK_LINT_JS_HAVE_EXPERIMENTAL_PREPROCESSOR_CXX)
45+
target_compile_options(benchmark PRIVATE /experimental:preprocessor-)
46+
endif ()
47+
else ()
48+
find_package(benchmark REQUIRED)
4549
endif ()
4650

4751
# quick-lint-js finds bugs in JavaScript programs.

vendor/boost.cmake

Lines changed: 61 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,73 @@
11
# Copyright (C) 2020 Matthew "strager" Glazar
22
# See end of file for extended copyright information.
33

4-
include(CheckCXXCompilerFlag)
4+
if (QUICK_LINT_JS_USE_BUNDLED_BOOST)
5+
include(CheckCXXCompilerFlag)
56

6-
add_library(
7-
boost
8-
"${CMAKE_CURRENT_LIST_DIR}/boost/libs/container/src/alloc_lib.c"
9-
"${CMAKE_CURRENT_LIST_DIR}/boost/libs/container/src/dlmalloc.cpp"
10-
"${CMAKE_CURRENT_LIST_DIR}/boost/libs/container/src/global_resource.cpp"
11-
"${CMAKE_CURRENT_LIST_DIR}/boost/libs/container/src/monotonic_buffer_resource.cpp"
12-
"${CMAKE_CURRENT_LIST_DIR}/boost/libs/container/src/pool_resource.cpp"
13-
"${CMAKE_CURRENT_LIST_DIR}/boost/libs/container/src/synchronized_pool_resource.cpp"
14-
"${CMAKE_CURRENT_LIST_DIR}/boost/libs/container/src/unsynchronized_pool_resource.cpp"
15-
)
16-
# NOTE(strager): SYSTEM disable undesirable warnings in Boost header files.
17-
target_include_directories(boost SYSTEM PUBLIC "${CMAKE_CURRENT_LIST_DIR}/boost")
18-
target_compile_definitions(
19-
boost
20-
PUBLIC
21-
BOOST_ALL_NO_LIB
22-
BOOST_CONTAINER_NO_LIB
23-
BOOST_JSON_STANDALONE
24-
BOOST_JSON_USE_BOOST_PMR
25-
BOOST_LEAF_NO_EXCEPTIONS
26-
BOOST_NO_EXCEPTIONS
27-
)
28-
# Disable undesirable warnings in headers and source files.
29-
quick_lint_js_add_warning_options_if_supported(
30-
boost
31-
PRIVATE
32-
-Wno-null-pointer-arithmetic
33-
)
34-
35-
# Allow the entire project to be compiled with -fno-rtti. Boost uses
36-
# dynamic_cast which requires RTTI, so forcefully enable RTTI for Boost.
37-
check_cxx_compiler_flag(-frtti QUICK_LINT_JS_HAVE_FRTTI)
38-
if (QUICK_LINT_JS_HAVE_FRTTI)
39-
target_compile_options(
7+
add_library(
8+
boost
9+
"${CMAKE_CURRENT_LIST_DIR}/boost/libs/container/src/alloc_lib.c"
10+
"${CMAKE_CURRENT_LIST_DIR}/boost/libs/container/src/dlmalloc.cpp"
11+
"${CMAKE_CURRENT_LIST_DIR}/boost/libs/container/src/global_resource.cpp"
12+
"${CMAKE_CURRENT_LIST_DIR}/boost/libs/container/src/monotonic_buffer_resource.cpp"
13+
"${CMAKE_CURRENT_LIST_DIR}/boost/libs/container/src/pool_resource.cpp"
14+
"${CMAKE_CURRENT_LIST_DIR}/boost/libs/container/src/synchronized_pool_resource.cpp"
15+
"${CMAKE_CURRENT_LIST_DIR}/boost/libs/container/src/unsynchronized_pool_resource.cpp"
16+
)
17+
# NOTE(strager): SYSTEM disable undesirable warnings in Boost header files.
18+
target_include_directories(boost SYSTEM PUBLIC "${CMAKE_CURRENT_LIST_DIR}/boost")
19+
target_compile_definitions(
20+
boost
21+
PUBLIC
22+
BOOST_ALL_NO_LIB
23+
BOOST_CONTAINER_NO_LIB
24+
BOOST_JSON_STANDALONE
25+
BOOST_JSON_USE_BOOST_PMR
26+
BOOST_LEAF_NO_EXCEPTIONS
27+
BOOST_NO_EXCEPTIONS
28+
)
29+
# Disable undesirable warnings in headers and source files.
30+
quick_lint_js_add_warning_options_if_supported(
4031
boost
4132
PRIVATE
42-
$<$<COMPILE_LANGUAGE:CXX>:-frtti>
33+
-Wno-null-pointer-arithmetic
4334
)
44-
endif ()
4535

46-
if (EMSCRIPTEN)
47-
# HACK(strager): In STANDALONE_WASM mode, emscripten generates calls to
48-
# clock_time_get, originating from Boost. As of Node.js version v12.20.0, such
49-
# calls require Node to be run with --experimental-wasm-bigint. Without this
50-
# flag, clock_time_get calls fail with the following message:
51-
#
52-
# > Error: TypeError: wasm function signature contains illegal type
53-
#
54-
# Our Visual Studio Code plugin cannot enable this Node.js flag itself. Work
55-
# around emscripten's code gen by avoiding the call to clock_time_get in
56-
# Boost's dlmalloc.
57-
target_compile_definitions(boost PRIVATE LACKS_TIME_H)
58-
endif ()
36+
# Allow the entire project to be compiled with -fno-rtti. Boost uses
37+
# dynamic_cast which requires RTTI, so forcefully enable RTTI for Boost.
38+
check_cxx_compiler_flag(-frtti QUICK_LINT_JS_HAVE_FRTTI)
39+
if (QUICK_LINT_JS_HAVE_FRTTI)
40+
target_compile_options(
41+
boost
42+
PRIVATE
43+
$<$<COMPILE_LANGUAGE:CXX>:-frtti>
44+
)
45+
endif ()
5946

60-
# Keep boost_json as a separate library so we can use it only in tests (and not
61-
# compile and link it into production executables).
62-
add_library(boost_json STATIC "${CMAKE_CURRENT_LIST_DIR}/boost-json.cpp")
63-
target_link_libraries(boost_json PUBLIC boost)
47+
if (EMSCRIPTEN)
48+
# HACK(strager): In STANDALONE_WASM mode, emscripten generates calls to
49+
# clock_time_get, originating from Boost. As of Node.js version v12.20.0, such
50+
# calls require Node to be run with --experimental-wasm-bigint. Without this
51+
# flag, clock_time_get calls fail with the following message:
52+
#
53+
# > Error: TypeError: wasm function signature contains illegal type
54+
#
55+
# Our Visual Studio Code plugin cannot enable this Node.js flag itself. Work
56+
# around emscripten's code gen by avoiding the call to clock_time_get in
57+
# Boost's dlmalloc.
58+
target_compile_definitions(boost PRIVATE LACKS_TIME_H)
59+
endif ()
60+
61+
# Keep boost_json as a separate library so we can use it only in tests (and not
62+
# compile and link it into production executables).
63+
add_library(boost_json STATIC "${CMAKE_CURRENT_LIST_DIR}/boost-json.cpp")
64+
target_link_libraries(boost_json PUBLIC boost)
65+
else ()
66+
find_package(Boost REQUIRED COMPONENTS container json)
67+
add_library(boost INTERFACE)
68+
target_link_libraries(boost INTERFACE Boost::boost Boost::container)
69+
add_library(boost_json ALIAS Boost::json)
70+
endif ()
6471

6572
# quick-lint-js finds bugs in JavaScript programs.
6673
# Copyright (C) 2020 Matthew "strager" Glazar

0 commit comments

Comments
 (0)