Skip to content

Commit 2ac10ef

Browse files
committed
More stuff
1 parent 3072323 commit 2ac10ef

File tree

7 files changed

+280
-317
lines changed

7 files changed

+280
-317
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ jobs:
6464
- '64' # 64-bit Julia.
6565
github-runner:
6666
- ubuntu-latest
67-
# - windows-latest # TODO: uncomment this line
67+
- windows-latest
6868
- macos-13 # macos-13 = Intel.
69-
# - macos-14 # macos-14 = Apple Silicon. # TODO: uncomment this line
69+
- macos-14 # macos-14 = Apple Silicon.
7070
coverage:
7171
- 'true'
7272
- 'false' # needed for Julia 1.9+ to test from a session using pkgimages

Project.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ julia = "1.6"
2828

2929
[extras]
3030
Example = "7876af07-990d-54b4-ab0e-23690620f79a"
31-
GNUMake_jll = "6c1a3432-6b93-5c89-98b5-f3caf0c092ba"
3231
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
3332
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3433

3534
[targets]
36-
test = ["Test", "Example", "GNUMake_jll", "TOML"]
35+
test = ["Test", "Example", "TOML"]

examples/MyLib/Makefile

+12-51
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,28 @@
11
# Makefile
22

3-
# This is the default target:
43
.DEFAULT_GOAL := all
5-
.PHONY: all
6-
all: build-library build-executable
7-
8-
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
94

10-
# The user can override these to use custom locations for Julia and/or GCC:
115
JULIA ?= julia
12-
GCC ?= gcc
13-
14-
# We automatically compute DLEXT:
15-
DLEXT := $(shell $(JULIA) --startup-file=no -e 'import Libdl; print(Libdl.dlext)')
6+
DLEXT := $(shell $(JULIA) --startup-file=no -e 'using Libdl; print(Libdl.dlext)')
167

17-
# Define TARGET in one place, so that we don't need to keep retyping it.
188
TARGET="MyLibCompiled"
199

20-
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21-
22-
# build-library and build-executable are just for convenience:
23-
24-
.PHONY: build-library
25-
build-library: $(TARGET)/lib/libmylib.$(DLEXT)
26-
27-
.PHONY: build-executable
28-
build-executable: my_application.out
29-
30-
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31-
32-
.PHONY: clean
33-
clean:
34-
$(RM) *.o
35-
$(RM) *.out
36-
$(RM) *.$(DLEXT)
37-
$(RM) -rf $(TARGET)
38-
39-
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
40-
41-
# Library:
42-
4310
MYLIB_INCLUDES = $(TARGET)/include/julia_init.h $(TARGET)/include/mylib.h
4411
MYLIB_PATH := $(TARGET)/lib/libmylib.$(DLEXT)
4512

46-
# We split this up into multiple lines, just so that we don't end up with a single really long line.
47-
DEPS_build_library := src/MyLib.jl
48-
DEPS_build_library += build/build.jl
49-
DEPS_build_library += build/generate_precompile.jl build/additional_precompile.jl
50-
DEPS_build_library += build/mylib.h
51-
DEPS_build_library += build/Project.toml build/Manifest.toml
52-
53-
$(TARGET)/lib/libmylib.$(DLEXT): $(DEPS_build_library)
54-
$(JULIA) --startup-file=no --project=. -e 'import Pkg; Pkg.instantiate(); Pkg.precompile()'
55-
$(JULIA) --startup-file=no --project=build -e 'import Pkg; Pkg.instantiate(); Pkg.precompile()'
56-
$(JULIA) --startup-file=no --project=build -e 'include("build/build.jl")'
13+
build-library: build/build.jl src/MyLib.jl
14+
$(JULIA) --startup-file=no --project=. -e 'using Pkg; Pkg.instantiate()'
15+
$(JULIA) --startup-file=no --project=build -e 'using Pkg; Pkg.instantiate(); include("build/build.jl")'
5716

58-
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
17+
INCLUDE_DIR = $(TARGET)/include
5918

60-
# Application (my_application.out):
19+
build-executable:
20+
gcc my_application.c -o my_application.out -I$(INCLUDE_DIR) -L$(TARGET)/lib -ljulia -lmylib
6121

62-
INCLUDE_DIR = $(TARGET)/include
22+
all: build-library build-executable
6323

64-
my_application.out: $(TARGET)/lib/libmylib.$(DLEXT)
65-
$(GCC) my_application.c -o my_application.out -I$(INCLUDE_DIR) -L$(TARGET)/lib -ljulia -lmylib
24+
clean:
25+
$(RM) *~ *.o *.$(DLEXT)
26+
$(RM) -Rf $(TARGET)
6627

67-
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28+
.PHONY: build-library build-executable clean all

examples/MyLib/runme.bash

-11
This file was deleted.

src/PackageCompiler.jl

+4-3
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ function create_fresh_base_sysimage(stdlibs::Vector{String}; cpu_target::String,
237237
# we can't strip the IR from the base sysimg, so we filter out this flag
238238
# also presumably `--compile=all` and maybe a few others we missed here...
239239
sysimage_build_args_strs = map(p -> "$(p...)", values(sysimage_build_args))
240-
filter!(p -> !contains(p, "--compile") && p ̸ ("--strip-ir",), sysimage_build_args_strs)
240+
filter!(p -> !contains(p, "--compile") && p ("--strip-ir",), sysimage_build_args_strs)
241241
sysimage_build_args = Cmd(sysimage_build_args_strs)
242242

243243
cd(base_dir) do
@@ -291,8 +291,9 @@ function ensurecompiled(project, packages, sysimage)
291291
# TODO: Only precompile `packages` (should be available in Pkg 1.8)
292292
cmd = `$(get_julia_cmd()) --sysimage=$sysimage -e 'using Pkg; Pkg.precompile()'`
293293
splitter = Sys.iswindows() ? ';' : ':'
294-
@debug "ensurecompiled: running $cmd" JULIA_LOAD_PATH = "$project$(splitter)@stdlib"
295-
cmd = addenv(cmd, "JULIA_LOAD_PATH" => "$project$(splitter)@stdlib")
294+
JULIA_LOAD_PATH = "$project$(splitter)@stdlib"
295+
@debug "ensurecompiled: running $cmd" JULIA_LOAD_PATH
296+
cmd = setenv(cmd, "JULIA_LOAD_PATH" => JULIA_LOAD_PATH, "JULIA_PROJECT" => project)
296297
run(cmd)
297298
return
298299
end

test/examples_mylib.jl

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# This testset makes sure that the `examples/MyLib` example does not bitrot.
2+
3+
if Sys.iswindows()
4+
@info "Skipping the examples/MyLib test on Windows"
5+
@test_skip false
6+
# TODO: Figure out how to get this testset to work on Windows.
7+
else
8+
rootdir_testdir = @__DIR__
9+
rootdir = dirname(rootdir_testdir)
10+
rootdir_examples = joinpath(rootdir, "examples")
11+
rootdir_examples_MyLib = joinpath(rootdir_examples, "MyLib")
12+
13+
run_julia_code = (project, code; env = ENV) -> begin
14+
julia_binary = Base.julia_cmd()[1]
15+
env2 = copy(env)
16+
env2["JULIA_PROJECT"] = project
17+
cmd = `$(julia_binary) --startup-file=no -e "$(code)"`
18+
return run(setenv(cmd, env2))
19+
end
20+
run_julia_script = (project, scriptfile; env = ENV) -> begin
21+
julia_binary = Base.julia_cmd()[1]
22+
env2 = copy(env)
23+
env2["JULIA_PROJECT"] = project
24+
cmd = `$(julia_binary) --startup-file=no "$(scriptfile)"`
25+
return run(setenv(cmd, env2))
26+
end
27+
28+
mktempdir() do mytmp
29+
# The PackageCompiler.jl source code directory might be read-only. So let's copy
30+
# examples/MyLib to a temp directory so that we can write stuff to it.
31+
MyLib_tmp = joinpath(mytmp, "MyLib")
32+
cp(rootdir_examples_MyLib, MyLib_tmp)
33+
34+
cd(MyLib_tmp) do
35+
# Go into MyLib_tmp/build/ and dev this copy of PackageCompiler.jl
36+
run_julia_code("./build", """
37+
import Pkg
38+
Pkg.develop(; path = "$(rootdir)")
39+
""")
40+
41+
# Instantiate and precompile the `MyLib/` and `MyLib/build/` environments.
42+
run_julia_code(".", "import Pkg; Pkg.instantiate(); Pkg.precompile()")
43+
run_julia_code("./build", "import Pkg; Pkg.instantiate(); Pkg.precompile()")
44+
45+
# We don't want to assume that the machine running the tests has `make` installed
46+
# and available in the PATH. Therefore, we just run the relevant commands directly.
47+
48+
# build-library
49+
run_julia_script("./build", "build/build.jl")
50+
51+
# build-executable
52+
CC = PackageCompiler.get_compiler_cmd()
53+
TARGET = joinpath(MyLib_tmp, "MyLibCompiled")
54+
INCLUDE_DIR = joinpath(TARGET, "include")
55+
cmd = `$(CC) my_application.c -o $(TARGET)/my_application.out -I$(INCLUDE_DIR) -L$(TARGET)/lib -ljulia -lmylib`
56+
run(cmd)
57+
58+
# Run `./my_application.out`
59+
env2 = copy(ENV)
60+
if Sys.isapple()
61+
env2["DYLD_FALLBACK_LIBRARY_PATH"] = "./MyLibCompiled/lib/:./MyLibCompiled/lib/julia/"
62+
else
63+
env2["LD_LIBRARY_PATH"] = "./MyLibCompiled/lib/"
64+
end
65+
cmd = `$(TARGET)/my_application.out`
66+
@test success(run(setenv(cmd, env2)))
67+
observed_str = strip(read(setenv(cmd, env2), String))
68+
expected_str = "Incremented count: 4 (Cint)\nIncremented value: 4"
69+
@test observed_str == expected_str
70+
end
71+
72+
73+
end
74+
75+
end # if-elseif-else-end

0 commit comments

Comments
 (0)