diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 721de8e1..1072132a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: @@ -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' diff --git a/src/PackageCompiler.jl b/src/PackageCompiler.jl index 220763b5..855ec534 100644 --- a/src/PackageCompiler.jl +++ b/src/PackageCompiler.jl @@ -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 diff --git a/test/examples_mylib.jl b/test/examples_mylib.jl new file mode 100644 index 00000000..a7c8388a --- /dev/null +++ b/test/examples_mylib.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index a02e20a0..60c75a55 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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