Skip to content

Commit

Permalink
Move the build-mylib test into the regular test suite (and get rid …
Browse files Browse the repository at this point in the history
…of the separate `build-mylib` CI job)
  • Loading branch information
DilumAluthge committed Nov 24, 2024
1 parent 530b392 commit 7fd62fb
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 33 deletions.
32 changes: 0 additions & 32 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ jobs:
- ci_started
- test
- docs
- build-mylib
steps:
- run: |
echo ci_started: ${{ needs.ci_started.result }}
echo test: ${{ needs.test.result }}
echo docs: ${{ needs.docs.result }}
echo build-mylib: ${{ needs.build-mylib.result }}
- run: exit 1
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped') }}
ci_started:
Expand Down Expand Up @@ -125,33 +123,3 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # If authenticating with GitHub Actions token
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # If authenticating with SSH deploy key
run: julia --project=docs/ -e 'using Pkg; Pkg.instantiate(); include("docs/make.jl")'
build-mylib:
runs-on: ubuntu-latest
timeout-minutes: 60
strategy:
# Only run 1 of the `build-mylib` job at a time, so that this job doesn't take over
# too many CI resources, and also to leave space for other runs in the JuliaLang org.
max-parallel: 1
fail-fast: false
matrix:
julia-version:
- '1.10' # current LTS
- '1.11' # current stable
steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
- uses: julia-actions/setup-julia@9b79636afcfb07ab02c256cede01fe2db6ba808c # v2.6.0
with:
version: ${{ matrix.julia-version }}
- uses: julia-actions/cache@824243901fb567ccb490b0d0e2483ccecde46834 # v2.0.5
- uses: julia-actions/julia-buildpkg@90dd6f23eb49626e4e6612cb9d64d456f86e6a1c # v1.6.0
with:
project: 'examples/MyLib'
- uses: julia-actions/julia-buildpkg@90dd6f23eb49626e4e6612cb9d64d456f86e6a1c # v1.6.0
with:
project: 'examples/MyLib/build'
- run: |
cd examples/MyLib
make
- run: ./examples/MyLib/my_application.out
env:
LD_LIBRARY_PATH: 'examples/MyLib/MyLibCompiled/lib'
2 changes: 1 addition & 1 deletion src/PackageCompiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function create_fresh_base_sysimage(stdlibs::Vector{String}; cpu_target::String,
# we can't strip the IR from the base sysimg, so we filter out this flag
# also presumably `--compile=all` and maybe a few others we missed here...
sysimage_build_args_strs = map(p -> "$(p...)", values(sysimage_build_args))
filter!(p -> !contains(p, "--compile") && p ̸ ("--strip-ir",), sysimage_build_args_strs)
filter!(p -> !contains(p, "--compile") && p ("--strip-ir",), sysimage_build_args_strs)
sysimage_build_args = Cmd(sysimage_build_args_strs)

cd(base_dir) do
Expand Down
75 changes: 75 additions & 0 deletions test/examples_mylib.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# This testset makes sure that the `examples/MyLib` example does not bitrot.

if Sys.iswindows()
@info "Skipping the examples/MyLib test on Windows"
@test_skip false
# TODO: Figure out how to get this testset to work on Windows.
else
rootdir_testdir = @__DIR__
rootdir = dirname(rootdir_testdir)
rootdir_examples = joinpath(rootdir, "examples")
rootdir_examples_MyLib = joinpath(rootdir_examples, "MyLib")

run_julia_code = (project, code; env = ENV) -> begin
julia_binary = Base.julia_cmd()[1]
env2 = copy(env)
env2["JULIA_PROJECT"] = project
cmd = `$(julia_binary) --startup-file=no -e "$(code)"`
return run(setenv(cmd, env2))
end
run_julia_script = (project, scriptfile; env = ENV) -> begin
julia_binary = Base.julia_cmd()[1]
env2 = copy(env)
env2["JULIA_PROJECT"] = project
cmd = `$(julia_binary) --startup-file=no "$(scriptfile)"`
return run(setenv(cmd, env2))
end

mktempdir() do mytmp
# The PackageCompiler.jl source code directory might be read-only. So let's copy
# examples/MyLib to a temp directory so that we can write stuff to it.
MyLib_tmp = joinpath(mytmp, "MyLib")
cp(rootdir_examples_MyLib, MyLib_tmp)

cd(MyLib_tmp) do
# Go into MyLib_tmp/build/ and dev this copy of PackageCompiler.jl
run_julia_code("./build", """
import Pkg
Pkg.develop(; path = "$(rootdir)")
""")

# Instantiate and precompile the `MyLib/` and `MyLib/build/` environments.
run_julia_code(".", "import Pkg; Pkg.instantiate(); Pkg.precompile()")
run_julia_code("./build", "import Pkg; Pkg.instantiate(); Pkg.precompile()")

# We don't want to assume that the machine running the tests has `make` installed
# and available in the PATH. Therefore, we just run the relevant commands directly.

# build-library
run_julia_script("./build", "build/build.jl")

# build-executable
CC = PackageCompiler.get_compiler_cmd()
TARGET = joinpath(MyLib_tmp, "MyLibCompiled")
INCLUDE_DIR = joinpath(TARGET, "include")
cmd = `$(CC) my_application.c -o $(TARGET)/my_application.out -I$(INCLUDE_DIR) -L$(TARGET)/lib -ljulia -lmylib`
run(cmd)

# Run `./my_application.out`
env2 = copy(ENV)
if Sys.isapple()
env2["DYLD_FALLBACK_LIBRARY_PATH"] = "./MyLibCompiled/lib/:./MyLibCompiled/lib/julia/"
else
env2["LD_LIBRARY_PATH"] = "./MyLibCompiled/lib/"
end
cmd = `$(TARGET)/my_application.out`
@test success(run(setenv(cmd, env2)))
observed_str = strip(read(setenv(cmd, env2), String))
expected_str = "Incremented count: 4 (Cint)\nIncremented value: 4"
@test observed_str == expected_str
end


end

end # if-elseif-else-end
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,9 @@ end
hello = read(`$(Base.julia_cmd()) -J $(sysimage_path) -e 'print("hello, world")'`, String)
@test hello == "hello, world"
end

@testset "examples/MyLib" begin
include("examples_mylib.jl")
end

end

0 comments on commit 7fd62fb

Please sign in to comment.