Skip to content

Commit

Permalink
support cross-compiling.
Browse files Browse the repository at this point in the history
  • Loading branch information
Z572 committed Dec 13, 2023
1 parent 9f607c8 commit 958a045
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 10 deletions.
9 changes: 8 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ BUILT_SOURCES= $(filter %.x, $(libguile_ts_la_SOURCES:%.c=%.x))
moddir=$(prefix)/share/guile/site/$(GUILE_EFFECTIVE_VERSION)
godir=$(libdir)/guile/$(GUILE_EFFECTIVE_VERSION)/site-ccache
.scm.go:
$(AM_V_GEN)$(top_builddir)/pre-inst-env $(GUILE_TOOLS) compile $(GUILE_TARGET) $(GUILE_WARNINGS) -o "$@" "$<"
$(AM_V_GEN) $(CROSS_COMPILING_VARIABLE) $(top_builddir)/pre-inst-env \
$(GUILE_TOOLS) compile --target=$(host) $(GUILE_TARGET) $(GUILE_WARNINGS) -o "$@" "$<"
.c.x:
$(AM_V_GEN)$(top_builddir)/pre-inst-env guile-snarf -o $@ $< $(libguile_ts_la_CFLAGS)
EXTRA_DIST = $(SOURCES) $(TESTS) build-aux/test-driver.scm
Expand All @@ -35,6 +36,12 @@ GUILE_WARNINGS = \
GOBJECTS = $(SOURCES:%.scm=%.go)
CLEANFILES = $(GOBJECTS) $(TESTS:tests/%.scm=%.log) $(BUILT_SOURCES)

if CROSS_COMPILING
CROSS_COMPILING_VARIABLE = GUILE_TS_CROSS_COMPILING=yes
else
CROSS_COMPILING_VARIABLE =
endif

nobase_mod_DATA = $(SOURCES) $(NOCOMP_SOURCES) $(NODIST_SOURCES)
nobase_go_DATA = $(GOBJECTS)

Expand Down
1 change: 0 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@
- Poor documentation :: you can see tests/ directory for how to use.
- Some tree-sitter C apis is miss.
- Some apis are not friendly.
- No cross-compile support.
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ GUILE_PKG([3.0])
GUILE_PROGS
GUILE_SITE_DIR

AM_CONDITIONAL([CROSS_COMPILING], [test "x$cross_compiling" = "xyes"])

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.
Expand Down
3 changes: 2 additions & 1 deletion ts/init.scm
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
new-obj))))

(eval-when (expand load eval)
(load-extension "libguile_ts" "init_ts"))
(unless (getenv "GUILE_TS_CROSS_COMPILING")
(load-extension "libguile_ts" "init_ts")))
3 changes: 2 additions & 1 deletion ts/language.scm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
'<ts-language> '(%data)))

(eval-when (expand load eval)
(load-extension "libguile_ts" "init_ts_language"))
(unless (getenv "GUILE_TS_CROSS_COMPILING")
(load-extension "libguile_ts" "init_ts_language")))

(define (get-ts-language-from-file lib name)
(parameterize ((ltdl-library-path
Expand Down
13 changes: 12 additions & 1 deletion ts/parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,18 @@
ts-parser-print-dot-graphs))

(eval-when (expand load eval)
(load-extension "libguile_ts" "init_ts_parser"))
(if (getenv "GUILE_TS_CROSS_COMPILING")
(for-each (lambda (x)
(module-define! (current-module) x identity))
'(%tsp-language
%tsp-set-language!
%tsp-timeout
%tsp-set-timeout!
%tsp-included-ranges
%tsp-set-included-ranges!
%tsp-logger
%tsp-set-logger!))
(load-extension "libguile_ts" "init_ts_parser")))

(define (tsp-delete! o)
(let ((%data (slot-ref o '%data)))
Expand Down
3 changes: 2 additions & 1 deletion ts/query.scm
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
#:finalizer %ts-query-cursor-delete))

(eval-when (expand load eval)
(load-extension "libguile_ts" "init_ts_query"))
(unless (getenv "GUILE_TS_CROSS_COMPILING")
(load-extension "libguile_ts" "init_ts_query")))

(define (ts-query-new language . sources)
(let* ((str
Expand Down
3 changes: 2 additions & 1 deletion ts/tree.scm
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
#:finalizer %tcursor-finalizer))

(eval-when (expand load eval)
(load-extension "libguile_ts" "init_ts_tree"))
(unless (getenv "GUILE_TS_CROSS_COMPILING")
(load-extension "libguile_ts" "init_ts_tree")))

(define-method (equal? (node1 <ts-node>) (node2 <ts-node>))
(%ts-node-eq? node1 node2))
Expand Down
17 changes: 14 additions & 3 deletions ts/util.scm
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,24 @@ e.g.
(bytevector-slice bv start))
"utf-8")))

(eval-when (expand load eval)
(load-extension "libguile_ts" "init_ts_util"))

(define <%ts-range>
(make-foreign-object-type
'<%ts-range> '(%data)))

(eval-when (expand load eval)
(if (getenv "GUILE_TS_CROSS_COMPILING")
(for-each (lambda (x)
(module-define! (current-module) x identity))
'(%tsr-start-point
%tsr-end-point
%tsr-end-byte
%tsr-start-byte
%tsr-set-start-point!
%tsr-set-end-point!
%tsr-set-start-byte!
%tsr-set-end-byte!))
(load-extension "libguile_ts" "init_ts_util")))

(define-class <ts-range> (<%ts-range>)
(start-point #:allocation #:virtual
#:slot-ref %tsr-start-point
Expand Down

0 comments on commit 958a045

Please sign in to comment.