Skip to content

Commit 7fd62fb

Browse files
committed
Move the build-mylib test into the regular test suite (and get rid of the separate build-mylib CI job)
1 parent 530b392 commit 7fd62fb

File tree

4 files changed

+81
-33
lines changed

4 files changed

+81
-33
lines changed

.github/workflows/ci.yml

-32
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@ jobs:
2424
- ci_started
2525
- test
2626
- docs
27-
- build-mylib
2827
steps:
2928
- run: |
3029
echo ci_started: ${{ needs.ci_started.result }}
3130
echo test: ${{ needs.test.result }}
3231
echo docs: ${{ needs.docs.result }}
33-
echo build-mylib: ${{ needs.build-mylib.result }}
3432
- run: exit 1
3533
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped') }}
3634
ci_started:
@@ -125,33 +123,3 @@ jobs:
125123
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # If authenticating with GitHub Actions token
126124
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # If authenticating with SSH deploy key
127125
run: julia --project=docs/ -e 'using Pkg; Pkg.instantiate(); include("docs/make.jl")'
128-
build-mylib:
129-
runs-on: ubuntu-latest
130-
timeout-minutes: 60
131-
strategy:
132-
# Only run 1 of the `build-mylib` job at a time, so that this job doesn't take over
133-
# too many CI resources, and also to leave space for other runs in the JuliaLang org.
134-
max-parallel: 1
135-
fail-fast: false
136-
matrix:
137-
julia-version:
138-
- '1.10' # current LTS
139-
- '1.11' # current stable
140-
steps:
141-
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
142-
- uses: julia-actions/setup-julia@9b79636afcfb07ab02c256cede01fe2db6ba808c # v2.6.0
143-
with:
144-
version: ${{ matrix.julia-version }}
145-
- uses: julia-actions/cache@824243901fb567ccb490b0d0e2483ccecde46834 # v2.0.5
146-
- uses: julia-actions/julia-buildpkg@90dd6f23eb49626e4e6612cb9d64d456f86e6a1c # v1.6.0
147-
with:
148-
project: 'examples/MyLib'
149-
- uses: julia-actions/julia-buildpkg@90dd6f23eb49626e4e6612cb9d64d456f86e6a1c # v1.6.0
150-
with:
151-
project: 'examples/MyLib/build'
152-
- run: |
153-
cd examples/MyLib
154-
make
155-
- run: ./examples/MyLib/my_application.out
156-
env:
157-
LD_LIBRARY_PATH: 'examples/MyLib/MyLibCompiled/lib'

src/PackageCompiler.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ function create_fresh_base_sysimage(stdlibs::Vector{String}; cpu_target::String,
245245
# we can't strip the IR from the base sysimg, so we filter out this flag
246246
# also presumably `--compile=all` and maybe a few others we missed here...
247247
sysimage_build_args_strs = map(p -> "$(p...)", values(sysimage_build_args))
248-
filter!(p -> !contains(p, "--compile") && p ̸ ("--strip-ir",), sysimage_build_args_strs)
248+
filter!(p -> !contains(p, "--compile") && p ("--strip-ir",), sysimage_build_args_strs)
249249
sysimage_build_args = Cmd(sysimage_build_args_strs)
250250

251251
cd(base_dir) do

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

test/runtests.jl

+5
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,9 @@ end
242242
hello = read(`$(Base.julia_cmd()) -J $(sysimage_path) -e 'print("hello, world")'`, String)
243243
@test hello == "hello, world"
244244
end
245+
246+
@testset "examples/MyLib" begin
247+
include("examples_mylib.jl")
248+
end
249+
245250
end

0 commit comments

Comments
 (0)