Skip to content

Commit 2a6d391

Browse files
committed
build: add recipes for installing LLVM
1 parent 22b1ac8 commit 2a6d391

File tree

5 files changed

+314
-0
lines changed

5 files changed

+314
-0
lines changed

deps/test/llvm/test_install.c

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
double add( double x, double y ) {
20+
return x + y;
21+
}

tools/make/common.mk

+12
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,18 @@ ifeq (, $(BLAS_DIR))
490490
endif
491491
endif
492492

493+
# Define the output path when building LLVM:
494+
DEPS_LLVM_BUILD_OUT ?= $(DEPS_BUILD_DIR)/llvm
495+
496+
# Define the LLVM version:
497+
DEPS_LLVM_VERSION ?=
498+
499+
# Define the path to clang compiler:
500+
DEPS_LLVM_CLANG ?= $(DEPS_LLVM_BUILD_OUT)/build/bin/clang
501+
502+
# Define the path to LLVM static compiler:
503+
DEPS_LLVM_LLC ?= $(DEPS_LLVM_BUILD_OUT)/build/bin/llc
504+
493505
# Define the output path when building the Emscripten SDK:
494506
DEPS_EMSDK_BUILD_OUT ?= $(DEPS_BUILD_DIR)/emsdk
495507

tools/make/lib/install/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ include $(TOOLS_MAKE_LIB_DIR)/install/cephes.mk
3939
include $(TOOLS_MAKE_LIB_DIR)/install/cppcheck.mk
4040
include $(TOOLS_MAKE_LIB_DIR)/install/electron.mk
4141
include $(TOOLS_MAKE_LIB_DIR)/install/emsdk.mk
42+
include $(TOOLS_MAKE_LIB_DIR)/install/llvm.mk
4243
include $(TOOLS_MAKE_LIB_DIR)/install/node.mk
4344
include $(TOOLS_MAKE_LIB_DIR)/install/openblas.mk
4445
include $(TOOLS_MAKE_LIB_DIR)/install/python_deps.mk

tools/make/lib/install/README.md

+33
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ This directory contains [`make`][make] rules for running the project's installat
3737
- [Cppcheck](#cppcheck)
3838
- [Electron](#electron)
3939
- [Emscripten SDK](#emscripten-sdk)
40+
- [LLVM](#llvm)
4041
- [OpenBLAS](#openblas)
4142
- [Python](#python)
4243
- [R](#r)
@@ -419,6 +420,36 @@ $ make clean-deps-emscripten-tests
419420

420421
* * *
421422

423+
<a name="llvm"></a>
424+
425+
### LLVM
426+
427+
#### install-deps-llvm
428+
429+
Installs [LLVM][llvm].
430+
431+
```bash
432+
$ make install-deps-llvm
433+
```
434+
435+
#### clean-deps-llvm
436+
437+
Removes an installed [LLVM][llvm] distribution.
438+
439+
```bash
440+
$ make clean-deps-llvm
441+
```
442+
443+
#### clean-deps-llvm-tests
444+
445+
Removes [LLVM][llvm] installation tests.
446+
447+
```bash
448+
$ make clean-deps-llvm-tests
449+
```
450+
451+
* * *
452+
422453
<a name="openblas"></a>
423454

424455
### OpenBLAS
@@ -595,6 +626,8 @@ $ make clean-deps-wabt-tests
595626

596627
[emscripten-sdk]: https://github.com/emscripten-core/emsdk
597628

629+
[llvm]: https://llvm.org
630+
598631
[node-js]: https://nodejs.org/en/
599632

600633
[node-js-add-ons]: https://nodejs.org/api/addons.html

tools/make/lib/install/llvm.mk

+247
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
#/
2+
# @license Apache-2.0
3+
#
4+
# Copyright (c) 2017 The Stdlib Authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#/
18+
19+
# VARIABLES #
20+
21+
# Define the path to an executable for checking CMake:
22+
DEPS_CHECK_CMAKE ?= $(TOOLS_DIR)/scripts/check_cmake
23+
24+
# Define the path to an executable for checking git:
25+
DEPS_CHECK_GIT ?= $(TOOLS_DIR)/scripts/check_git
26+
27+
# Define the path to an executable for checking Python:
28+
DEPS_CHECK_PYTHON ?= $(TOOLS_DIR)/scripts/check_python
29+
30+
# Define the download URL:
31+
DEPS_LLVM_URL ?= https://github.com/llvm/llvm-project.git
32+
33+
# Determine the basename for the download:
34+
deps_llvm_basename := llvm
35+
36+
# Define the path to the file containing a checksum to verify a download:
37+
DEPS_LLVM_CHECKSUM ?= $(shell $(CAT) $(DEPS_CHECKSUMS_DIR)/$(subst .,_,$(deps_llvm_basename))/sha256)
38+
39+
# Define the output path when downloading:
40+
DEPS_LLVM_DOWNLOAD_OUT ?= $(DEPS_TMP_DIR)/$(deps_llvm_basename)
41+
42+
# Define the output path after extracting:
43+
deps_llvm_extract_out := $(DEPS_BUILD_DIR)/llvm_extracted
44+
45+
# Define the path to the directory containing tests:
46+
DEPS_LLVM_TEST_DIR ?= $(DEPS_DIR)/test/llvm
47+
48+
# Define the output directory path for compiled tests:
49+
DEPS_LLVM_TEST_OUT ?= $(DEPS_LLVM_TEST_DIR)/build
50+
51+
# Define the path to a test file for checking an installation:
52+
DEPS_LLVM_TEST_INSTALL ?= $(DEPS_LLVM_TEST_DIR)/test_install.c
53+
54+
# Define output paths for a compiled test file:
55+
DEPS_LLVM_TEST_INSTALL_WASM_OUT ?= $(DEPS_LLVM_TEST_OUT)/test.wasm
56+
57+
58+
# RULES #
59+
60+
#/
61+
# Downloads LLVM.
62+
#
63+
# @private
64+
#/
65+
$(DEPS_LLVM_DOWNLOAD_OUT): | $(DEPS_TMP_DIR)
66+
$(QUIET) echo 'Downloading LLVM...' >&2
67+
$(QUIET) $(GIT) clone --depth=1 $(DEPS_LLVM_URL) $(DEPS_LLVM_DOWNLOAD_OUT)
68+
69+
#/
70+
# Extracts an LLVM download.
71+
#
72+
# @private
73+
#/
74+
$(DEPS_LLVM_BUILD_OUT): | $(DEPS_BUILD_DIR) $(DEPS_LLVM_DOWNLOAD_OUT)
75+
$(QUIET) echo 'Extracting LLVM...' >&2
76+
$(QUIET) $(CP) -a $(DEPS_LLVM_DOWNLOAD_OUT) $(deps_llvm_extract_out)
77+
$(QUIET) mv $(deps_llvm_extract_out) $(DEPS_LLVM_BUILD_OUT)
78+
79+
#/
80+
# Creates a directory for storing compiled LLVM tests.
81+
#
82+
# @private
83+
#/
84+
$(DEPS_LLVM_TEST_OUT):
85+
$(QUIET) $(MKDIR_RECURSIVE) $(DEPS_LLVM_TEST_OUT)
86+
87+
#/
88+
# Compiles a WebAssembly test file for testing an LLVM installation.
89+
#
90+
# @private
91+
#/
92+
$(DEPS_LLVM_TEST_INSTALL_WASM_OUT): $(DEPS_LLVM_BUILD_OUT) $(DEPS_LLVM_TEST_OUT)
93+
$(QUIET) $(DEPS_LLVM_CLANG) $(DEPS_LLVM_TEST_INSTALL) \
94+
--target=wasm32 \
95+
--no-standard-libraries \
96+
-Wl,--export-all \
97+
-Wl,--no-entry \
98+
-o $(DEPS_LLVM_TEST_INSTALL_WASM_OUT)
99+
100+
#/
101+
# Downloads LLVM.
102+
#
103+
# @private
104+
#
105+
# @example
106+
# make deps-download-llvm
107+
#/
108+
deps-download-llvm: $(DEPS_LLVM_DOWNLOAD_OUT)
109+
110+
.PHONY: deps-download-llvm
111+
112+
#/
113+
# Verifies an LLVM download.
114+
#
115+
# @private
116+
#
117+
# @example
118+
# make deps-verify-llvm
119+
#/
120+
deps-verify-llvm: deps-download-llvm
121+
$(QUIET) echo 'Verifying download...' >&2
122+
$(QUIET) echo 'Nothing to verify.' >&2
123+
124+
.PHONY: deps-verify-llvm
125+
126+
#/
127+
# Extracts an LLVM download.
128+
#
129+
# @private
130+
#
131+
# @example
132+
# make deps-extract-llvm
133+
#/
134+
deps-extract-llvm: $(DEPS_LLVM_BUILD_OUT)
135+
136+
.PHONY: deps-extract-llvm
137+
138+
#/
139+
# Checks a host system for LLVM installation prerequisites.
140+
#
141+
# @private
142+
#
143+
# @example
144+
# make deps-prerequisites-llvm
145+
#/
146+
deps-prerequisites-llvm:
147+
$(QUIET) $(DEPS_CHECK_CMAKE)
148+
$(QUIET) $(DEPS_CHECK_GIT)
149+
$(QUIET) $(DEPS_CHECK_PYTHON)
150+
151+
.PHONY: deps-prerequisites-llvm
152+
153+
#/
154+
# Installs LLVM.
155+
#
156+
# @private
157+
#
158+
# @example
159+
# make deps-install-llvm
160+
#/
161+
deps-install-llvm: $(DEPS_LLVM_BUILD_OUT) deps-prerequisites-llvm
162+
$(QUIET) cd $(DEPS_LLVM_BUILD_OUT) && $(MKDIR_RECURSIVE) build
163+
$(QUIET) cd $(DEPS_LLVM_BUILD_OUT)/build && $(CMAKE) -DLLVM_ENABLE_PROJECTS="clang;lld" -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" ../llvm
164+
$(QUIET) cd $(DEPS_LLVM_BUILD_OUT)/build && $(MAKE)
165+
166+
.PHONY: deps-install-llvm
167+
168+
#/
169+
# Updates an installed LLVM.
170+
#
171+
# @private
172+
#
173+
# @example
174+
# make deps-update-llvm
175+
#/
176+
deps-update-llvm: deps-install-llvm deps-test-llvm
177+
178+
.PHONY: deps-update-llvm
179+
180+
#
181+
# Tests an LLVM installation.
182+
#
183+
# @private
184+
#
185+
# @example
186+
# make deps-test-llvm
187+
#/
188+
deps-test-llvm: $(DEPS_LLVM_TEST_INSTALL_WASM_OUT) deps-test-llvm-wasm
189+
$(QUIET) echo '' >&2
190+
$(QUIET) echo 'LLVM info...' >&2
191+
$(QUIET) echo '' >&2
192+
$(QUIET) $(DEPS_LLVM_CLANG) --help >&2
193+
$(QUIET) echo '' >&2
194+
$(QUIET) cd $(DEPS_LLVM_BUILD_OUT)/build && $(MAKE) check-clang
195+
$(QUIET) echo 'Success.' >&2
196+
197+
.PHONY: deps-test-llvm
198+
199+
#/
200+
# Tests an LLVM installation for generating WebAssembly.
201+
#
202+
# @private
203+
#
204+
# @example
205+
# make deps-test-llvm-wasm
206+
#/
207+
deps-test-llvm-wasm: $(DEPS_LLVM_TEST_INSTALL_WASM_OUT)
208+
$(QUIET) echo 'Running wasm tests...' >&2
209+
$(QUIET) echo '' >&2
210+
$(QUIET) echo 'TODO: make test more robust' >&2
211+
$(QUIET) test -f $(DEPS_LLVM_TEST_INSTALL_WASM_OUT) >&2
212+
$(QUIET) echo '' >&2
213+
$(QUIET) echo 'Success.' >&2
214+
215+
.PHONY: deps-test-llvm-wasm
216+
217+
#/
218+
# Installs LLVM.
219+
#
220+
# @example
221+
# make install-deps-llvm
222+
#/
223+
install-deps-llvm: deps-download-llvm deps-verify-llvm deps-extract-llvm deps-install-llvm deps-test-llvm
224+
225+
.PHONY: install-deps-llvm
226+
227+
#/
228+
# Removes an LLVM installation (but does not remove an LLVM download if one exists).
229+
#
230+
# @example
231+
# make clean-deps-llvm
232+
#/
233+
clean-deps-llvm: clean-deps-llvm-tests
234+
$(QUIET) $(DELETE) $(DELETE_FLAGS) $(DEPS_LLVM_BUILD_OUT)
235+
236+
.PHONY: clean-deps-llvm
237+
238+
#/
239+
# Removes LLVM installation tests.
240+
#
241+
# @example
242+
# make clean-deps-llvm-tests
243+
#/
244+
clean-deps-llvm-tests:
245+
$(QUIET) $(DELETE) $(DELETE_FLAGS) $(DEPS_LLVM_TEST_OUT)
246+
247+
.PHONY: clean-deps-llvm-tests

0 commit comments

Comments
 (0)