Skip to content

Commit

Permalink
Use preferences for juliac compile time branching
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Sep 2, 2024
1 parent 5c017e5 commit f57c3f2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 26 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ version = "1.0.0"

[deps]
JuliaSyntax = "70703baa-626e-46a2-a12c-08ffd08c73b4"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"

[compat]
JuliaSyntax = "0.4.10"
Preferences = "1"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
1 change: 1 addition & 0 deletions juliac/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/Manifest.toml
/runicc
30 changes: 11 additions & 19 deletions juliac/Makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
JULIA ?= /opt/julia/julia-c/bin/julia
JULIAC ?= $(shell $(JULIA) -e 'print(normpath(joinpath(Sys.BINDIR, Base.DATAROOTDIR, "julia", "juliac.jl")))')
RUNIC_SRCFILES := $(wildcard ../src/*.jl)

runicc: runicc.jl $(RUNIC_SRCFILES) invalidate-precompile-cache
$(JULIA) $(JULIAC) --output-exe $@ --trim=unsafe-warn $<
RUNIC_FILES := $(wildcard ../src/*.jl) ../Project.toml

clean:
rm runicc
runicc: runicc.jl Project.toml Manifest.toml $(RUNIC_FILES)
$(JULIA) --project=. $(JULIAC) --output-exe $@ --trim=unsafe-warn $<

Manifest.toml: Project.toml ../Project.toml
$(JULIA) --project=. -e 'using Pkg; Pkg.instantiate()'

# Prune cached precompile files for Runic. This is needed because there are
# (compile time) branches in the Runic source code which depends on whether
# Runic is compiled or not. It looks like juliac will use existing cache files
# but not produce any so there is no need to prune them again after compilation
# to force regular usage to recompile.
invalidate-precompile-cache:
$(JULIA) -e ' \
ji = Base.compilecache_path(Base.PkgId(Base.UUID("62bfec6d-59d7-401d-8490-b29ee721c001"), "Runic")); \
if ji !== nothing; \
isfile(ji) && (@info "Deleting precompile file $$(ji)"; rm(ji)); \
so = splitext(ji)[1] * "." * Base.BinaryPlatforms.platform_dlext(); \
isfile(so) && (@info "Deleting pkgimage file $$(so)"; rm(so)); \
end'
clean:
-rm -f runicc Manifest.toml

print-%:
@echo '$*=$($*)'

.PHONY: invalidate-precompile-cache clean
.PHONY: clean
8 changes: 8 additions & 0 deletions juliac/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[deps]
Runic = "62bfec6d-59d7-401d-8490-b29ee721c001"

[sources]
Runic = {path = ".."}

[preferences.Runic]
juliac = true
9 changes: 2 additions & 7 deletions src/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@ else
end

# Check whether we are compiling with juliac
# TODO: I thought juliac would never use existing pkgimages but looks like it does so this
# isn't reliable... Existing cache files are pruned in the Makefile for now.
const juliac = let opts = Base.JLOptions()
hasfield(typeof(opts), :trim) &&
getfield(opts, :trim) != 0 &&
Base.generating_output()
end
using Preferences: @load_preference
const juliac = @load_preference("juliac", false)

@static if juliac
stderr() = Core.stderr
Expand Down

0 comments on commit f57c3f2

Please sign in to comment.