Skip to content

Commit 0c33897

Browse files
committed
Add fswatch dependency in Savi compiler, for watching file changes.
1 parent 254ed07 commit 0c33897

30 files changed

+933
-9
lines changed

Makefile

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ CLANG_TARGET_PLATFORM?=$(TARGET_PLATFORM)
128128
LLVM_STATIC_RELEASE_URL?=https://github.com/savi-lang/llvm-static/releases/download/20220112
129129
$(eval $(call MAKE_VAR_CACHE_FOR,LLVM_STATIC_RELEASE_URL))
130130

131-
# Specify where to download our pre-built LLVM/clang static libraries from.
132-
# This needs to get bumped explicitly here when we do a new LLVM build.
131+
# Specify where to download our pre-built runtime bitcode from.
132+
# This needs to get bumped explicitly here when we do a new runtime build.
133133
RUNTIME_BITCODE_RELEASE_URL?=https://github.com/savi-lang/runtime-bitcode/releases/download/20220105b
134134
$(eval $(call MAKE_VAR_CACHE_FOR,RUNTIME_BITCODE_RELEASE_URL))
135135

@@ -139,6 +139,11 @@ $(eval $(call MAKE_VAR_CACHE_FOR,RUNTIME_BITCODE_RELEASE_URL))
139139
LLVM_PATH?=$(BUILD)/llvm-static
140140
LLVM_CONFIG?=$(LLVM_PATH)/bin/llvm-config
141141

142+
# Specify where to download the fswatch release source tarball from.
143+
# This needs to get bumped explicitly here to update to a different version.
144+
FSWATCH_RELEASE_URL?=https://github.com/emcrisostomo/fswatch/releases/download/1.16.0/fswatch-1.16.0.tar.gz
145+
$(eval $(call MAKE_VAR_CACHE_FOR,FSWATCH_RELEASE_URL))
146+
142147
# Determine which flavor of the C++ standard library to link against.
143148
# We choose libstdc++ on Linux, and libc++ on FreeBSD and MacOS.
144149
ifneq (,$(findstring linux,$(TARGET_PLATFORM)))
@@ -168,6 +173,21 @@ endif
168173
# including the LLVM extensions C++ file we need to build and link.
169174
CRYSTAL_PATH?=$(shell env $(shell crystal env) printenv CRYSTAL_PATH | rev | cut -d ':' -f 1 | rev)
170175

176+
# Download the fswatch library sourece code to build it.
177+
$(BUILD)/fswatch: $(MAKE_VAR_CACHE)/FSWATCH_RELEASE_URL
178+
rm -rf $@-tmp
179+
mkdir -p $@-tmp
180+
cd $@-tmp && curl -L --fail -sS "${FSWATCH_RELEASE_URL}" \
181+
| tar --strip-components=1 -xzvf -
182+
rm -rf $@
183+
mv $@-tmp $@
184+
touch $@
185+
186+
# Build the static library for the fswatch library sourece code to build it.
187+
LIB_FSWATCH?=$(BUILD)/fswatch/libfswatch/src/libfswatch/.libs/libfswatch.a
188+
$(LIB_FSWATCH): $(BUILD)/fswatch
189+
cd $^ && ./configure && make
190+
171191
# Download the runtime bitcode library we have built separately.
172192
# See github.com/savi-lang/runtime-bitcode for more info.
173193
lib/libsavi_runtime: $(MAKE_VAR_CACHE)/RUNTIME_BITCODE_RELEASE_URL
@@ -260,11 +280,11 @@ $(BUILD)/savi-spec.o: spec/all.cr $(LLVM_PATH) $(shell find src lib spec -name '
260280

261281
# Build the Savi compiler executable, by linking the above targets together.
262282
# This variant of the target compiles in release mode.
263-
$(BUILD)/savi-release: $(BUILD)/savi-release.o $(BUILD)/llvm_ext.bc $(BUILD)/llvm_ext_for_savi.bc lib/libsavi_runtime
283+
$(BUILD)/savi-release: $(BUILD)/savi-release.o $(BUILD)/llvm_ext.bc $(BUILD)/llvm_ext_for_savi.bc lib/libsavi_runtime $(LIB_FSWATCH)
264284
mkdir -p `dirname $@`
265285
${CLANG} -O3 -o $@ -flto=thin -fPIC \
266286
$(BUILD)/savi-release.o $(BUILD)/llvm_ext.bc $(BUILD)/llvm_ext_for_savi.bc \
267-
${CRYSTAL_RT_LIBS} \
287+
${CRYSTAL_RT_LIBS} $(LIB_FSWATCH) \
268288
-target $(CLANG_TARGET_PLATFORM) \
269289
`sh -c 'ls $(LLVM_PATH)/lib/libclang*.a'` \
270290
`sh -c 'ls $(LLVM_PATH)/lib/liblld*.a'` \
@@ -273,11 +293,11 @@ $(BUILD)/savi-release: $(BUILD)/savi-release.o $(BUILD)/llvm_ext.bc $(BUILD)/llv
273293

274294
# Build the Savi compiler executable, by linking the above targets together.
275295
# This variant of the target compiles in debug mode.
276-
$(BUILD)/savi-debug: $(BUILD)/savi-debug.o $(BUILD)/llvm_ext.bc $(BUILD)/llvm_ext_for_savi.bc lib/libsavi_runtime
296+
$(BUILD)/savi-debug: $(BUILD)/savi-debug.o $(BUILD)/llvm_ext.bc $(BUILD)/llvm_ext_for_savi.bc lib/libsavi_runtime $(LIB_FSWATCH)
277297
mkdir -p `dirname $@`
278298
${CLANG} -O0 -o $@ -flto=thin -fPIC \
279299
$(BUILD)/savi-debug.o $(BUILD)/llvm_ext.bc $(BUILD)/llvm_ext_for_savi.bc \
280-
${CRYSTAL_RT_LIBS} \
300+
${CRYSTAL_RT_LIBS} $(LIB_FSWATCH) \
281301
-target $(CLANG_TARGET_PLATFORM) \
282302
`sh -c 'ls $(LLVM_PATH)/lib/libclang*.a'` \
283303
`sh -c 'ls $(LLVM_PATH)/lib/liblld*.a'` \
@@ -287,11 +307,11 @@ $(BUILD)/savi-debug: $(BUILD)/savi-debug.o $(BUILD)/llvm_ext.bc $(BUILD)/llvm_ex
287307

288308
# Build the Savi specs executable, by linking the above targets together.
289309
# This variant of the target will be used when running tests.
290-
$(BUILD)/savi-spec: $(BUILD)/savi-spec.o $(BUILD)/llvm_ext.bc $(BUILD)/llvm_ext_for_savi.bc lib/libsavi_runtime
310+
$(BUILD)/savi-spec: $(BUILD)/savi-spec.o $(BUILD)/llvm_ext.bc $(BUILD)/llvm_ext_for_savi.bc lib/libsavi_runtime $(LIB_FSWATCH)
291311
mkdir -p `dirname $@`
292312
${CLANG} -O0 -o $@ -flto=thin -fPIC \
293313
$(BUILD)/savi-spec.o $(BUILD)/llvm_ext.bc $(BUILD)/llvm_ext_for_savi.bc \
294-
${CRYSTAL_RT_LIBS} \
314+
${CRYSTAL_RT_LIBS} $(LIB_FSWATCH) \
295315
-target $(CLANG_TARGET_PLATFORM) \
296316
`sh -c 'ls $(LLVM_PATH)/lib/libclang*.a'` \
297317
`sh -c 'ls $(LLVM_PATH)/lib/liblld*.a'` \

lib/.shards.info

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ shards:
1313
clang:
1414
git: https://github.com/crystal-lang/clang.cr.git
1515
version: 0.3.0
16+
fswatch:
17+
git: https://github.com/bcardiff/crystal-fswatch.git
18+
version: 0.1.0+git.commit.04aca8703e22fb0ed3d7a39316a49bc0e30eefba

lib/fswatch/.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*.cr]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 2
9+
trim_trailing_whitespace = true

lib/fswatch/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/docs/
2+
/lib/
3+
/bin/
4+
/.shards/
5+
*.dwarf
6+
7+
# Libraries don't need dependency lock
8+
# Dependencies will be locked in applications that use them
9+
/shard.lock

lib/fswatch/.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
language: crystal
2+
3+
# Uncomment the following if you'd like Travis to run specs and check code formatting
4+
# script:
5+
# - crystal spec
6+
# - crystal tool format --check

lib/fswatch/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2020 Brian J. Cardiff
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

lib/fswatch/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# crystal-fswatch
2+
3+
[fswatch](https://emcrisostomo.github.io/fswatch/) bindings for [Crystal](https://crystal-lang.org/)
4+
5+
## Installation
6+
7+
1. Add the dependency to your `shard.yml`:
8+
9+
```yaml
10+
dependencies:
11+
fswatch:
12+
github: bcardiff/crystal-fswatch
13+
```
14+
15+
2. Run `shards install`
16+
17+
## Usage
18+
19+
```crystal
20+
require "fswatch"
21+
22+
FSWatch.watch "." do |event|
23+
pp! event
24+
end
25+
26+
sleep 10 # keep main fiber busy to prevent exiting
27+
```
28+
29+
## Contributing
30+
31+
1. Fork it (<https://github.com/bcardiff/crystal-fswatch/fork>)
32+
2. Create your feature branch (`git checkout -b my-new-feature`)
33+
3. Commit your changes (`git commit -am 'Add some feature'`)
34+
4. Push to the branch (`git push origin my-new-feature`)
35+
5. Create a new Pull Request
36+
37+
## Contributors
38+
39+
- [Brian J. Cardiff](https://github.com/bcardiff) - creator and maintainer

lib/fswatch/docker-compose.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: '3'
2+
3+
services:
4+
ubuntu:
5+
build:
6+
context: ./docker
7+
dockerfile: Dockerfile.ubuntu
8+
volumes:
9+
- .:/src
10+
working_dir: /src
11+
entrypoint: /bin/bash
12+
13+
alpine:
14+
build:
15+
context: ./docker
16+
dockerfile: Dockerfile.alpine
17+
volumes:
18+
- .:/src
19+
working_dir: /src
20+
entrypoint: /bin/sh
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM crystallang/crystal:0.35.1-alpine
2+
3+
# Based on https://github.com/emcrisostomo/fswatch/blob/master/docker/alpine/Dockerfile.in
4+
5+
RUN apk add --no-cache file git autoconf automake libtool gettext gettext-dev make g++ texinfo curl
6+
7+
ENV ROOT_HOME /root
8+
ENV FSWATCH_BRANCH 1.14.0
9+
10+
WORKDIR ${ROOT_HOME}
11+
RUN git clone https://github.com/emcrisostomo/fswatch.git
12+
13+
WORKDIR ${ROOT_HOME}/fswatch
14+
RUN git checkout ${FSWATCH_BRANCH}
15+
RUN ./autogen.sh && ./configure && make -j
16+
RUN make install
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM crystallang/crystal:0.35.1
2+
3+
RUN apt-get update \
4+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y libfswatch-dev

0 commit comments

Comments
 (0)