From 0aa48ccbdfffbdc071de9ff2609abd92b6dd1ee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mos=C3=A8=20Giordano?= Date: Tue, 29 Apr 2025 18:25:06 -0500 Subject: [PATCH 1/5] Update RootFS build --- Artifacts.toml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Artifacts.toml b/Artifacts.toml index 772f7811..9f853eac 100644 --- a/Artifacts.toml +++ b/Artifacts.toml @@ -5190,6 +5190,28 @@ os = "linux" sha256 = "f51e2d7defe0979abff04e024f75d75d1ef18da9cc9813dbfd5deb8701b8cf7f" url = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/Rootfs-v2024.3.29/Rootfs.v2024.3.29.x86_64-linux-musl.unpacked.tar.gz" +[["Rootfs.v2025.4.29.x86_64-linux-musl.squashfs"]] +arch = "x86_64" +git-tree-sha1 = "5526badb5a049bc45844cae977818e2c3316adb7" +lazy = true +libc = "musl" +os = "linux" + + [["Rootfs.v2025.4.29.x86_64-linux-musl.squashfs".download]] + sha256 = "fd17c40c6833111743bb2fde602596cb6bad1f22c5ec765d017c67fc9afe1e9d" + url = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/Rootfs-v2025.4.29/Rootfs.v2025.4.29.x86_64-linux-musl.squashfs.tar.gz" + +[["Rootfs.v2025.4.29.x86_64-linux-musl.unpacked"]] +arch = "x86_64" +git-tree-sha1 = "9e748d08d77b69cc7838da98974697ab494e63d7" +lazy = true +libc = "musl" +os = "linux" + + [["Rootfs.v2025.4.29.x86_64-linux-musl.unpacked".download]] + sha256 = "6891d3590153dbc8ad1e9c401f5f9d91e44d179747b6df38ef1ac31375fb1852" + url = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/Rootfs-v2025.4.29/Rootfs.v2025.4.29.x86_64-linux-musl.unpacked.tar.gz" + [["RustBase.v1.57.0.x86_64-linux-musl.squashfs"]] arch = "x86_64" git-tree-sha1 = "ced9ffc9b69fbf10db7f413aacfd4d6099825cf2" From 00583d3170c56d18d9659f8bd920140922de6a95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mos=C3=A8=20Giordano?= Date: Tue, 29 Apr 2025 18:28:26 -0500 Subject: [PATCH 2/5] [Runner] Fix bootstrap --- src/Runner.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Runner.jl b/src/Runner.jl index cf4f3c5d..7b2e0954 100644 --- a/src/Runner.jl +++ b/src/Runner.jl @@ -1489,7 +1489,9 @@ function runner_setup!(workspaces, mappings, workspace_root, verbose, kwargs, pl if !isdir(ccache_dir()) mkpath(ccache_dir()) end - push!(workspaces, ccache_dir() => envs["CCACHE_DIR"]) + # During bootstrap `CCACHE_DIR` may not be defined, we provide a + # fallback for that case, otherwise rely on the environment variable. + push!(workspaces, ccache_dir() => get(envs, "CCACHE_DIR", "/root/.ccache")) end return platform, envs, shards From a63742a07e90d247a8c6ea32e78ff6fff9ff7316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mos=C3=A8=20Giordano?= Date: Wed, 30 Apr 2025 18:21:41 +0100 Subject: [PATCH 3/5] DROP ME: Debug --- test/runners.jl | 1012 +++++++++++++++++++++++----------------------- test/runtests.jl | 16 +- 2 files changed, 514 insertions(+), 514 deletions(-) diff --git a/test/runners.jl b/test/runners.jl index 3d330b86..3a112f5d 100644 --- a/test/runners.jl +++ b/test/runners.jl @@ -3,337 +3,337 @@ using BinaryBuilderBase using BinaryBuilderBase: platform_dlext, platform_exeext, prefer_clang using Pkg -@testset "Wrappers utilities" begin - @test nbits(Platform("i686", "linux")) == 32 - @test nbits(Platform("x86_64", "linux"; march="avx")) == 64 - @test nbits(Platform("armv7l", "linux")) == 32 - @test nbits(Platform("aarch64", "linux"; cuda="10.1")) == 64 - @test nbits(Platform("powerpc64le", "linux")) == 64 - @test nbits(Platform("riscv64", "linux")) == 64 - @test nbits(AnyPlatform()) == 64 - - @test proc_family(Platform("i686", "linux")) == "intel" - @test proc_family(Platform("x86_64", "linux"; march="avx")) == "intel" - @test proc_family(Platform("armv7l", "linux")) == "arm" - @test proc_family(Platform("aarch64", "linux"; cuda="10.1")) == "arm" - @test proc_family(Platform("powerpc64le", "linux")) == "power" - @test proc_family(Platform("riscv64", "linux")) == "riscv" - @test proc_family(AnyPlatform()) == "any" - - @test platform_exeext(Platform("i686", "linux")) == "" - @test platform_exeext(Platform("x86_64", "freebsd")) == "" - @test platform_exeext(Platform("x86_64", "macos")) == "" - @test platform_exeext(Platform("i686", "windows")) == ".exe" - @test platform_exeext(Platform("x86_64", "linux"; march="avx512")) == "" - - @test aatriplet(Platform("x86_64", "linux"; libc="glibc", libgfortran_version=v"4.0.0", march="avx", cuda="9.2")) == "x86_64-linux-gnu" - - @test prefer_clang(Platform("x86_64", "freebsd")) - @test prefer_clang(Platform("aarch64", "macos")) - @test !prefer_clang(Platform("powerpc64le", "linux")) - @test !prefer_clang(Platform("riscv64", "linux")) - @test !prefer_clang(Platform("x86_64", "linux")) - @test prefer_clang(Platform("x86_64", "linux"; sanitize="memory")) - @test !prefer_clang(Platform("x86_64", "linux"; sanitize="thread")) -end - -@testset "with_logfile" begin - mktempdir() do dir - logfile = joinpath(dir, "dir", "logfile.txt") - with_logfile(logfile) do io - print(io, logfile) - end - @test readchomp(logfile) == logfile - # Test writing on an existing file - with_logfile(logfile) do io - print(io, logfile * logfile) - end - @test readchomp(logfile) == logfile * logfile - - # Test using a Prefix as argument - prefix = Prefix(dir) - subdir = "my_package" - ldir = logdir(prefix; subdir) - name = "logfile.txt" - logfile = joinpath(ldir, name) - with_logfile(prefix, name; subdir) do io - print(io, logfile) - end - @test readchomp(logfile) == logfile - end -end +# @testset "Wrappers utilities" begin +# @test nbits(Platform("i686", "linux")) == 32 +# @test nbits(Platform("x86_64", "linux"; march="avx")) == 64 +# @test nbits(Platform("armv7l", "linux")) == 32 +# @test nbits(Platform("aarch64", "linux"; cuda="10.1")) == 64 +# @test nbits(Platform("powerpc64le", "linux")) == 64 +# @test nbits(Platform("riscv64", "linux")) == 64 +# @test nbits(AnyPlatform()) == 64 + +# @test proc_family(Platform("i686", "linux")) == "intel" +# @test proc_family(Platform("x86_64", "linux"; march="avx")) == "intel" +# @test proc_family(Platform("armv7l", "linux")) == "arm" +# @test proc_family(Platform("aarch64", "linux"; cuda="10.1")) == "arm" +# @test proc_family(Platform("powerpc64le", "linux")) == "power" +# @test proc_family(Platform("riscv64", "linux")) == "riscv" +# @test proc_family(AnyPlatform()) == "any" + +# @test platform_exeext(Platform("i686", "linux")) == "" +# @test platform_exeext(Platform("x86_64", "freebsd")) == "" +# @test platform_exeext(Platform("x86_64", "macos")) == "" +# @test platform_exeext(Platform("i686", "windows")) == ".exe" +# @test platform_exeext(Platform("x86_64", "linux"; march="avx512")) == "" + +# @test aatriplet(Platform("x86_64", "linux"; libc="glibc", libgfortran_version=v"4.0.0", march="avx", cuda="9.2")) == "x86_64-linux-gnu" + +# @test prefer_clang(Platform("x86_64", "freebsd")) +# @test prefer_clang(Platform("aarch64", "macos")) +# @test !prefer_clang(Platform("powerpc64le", "linux")) +# @test !prefer_clang(Platform("riscv64", "linux")) +# @test !prefer_clang(Platform("x86_64", "linux")) +# @test prefer_clang(Platform("x86_64", "linux"; sanitize="memory")) +# @test !prefer_clang(Platform("x86_64", "linux"; sanitize="thread")) +# end + +# @testset "with_logfile" begin +# mktempdir() do dir +# logfile = joinpath(dir, "dir", "logfile.txt") +# with_logfile(logfile) do io +# print(io, logfile) +# end +# @test readchomp(logfile) == logfile +# # Test writing on an existing file +# with_logfile(logfile) do io +# print(io, logfile * logfile) +# end +# @test readchomp(logfile) == logfile * logfile + +# # Test using a Prefix as argument +# prefix = Prefix(dir) +# subdir = "my_package" +# ldir = logdir(prefix; subdir) +# name = "logfile.txt" +# logfile = joinpath(ldir, name) +# with_logfile(prefix, name; subdir) do io +# print(io, logfile) +# end +# @test readchomp(logfile) == logfile +# end +# end # Are we using docker? If so, test that the docker runner works... @testset "Runner utilities" begin # Test that is_ecryptfs works for something we're certain isn't encrypted - if isdir("/proc") && Sys.islinux() - isecfs = (false, "/proc/") - @test_logs (:info, "Checking to see if /proc/ is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc"; verbose=true) == isecfs - @test_logs (:info, "Checking to see if /proc/ is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc/"; verbose=true) == isecfs - @test_logs (:info, "Checking to see if /proc/not_a_file is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc/not_a_file"; verbose=true) == isecfs - elseif Sys.islinux() - @test_logs (:info, "Checking to see if /proc/ is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc"; verbose=true) == (false, "/proc") - @test_logs (:info, "Checking to see if /proc/ is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc/"; verbose=true) == (false, "/proc/") - @test_logs (:info, "Checking to see if /proc/not_a_file is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc/not_a_file"; verbose=true) == (false, "/proc/not_a_file") - end - - if isa(preferred_runner(), BinaryBuilderBase.DockerRunner) - @testset "Docker image importing" begin - # First, delete the docker image, in case it already existed - BinaryBuilderBase.delete_docker_image() - - # Next, import it and ensure that doesn't throw - rootfs = first(BinaryBuilderBase.choose_shards(platform)) - mktempdir() do dir - @test BinaryBuilderBase.import_docker_image(rootfs, dir; verbose=true) === nothing - end - - # Test that deleting the docker image suceeds, now that we know - # it exists - @test BinaryBuilderBase.delete_docker_image() - end - end - - @testset "hello world" begin - mktempdir() do dir - # Make sure we can start a shell in a runner when the bootstrap list is non-empty - @eval BinaryBuilderBase push!(bootstrap_list, :rootfs, :platform_support) - ur = preferred_runner()(dir; platform=Platform("x86_64", "linux"; libc="musl")) - iobuff = IOBuffer() - @test run(ur, `/bin/bash -c "echo test"`, iobuff) - seek(iobuff, 0) - # Test that we get the output we expect (e.g. the second line is `test`) - @test readlines(iobuff)[2] == "test" - # Restore empty bootstrap list - @eval BinaryBuilderBase empty!(bootstrap_list) - end - end - - @testset "run_interactive" begin - platform = default_host_platform - io = IOBuffer() - @test run_interactive(preferred_runner()(mktempdir(); platform), `/bin/bash -c "echo hello world"`, stdout=io) - s = String(take!(io)) - @test s == "hello world\n" - # Make sure that `run_interactive` consistently throws an error when the process fails, - # whatever is the type of `stdout`, or it consistently ignores failures if so requested. - # Ref: https://github.com/JuliaPackaging/BinaryBuilderBase.jl/pull/201#issuecomment-1003192121 - cmd = `/bin/bash -c "false"` - @test_throws ProcessFailedException run_interactive(preferred_runner()(mktempdir(); platform), cmd) - @test_throws ProcessFailedException run_interactive(preferred_runner()(mktempdir(); platform), cmd; stdout=IOBuffer()) - cmd = Cmd(`/bin/bash -c "false"`; ignorestatus=true) - @test !run_interactive(preferred_runner()(mktempdir(); platform), cmd) - @test !run_interactive(preferred_runner()(mktempdir(); platform), cmd; stdout=IOBuffer()) - end - - if lowercase(get(ENV, "BINARYBUILDER_FULL_SHARD_TEST", "false")) == "true" - @info("Beginning full shard test... (this can take a while)") - platforms = supported_platforms() - else - platforms = (default_host_platform,) - end - - # Checks that the wrappers provide the correct C++ string ABI - @testset "Compilation - C++ string ABI" begin - mktempdir() do dir - # Host is x86_64-linux-musl-cxx11 and target is x86_64-linux-musl-cxx03 - ur = preferred_runner()(dir; platform=Platform("x86_64", "linux"; libc="musl", cxxstring_abi="cxx03"), preferred_gcc_version=v"5") - iobuff = IOBuffer() - test_script = raw""" - set -e - - # Building for the target uses C++03 string ABI - echo 'int main() {return 0;}' | SUPER_VERBOSE=1 ${CC} -x c - 2>&1 | grep -- "-D_GLIBCXX_USE_CXX11_ABI=0" - - # Building for the host uses C++11 string ABI - echo 'int main() {return 0;}' | SUPER_VERBOSE=1 ${HOSTCC} -x c - 2>&1 | grep -v -- "-D_GLIBCXX_USE_CXX11_ABI=0" - """ - @test run(ur, `/bin/bash -c "$(test_script)"`, iobuff; tee_stream=devnull) - end - end - - # This tests only that compilers for all platforms can build and link simple C code - @testset "Compilation - $(platform) - $(compiler)" for platform in platforms, compiler in ("cc", "gcc", "clang") - mktempdir() do dir - # if compiler == "clang" - # ur = preferred_runner()(dir; platform=platform, preferred_gcc_version=v"5") #TODO: Fix CI disk size issues to allow this - # else - # ur = preferred_runner()(dir; platform=platform) - # end - ur = preferred_runner()(dir; platform=platform) - iobuff = IOBuffer() - test_c = """ - #include - int test(void) { - return 0; - } - """ - main_c = """ - int test(void); - int main(void) { - return test(); - } - """ - test_script = """ - set -e - # Make sure setting `CCACHE` doesn't affect the compiler wrappers. - export CCACHE=pwned - export USE_CCACHE=false - echo '$(test_c)' > test.c - echo '$(main_c)' > main.c - # Build object file - $(compiler) -Werror -c test.c -o test.o - # Build shared library - $(compiler) -Werror -shared test.c -o libtest.\${dlext} - # Build and link program with object file - $(compiler) -Werror -o main main.c test.o - # Build and link program with shared library - $(compiler) -Werror -o main main.c -L. -ltest - """ - cmd = `/bin/bash -c "$(test_script)"` - @test run(ur, cmd, iobuff) - seekstart(iobuff) - # Make sure `iobuff` contains only the input command, no other text - @test readchomp(iobuff) == string(cmd) - end - end - - # This tests only that compilers for all platforms can build and link simple C++ code - # Note: we test the slightly weird `clang -x c++` as compiler driver because that's used - # in some cases and we want to make sure it works correctly. - @testset "Compilation - $(platform) - $(compiler)" for platform in platforms, (compiler, linker) in (("c++", "c++"), ("g++", "g++"), ("clang -x c++", "clang++")) - mktempdir() do dir - ur = preferred_runner()(dir; platform=platform) - iobuff = IOBuffer() - needfpic = Sys.iswindows(platform) ? "" : "-fPIC" - test_cpp = """ - #include - std::complex add(std::complex a, std::complex b) { - return a + b; - } - """ - main_cpp = """ - #include - std::complex add(std::complex a, std::complex b); - int main(void) { - std::complex z3 = add(std::complex(1.,2.),std::complex(4.,2.)); - return 0; - } - """ - main_c = """ - int main(void) { - return 0; - } - """ - test_script = """ - set -e - echo '$(test_cpp)' > test.cpp - echo '$(main_cpp)' > main.cpp - echo '$(main_c)' > main.c - # Make sure setting `CCACHE` doesn't affect the compiler wrappers. - export CCACHE=pwned - export USE_CCACHE=true - # Build object file - $(compiler) $(needfpic) -Werror -std=c++11 -c test.cpp -o test.o - # Link shared library - $(linker) -shared test.o -o libtest.\${dlext} - # Build and link program with object file - $(compiler) $(needfpic) -Werror -std=c++11 -c main.cpp -o main.o - # Link main program with test object file - $(linker) -o main main.o test.o - # Link main program with shared library - $(linker) -o main main.o -L. -ltest - - # Also make sure we can link to libtest (which may link to - # libstdc++) with gcc (as in the C compiler). - gcc -o main_c main.c -ltest -L. - """ - cmd = `/bin/bash -c "$(test_script)"` - @test run(ur, cmd, iobuff; tee_stream=devnull) - seekstart(iobuff) - # Make sure `iobuff` contains only the input command, no other text - is_broken = (compiler == "g++" && Sys.isapple(platform) && arch(platform) == "x86_64") # This gets fixed by using GCC7 or up - @test readchomp(iobuff) == string(cmd) broken=is_broken - end - end + # if isdir("/proc") && Sys.islinux() + # isecfs = (false, "/proc/") + # @test_logs (:info, "Checking to see if /proc/ is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc"; verbose=true) == isecfs + # @test_logs (:info, "Checking to see if /proc/ is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc/"; verbose=true) == isecfs + # @test_logs (:info, "Checking to see if /proc/not_a_file is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc/not_a_file"; verbose=true) == isecfs + # elseif Sys.islinux() + # @test_logs (:info, "Checking to see if /proc/ is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc"; verbose=true) == (false, "/proc") + # @test_logs (:info, "Checking to see if /proc/ is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc/"; verbose=true) == (false, "/proc/") + # @test_logs (:info, "Checking to see if /proc/not_a_file is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc/not_a_file"; verbose=true) == (false, "/proc/not_a_file") + # end + + # if isa(preferred_runner(), BinaryBuilderBase.DockerRunner) + # @testset "Docker image importing" begin + # # First, delete the docker image, in case it already existed + # BinaryBuilderBase.delete_docker_image() + + # # Next, import it and ensure that doesn't throw + # rootfs = first(BinaryBuilderBase.choose_shards(platform)) + # mktempdir() do dir + # @test BinaryBuilderBase.import_docker_image(rootfs, dir; verbose=true) === nothing + # end + + # # Test that deleting the docker image suceeds, now that we know + # # it exists + # @test BinaryBuilderBase.delete_docker_image() + # end + # end + + # @testset "hello world" begin + # mktempdir() do dir + # # Make sure we can start a shell in a runner when the bootstrap list is non-empty + # @eval BinaryBuilderBase push!(bootstrap_list, :rootfs, :platform_support) + # ur = preferred_runner()(dir; platform=Platform("x86_64", "linux"; libc="musl")) + # iobuff = IOBuffer() + # @test run(ur, `/bin/bash -c "echo test"`, iobuff) + # seek(iobuff, 0) + # # Test that we get the output we expect (e.g. the second line is `test`) + # @test readlines(iobuff)[2] == "test" + # # Restore empty bootstrap list + # @eval BinaryBuilderBase empty!(bootstrap_list) + # end + # end + + # @testset "run_interactive" begin + # platform = default_host_platform + # io = IOBuffer() + # @test run_interactive(preferred_runner()(mktempdir(); platform), `/bin/bash -c "echo hello world"`, stdout=io) + # s = String(take!(io)) + # @test s == "hello world\n" + # # Make sure that `run_interactive` consistently throws an error when the process fails, + # # whatever is the type of `stdout`, or it consistently ignores failures if so requested. + # # Ref: https://github.com/JuliaPackaging/BinaryBuilderBase.jl/pull/201#issuecomment-1003192121 + # cmd = `/bin/bash -c "false"` + # @test_throws ProcessFailedException run_interactive(preferred_runner()(mktempdir(); platform), cmd) + # @test_throws ProcessFailedException run_interactive(preferred_runner()(mktempdir(); platform), cmd; stdout=IOBuffer()) + # cmd = Cmd(`/bin/bash -c "false"`; ignorestatus=true) + # @test !run_interactive(preferred_runner()(mktempdir(); platform), cmd) + # @test !run_interactive(preferred_runner()(mktempdir(); platform), cmd; stdout=IOBuffer()) + # end + + # if lowercase(get(ENV, "BINARYBUILDER_FULL_SHARD_TEST", "false")) == "true" + # @info("Beginning full shard test... (this can take a while)") + # platforms = supported_platforms() + # else + # platforms = (default_host_platform,) + # end + + # # Checks that the wrappers provide the correct C++ string ABI + # @testset "Compilation - C++ string ABI" begin + # mktempdir() do dir + # # Host is x86_64-linux-musl-cxx11 and target is x86_64-linux-musl-cxx03 + # ur = preferred_runner()(dir; platform=Platform("x86_64", "linux"; libc="musl", cxxstring_abi="cxx03"), preferred_gcc_version=v"5") + # iobuff = IOBuffer() + # test_script = raw""" + # set -e + + # # Building for the target uses C++03 string ABI + # echo 'int main() {return 0;}' | SUPER_VERBOSE=1 ${CC} -x c - 2>&1 | grep -- "-D_GLIBCXX_USE_CXX11_ABI=0" + + # # Building for the host uses C++11 string ABI + # echo 'int main() {return 0;}' | SUPER_VERBOSE=1 ${HOSTCC} -x c - 2>&1 | grep -v -- "-D_GLIBCXX_USE_CXX11_ABI=0" + # """ + # @test run(ur, `/bin/bash -c "$(test_script)"`, iobuff; tee_stream=devnull) + # end + # end + + # # This tests only that compilers for all platforms can build and link simple C code + # @testset "Compilation - $(platform) - $(compiler)" for platform in platforms, compiler in ("cc", "gcc", "clang") + # mktempdir() do dir + # # if compiler == "clang" + # # ur = preferred_runner()(dir; platform=platform, preferred_gcc_version=v"5") #TODO: Fix CI disk size issues to allow this + # # else + # # ur = preferred_runner()(dir; platform=platform) + # # end + # ur = preferred_runner()(dir; platform=platform) + # iobuff = IOBuffer() + # test_c = """ + # #include + # int test(void) { + # return 0; + # } + # """ + # main_c = """ + # int test(void); + # int main(void) { + # return test(); + # } + # """ + # test_script = """ + # set -e + # # Make sure setting `CCACHE` doesn't affect the compiler wrappers. + # export CCACHE=pwned + # export USE_CCACHE=false + # echo '$(test_c)' > test.c + # echo '$(main_c)' > main.c + # # Build object file + # $(compiler) -Werror -c test.c -o test.o + # # Build shared library + # $(compiler) -Werror -shared test.c -o libtest.\${dlext} + # # Build and link program with object file + # $(compiler) -Werror -o main main.c test.o + # # Build and link program with shared library + # $(compiler) -Werror -o main main.c -L. -ltest + # """ + # cmd = `/bin/bash -c "$(test_script)"` + # @test run(ur, cmd, iobuff) + # seekstart(iobuff) + # # Make sure `iobuff` contains only the input command, no other text + # @test readchomp(iobuff) == string(cmd) + # end + # end + + # # This tests only that compilers for all platforms can build and link simple C++ code + # # Note: we test the slightly weird `clang -x c++` as compiler driver because that's used + # # in some cases and we want to make sure it works correctly. + # @testset "Compilation - $(platform) - $(compiler)" for platform in platforms, (compiler, linker) in (("c++", "c++"), ("g++", "g++"), ("clang -x c++", "clang++")) + # mktempdir() do dir + # ur = preferred_runner()(dir; platform=platform) + # iobuff = IOBuffer() + # needfpic = Sys.iswindows(platform) ? "" : "-fPIC" + # test_cpp = """ + # #include + # std::complex add(std::complex a, std::complex b) { + # return a + b; + # } + # """ + # main_cpp = """ + # #include + # std::complex add(std::complex a, std::complex b); + # int main(void) { + # std::complex z3 = add(std::complex(1.,2.),std::complex(4.,2.)); + # return 0; + # } + # """ + # main_c = """ + # int main(void) { + # return 0; + # } + # """ + # test_script = """ + # set -e + # echo '$(test_cpp)' > test.cpp + # echo '$(main_cpp)' > main.cpp + # echo '$(main_c)' > main.c + # # Make sure setting `CCACHE` doesn't affect the compiler wrappers. + # export CCACHE=pwned + # export USE_CCACHE=true + # # Build object file + # $(compiler) $(needfpic) -Werror -std=c++11 -c test.cpp -o test.o + # # Link shared library + # $(linker) -shared test.o -o libtest.\${dlext} + # # Build and link program with object file + # $(compiler) $(needfpic) -Werror -std=c++11 -c main.cpp -o main.o + # # Link main program with test object file + # $(linker) -o main main.o test.o + # # Link main program with shared library + # $(linker) -o main main.o -L. -ltest + + # # Also make sure we can link to libtest (which may link to + # # libstdc++) with gcc (as in the C compiler). + # gcc -o main_c main.c -ltest -L. + # """ + # cmd = `/bin/bash -c "$(test_script)"` + # @test run(ur, cmd, iobuff; tee_stream=devnull) + # seekstart(iobuff) + # # Make sure `iobuff` contains only the input command, no other text + # is_broken = (compiler == "g++" && Sys.isapple(platform) && arch(platform) == "x86_64") # This gets fixed by using GCC7 or up + # @test readchomp(iobuff) == string(cmd) broken=is_broken + # end + # end # This tests that compilers for all Intel Linux platforms can build simple # C, C++, Fortran programs that we can also run @testset "Compilation and running" begin platforms = filter(p -> Sys.islinux(p) && proc_family(p) == "intel", supported_platforms()) - @testset "C - $(platform)" for platform in platforms - mktempdir() do dir - ur = preferred_runner()(dir; platform=platform) - iobuff = IOBuffer() - test_c = """ - #include - int main() { - printf("Hello World!\\n"); - return 0; - } - """ - cmd = `/bin/bash -c "echo '$(test_c)' > test.c && cc -o test test.c && ./test"` - @test run(ur, cmd, iobuff; tee_stream=devnull) - seekstart(iobuff) - # Test that we get the output we expect - @test endswith(readchomp(iobuff), "Hello World!") - end - end - - @testset "C and link to quadmath - $(platform)" for platform in platforms - mktempdir() do dir - # Use a recent GCC with libgfortran5 - options = (preferred_gcc_version=v"9", compilers=[:c]) - shards = choose_shards(platform; options...) - concrete_platform = get_concrete_platform(platform, shards) - prefix = setup_workspace( - dir, - [], - concrete_platform, - default_host_platform; - ) - # Install `MPICH_jll` in the `${prefix}` to make sure we can link to - # libquadmath without problems, see - # https://github.com/JuliaPackaging/BinaryBuilderBase.jl/pull/157#issuecomment-879263820 - version = VERSION≥v"1.9.0-" ? v"3.4.2+0" : v"3.4.2" # From Julia v1.9, JLLs need to specify the build number - artifact_paths = - setup_dependencies(prefix, - [PackageSpec(; name="MPICH_jll", version)], - concrete_platform, verbose=false) - ur = preferred_runner()(prefix.path; - platform=concrete_platform, - shards = shards, - options...) - iobuff = IOBuffer() - test_c = """ - #include - int main() { - printf("Hello World!\\n"); - return 0; - } - """ - test_script = """ - set -e - echo '$(test_c)' > test.c - # Make sure we can compile successfully also when linking to libmpifort - cc -o test test.c -L\${libdir} -lmpifort -lquadmath - ./test - """ - cmd = `/bin/bash -c "$(test_script)"` - if arch(platform) == "i686" && libc(platform) == "musl" - # We can't run this program for this platform - @test_broken run(ur, cmd, iobuff; tee_stream=devnull) - else - @test run(ur, cmd, iobuff; tee_stream=devnull) - seekstart(iobuff) - # Test that we get the output we expect - @test endswith(readchomp(iobuff), "Hello World!") - end - cleanup_dependencies(prefix, artifact_paths, concrete_platform) - end - end + # @testset "C - $(platform)" for platform in platforms + # mktempdir() do dir + # ur = preferred_runner()(dir; platform=platform) + # iobuff = IOBuffer() + # test_c = """ + # #include + # int main() { + # printf("Hello World!\\n"); + # return 0; + # } + # """ + # cmd = `/bin/bash -c "echo '$(test_c)' > test.c && cc -o test test.c && ./test 2>&1"` + # @test run(ur, cmd, iobuff; tee_stream=stdout) + # seekstart(iobuff) + # # Test that we get the output we expect + # @test endswith(readchomp(iobuff), "Hello World!") + # end + # end + + # @testset "C and link to quadmath - $(platform)" for platform in platforms + # mktempdir() do dir + # # Use a recent GCC with libgfortran5 + # options = (preferred_gcc_version=v"9", compilers=[:c]) + # shards = choose_shards(platform; options...) + # concrete_platform = get_concrete_platform(platform, shards) + # prefix = setup_workspace( + # dir, + # [], + # concrete_platform, + # default_host_platform; + # ) + # # Install `MPICH_jll` in the `${prefix}` to make sure we can link to + # # libquadmath without problems, see + # # https://github.com/JuliaPackaging/BinaryBuilderBase.jl/pull/157#issuecomment-879263820 + # version = VERSION≥v"1.9.0-" ? v"3.4.2+0" : v"3.4.2" # From Julia v1.9, JLLs need to specify the build number + # artifact_paths = + # setup_dependencies(prefix, + # [PackageSpec(; name="MPICH_jll", version)], + # concrete_platform, verbose=false) + # ur = preferred_runner()(prefix.path; + # platform=concrete_platform, + # shards = shards, + # options...) + # iobuff = IOBuffer() + # test_c = """ + # #include + # int main() { + # printf("Hello World!\\n"); + # return 0; + # } + # """ + # test_script = """ + # set -e + # echo '$(test_c)' > test.c + # # Make sure we can compile successfully also when linking to libmpifort + # cc -o test test.c -L\${libdir} -lmpifort -lquadmath + # ./test + # """ + # cmd = `/bin/bash -c "$(test_script)"` + # if arch(platform) == "i686" && libc(platform) == "musl" + # # We can't run this program for this platform + # @test_broken run(ur, cmd, iobuff; tee_stream=devnull) + # else + # @test run(ur, cmd, iobuff; tee_stream=devnull) + # seekstart(iobuff) + # # Test that we get the output we expect + # @test endswith(readchomp(iobuff), "Hello World!") + # end + # cleanup_dependencies(prefix, artifact_paths, concrete_platform) + # end + # end @testset "C++ - $(platform)" for platform in platforms mktempdir() do dir @@ -374,14 +374,14 @@ end # Make sure we can compile successfully also when `\${libdir}` is in the # linker search path c++ -o test test.cpp -L\${libdir} - ./test + ./test 2>&1 """ cmd = `/bin/bash -c "$(test_script)"` if arch(platform) == "i686" && libc(platform) == "musl" # We can't run C++ programs for this platform @test_broken run(ur, cmd, iobuff; tee_stream=devnull) else - @test run(ur, cmd, iobuff; tee_stream=devnull) + @test run(ur, cmd, iobuff; tee_stream=stdout) seekstart(iobuff) # Test that we get the output we expect @test endswith(readchomp(iobuff), "Hello World!") @@ -390,193 +390,193 @@ end end end - # This tests that compilers for all Intel Linux platforms can build a simple - # Fortran program that we can also run - @testset "Fortran - $(platform)" for platform in platforms - mktempdir() do dir - ur = preferred_runner()(dir; platform=platform) - iobuff = IOBuffer() - test_f = """ - program hello - print *, "Hello World!" - end program - """ - cmd = `/bin/bash -c "echo '$(test_f)' > test.f && gfortran -o test test.f && ./test"` - if arch(platform) == "i686" && libc(platform) == "musl" - # We can't run Fortran programs for this platform - @test_broken run(ur, cmd, iobuff; tee_stream=devnull) - else - @test run(ur, cmd, iobuff; tee_stream=devnull) - seekstart(iobuff) - # Test that we get the output we expect - @test endswith(readchomp(iobuff), "Hello World!") - end - end - end - end - - @testset "Locking microarchitecture" begin - mktempdir() do dir - platform = Platform("x86_64", "linux"; libc="musl") - cmd = `/bin/bash -c "echo 'int main() {return 0;}' | cc -x c -march=native -"` - ur = preferred_runner()(dir; platform=platform, lock_microarchitecture=true) - iobuff = IOBuffer() - @test !run(ur, cmd, iobuff; tee_stream=devnull) - seekstart(iobuff) - @test readlines(iobuff)[2] == "BinaryBuilder: Cannot force an architecture via -march" - - ur = preferred_runner()(dir; platform=platform, lock_microarchitecture=false) - iobuff = IOBuffer() - @test run(ur, cmd, iobuff; tee_stream=devnull) - seekstart(iobuff) - @test split(String(read(iobuff)), "\n")[2] == "" - end - end - - @testset "Unsafe flags" begin - mktempdir() do dir - platform = Platform("x86_64", "linux"; libc="musl") - cmd = `/bin/bash -c "echo 'int main() {return 0;}' | cc -x c -Ofast -"` - ur = preferred_runner()(dir; platform=platform, allow_unsafe_flags=false) - iobuff = IOBuffer() - @test !run(ur, cmd, iobuff; tee_stream=devnull) - seekstart(iobuff) - lines = readlines(iobuff) - @test lines[2] == "BinaryBuilder error: You used one or more of the unsafe flags: -Ofast, -ffast-math, -funsafe-math-optimizations" - @test lines[3] == "This is not allowed, please remove all unsafe flags from your build script to continue." - - ur = preferred_runner()(dir; platform=platform, allow_unsafe_flags=true) - iobuff = IOBuffer() - @test run(ur, cmd, iobuff; tee_stream=devnull) - seekstart(iobuff) - @test split(String(read(iobuff)), "\n")[2] == "" - end - end - - @testset "macOS SDK setting" begin - mktempdir() do dir - platform = Platform("x86_64", "macos") - test_script = raw""" - set -e - prog='int main(void) { return 0; }' - echo "${prog}" | clang -x c - -o test-clang - otool -lV test-clang | grep sdk - # Set `MACOSX_DEPLOYMENT_TARGET` to override the value of the SDK - export MACOSX_DEPLOYMENT_TARGET=10.14 - echo "${prog}" | gcc -x c - -o test-gcc - otool -lV test-gcc | grep sdk - """ - cmd = `/bin/bash -c "$(test_script)"` - ur = preferred_runner()(dir; platform=platform, allow_unsafe_flags=false) - iobuff = IOBuffer() - @test run(ur, cmd, iobuff; tee_stream=devnull) - seekstart(iobuff) - lines = readlines(iobuff) - # Make sure the SDK for this platform is set to 10.10, instead of other wrong - # values, and that we can set `MACOSX_DEPLOYMENT_TARGET` to control the value. - @test contains(lines[end - 1], r"^ +sdk 10\.10$") - @test contains(lines[end], r"^ +sdk 10\.14$") - end - end - - @testset "Test lld usage" begin - mktempdir() do dir - ur = preferred_runner()(dir; platform=Platform("x86_64", "windows"), preferred_gcc_version=v"6") - iobuff = IOBuffer() - test_c = """ - #include - int test(void) { - return 0; - } - """ - test_script = """ - set -e - echo '$(test_c)' > test.c - clang -Werror -shared test.c -o libtest.\${dlext} - """ - cmd = `/bin/bash -c "$(test_script)"` - @test run(ur, cmd, iobuff) - - test_script = """ - set -e - echo '$(test_c)' > test.c - clang -Werror -v -shared test.c -o libtest.\${dlext} - """ - iobuff = IOBuffer() - cmd = `/bin/bash -c "$(test_script)"` - @test run(ur, cmd, iobuff) - seekstart(iobuff) - @test occursin(r"ld.lld", readchomp(iobuff)) - end - - mktempdir() do dir - ur = preferred_runner()(dir; platform=Platform("x86_64", "linux", libc="musl"), preferred_gcc_version=v"9") - iobuff = IOBuffer() - test_c = """ - #include - int test(void) { - return 0; - } - """ - test_script = """ - set -e - echo '$(test_c)' > test.c - gcc -Werror -shared test.c -fuse-ld=lld -o libtest.\${dlext} - """ - cmd = `/bin/bash -c "$(test_script)"` - @test run(ur, cmd, iobuff) - - test_script = """ - set -e - echo '$(test_c)' > test.c - gcc -Werror -v -shared test.c -fuse-ld=lld -o libtest.\${dlext} - """ - iobuff = IOBuffer() - cmd = `/bin/bash -c "$(test_script)"` - @test run(ur, cmd, iobuff) - seekstart(iobuff) - @test occursin(r"lld", readchomp(iobuff)) - end - - mktempdir() do dir - platform = Platform("x86_64", "linux", libc="musl") - ur = preferred_runner()(dir; platform, preferred_gcc_version=v"9", clang_use_lld=false) - iobuff = IOBuffer() - test_script = raw""" - cat $(which clang) - """ - cmd = `/bin/bash -c "$(test_script)"` - @test run(ur, cmd, iobuff) - seekstart(iobuff) - @test occursin("-fuse-ld=$(aatriplet(platform))", readchomp(iobuff)) - end + # # This tests that compilers for all Intel Linux platforms can build a simple + # # Fortran program that we can also run + # @testset "Fortran - $(platform)" for platform in platforms + # mktempdir() do dir + # ur = preferred_runner()(dir; platform=platform) + # iobuff = IOBuffer() + # test_f = """ + # program hello + # print *, "Hello World!" + # end program + # """ + # cmd = `/bin/bash -c "echo '$(test_f)' > test.f && gfortran -o test test.f && ./test"` + # if arch(platform) == "i686" && libc(platform) == "musl" + # # We can't run Fortran programs for this platform + # @test_broken run(ur, cmd, iobuff; tee_stream=devnull) + # else + # @test run(ur, cmd, iobuff; tee_stream=devnull) + # seekstart(iobuff) + # # Test that we get the output we expect + # @test endswith(readchomp(iobuff), "Hello World!") + # end + # end + # end + # end + + # @testset "Locking microarchitecture" begin + # mktempdir() do dir + # platform = Platform("x86_64", "linux"; libc="musl") + # cmd = `/bin/bash -c "echo 'int main() {return 0;}' | cc -x c -march=native -"` + # ur = preferred_runner()(dir; platform=platform, lock_microarchitecture=true) + # iobuff = IOBuffer() + # @test !run(ur, cmd, iobuff; tee_stream=devnull) + # seekstart(iobuff) + # @test readlines(iobuff)[2] == "BinaryBuilder: Cannot force an architecture via -march" + + # ur = preferred_runner()(dir; platform=platform, lock_microarchitecture=false) + # iobuff = IOBuffer() + # @test run(ur, cmd, iobuff; tee_stream=devnull) + # seekstart(iobuff) + # @test split(String(read(iobuff)), "\n")[2] == "" + # end + # end + + # @testset "Unsafe flags" begin + # mktempdir() do dir + # platform = Platform("x86_64", "linux"; libc="musl") + # cmd = `/bin/bash -c "echo 'int main() {return 0;}' | cc -x c -Ofast -"` + # ur = preferred_runner()(dir; platform=platform, allow_unsafe_flags=false) + # iobuff = IOBuffer() + # @test !run(ur, cmd, iobuff; tee_stream=devnull) + # seekstart(iobuff) + # lines = readlines(iobuff) + # @test lines[2] == "BinaryBuilder error: You used one or more of the unsafe flags: -Ofast, -ffast-math, -funsafe-math-optimizations" + # @test lines[3] == "This is not allowed, please remove all unsafe flags from your build script to continue." + + # ur = preferred_runner()(dir; platform=platform, allow_unsafe_flags=true) + # iobuff = IOBuffer() + # @test run(ur, cmd, iobuff; tee_stream=devnull) + # seekstart(iobuff) + # @test split(String(read(iobuff)), "\n")[2] == "" + # end + # end + + # @testset "macOS SDK setting" begin + # mktempdir() do dir + # platform = Platform("x86_64", "macos") + # test_script = raw""" + # set -e + # prog='int main(void) { return 0; }' + # echo "${prog}" | clang -x c - -o test-clang + # otool -lV test-clang | grep sdk + # # Set `MACOSX_DEPLOYMENT_TARGET` to override the value of the SDK + # export MACOSX_DEPLOYMENT_TARGET=10.14 + # echo "${prog}" | gcc -x c - -o test-gcc + # otool -lV test-gcc | grep sdk + # """ + # cmd = `/bin/bash -c "$(test_script)"` + # ur = preferred_runner()(dir; platform=platform, allow_unsafe_flags=false) + # iobuff = IOBuffer() + # @test run(ur, cmd, iobuff; tee_stream=devnull) + # seekstart(iobuff) + # lines = readlines(iobuff) + # # Make sure the SDK for this platform is set to 10.10, instead of other wrong + # # values, and that we can set `MACOSX_DEPLOYMENT_TARGET` to control the value. + # @test contains(lines[end - 1], r"^ +sdk 10\.10$") + # @test contains(lines[end], r"^ +sdk 10\.14$") + # end + # end + + # @testset "Test lld usage" begin + # mktempdir() do dir + # ur = preferred_runner()(dir; platform=Platform("x86_64", "windows"), preferred_gcc_version=v"6") + # iobuff = IOBuffer() + # test_c = """ + # #include + # int test(void) { + # return 0; + # } + # """ + # test_script = """ + # set -e + # echo '$(test_c)' > test.c + # clang -Werror -shared test.c -o libtest.\${dlext} + # """ + # cmd = `/bin/bash -c "$(test_script)"` + # @test run(ur, cmd, iobuff) + + # test_script = """ + # set -e + # echo '$(test_c)' > test.c + # clang -Werror -v -shared test.c -o libtest.\${dlext} + # """ + # iobuff = IOBuffer() + # cmd = `/bin/bash -c "$(test_script)"` + # @test run(ur, cmd, iobuff) + # seekstart(iobuff) + # @test occursin(r"ld.lld", readchomp(iobuff)) + # end + + # mktempdir() do dir + # ur = preferred_runner()(dir; platform=Platform("x86_64", "linux", libc="musl"), preferred_gcc_version=v"9") + # iobuff = IOBuffer() + # test_c = """ + # #include + # int test(void) { + # return 0; + # } + # """ + # test_script = """ + # set -e + # echo '$(test_c)' > test.c + # gcc -Werror -shared test.c -fuse-ld=lld -o libtest.\${dlext} + # """ + # cmd = `/bin/bash -c "$(test_script)"` + # @test run(ur, cmd, iobuff) + + # test_script = """ + # set -e + # echo '$(test_c)' > test.c + # gcc -Werror -v -shared test.c -fuse-ld=lld -o libtest.\${dlext} + # """ + # iobuff = IOBuffer() + # cmd = `/bin/bash -c "$(test_script)"` + # @test run(ur, cmd, iobuff) + # seekstart(iobuff) + # @test occursin(r"lld", readchomp(iobuff)) + # end + + # mktempdir() do dir + # platform = Platform("x86_64", "linux", libc="musl") + # ur = preferred_runner()(dir; platform, preferred_gcc_version=v"9", clang_use_lld=false) + # iobuff = IOBuffer() + # test_script = raw""" + # cat $(which clang) + # """ + # cmd = `/bin/bash -c "$(test_script)"` + # @test run(ur, cmd, iobuff) + # seekstart(iobuff) + # @test occursin("-fuse-ld=$(aatriplet(platform))", readchomp(iobuff)) + # end end end -@testset "Shards" begin - # Run the testsuite as sanity check - @testset "testsuite" begin - mktempdir() do dir - # Skip Rust tests when they are broken. Ref: - # https://github.com/JuliaPackaging/BinaryBuilderBase.jl/issues/395 - compilers = if !BinaryBuilderBase.use_squashfs[] && get(ENV, "BINARYBUILDER_RUNNER", "") == "unprivileged" - [:c, :go] - else - [:c, :rust, :go] - end - ur = preferred_runner()(dir; platform=Platform("x86_64", "linux"; libc="glibc"), preferred_gcc_version=v"5", compilers) - # Make sure the runner platform is concrete even if the requested platform isn't - @test !isnothing(libgfortran_version(ur.platform)) - @test !isnothing(cxxstring_abi(ur.platform)) - iobuff = IOBuffer() - test_script = raw""" - set -e - make -j${nproc} -sC /usr/share/testsuite install - """ - @test run(ur, `/bin/bash -c "$(test_script)"`, iobuff) - end - end -end +# @testset "Shards" begin +# # Run the testsuite as sanity check +# @testset "testsuite" begin +# mktempdir() do dir +# # Skip Rust tests when they are broken. Ref: +# # https://github.com/JuliaPackaging/BinaryBuilderBase.jl/issues/395 +# compilers = if !BinaryBuilderBase.use_squashfs[] && get(ENV, "BINARYBUILDER_RUNNER", "") == "unprivileged" +# [:c, :go] +# else +# [:c, :rust, :go] +# end +# ur = preferred_runner()(dir; platform=Platform("x86_64", "linux"; libc="glibc"), preferred_gcc_version=v"5", compilers) +# # Make sure the runner platform is concrete even if the requested platform isn't +# @test !isnothing(libgfortran_version(ur.platform)) +# @test !isnothing(cxxstring_abi(ur.platform)) +# iobuff = IOBuffer() +# test_script = raw""" +# set -e +# make -j${nproc} -sC /usr/share/testsuite install +# """ +# @test run(ur, `/bin/bash -c "$(test_script)"`, iobuff) +# end +# end +# end diff --git a/test/runtests.jl b/test/runtests.jl index 51f6d96e..4ed9548e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,10 +1,10 @@ # Run all our tests -include("compat.jl") -include("archive_utils.jl") -include("dependencies.jl") -include("platforms.jl") -include("prefix.jl") -include("products.jl") -include("sources.jl") -include("rootfs.jl") +# include("compat.jl") +# include("archive_utils.jl") +# include("dependencies.jl") +# include("platforms.jl") +# include("prefix.jl") +# include("products.jl") +# include("sources.jl") +# include("rootfs.jl") include("runners.jl") From b462361b29b56ea66eeb4d90eb477327c5b170d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mos=C3=A8=20Giordano?= Date: Wed, 30 Apr 2025 18:48:59 +0100 Subject: [PATCH 4/5] Revert "DROP ME: Debug" This reverts commit a63742a07e90d247a8c6ea32e78ff6fff9ff7316. --- test/runners.jl | 1010 +++++++++++++++++++++++----------------------- test/runtests.jl | 16 +- 2 files changed, 513 insertions(+), 513 deletions(-) diff --git a/test/runners.jl b/test/runners.jl index 3a112f5d..a2be2424 100644 --- a/test/runners.jl +++ b/test/runners.jl @@ -3,337 +3,337 @@ using BinaryBuilderBase using BinaryBuilderBase: platform_dlext, platform_exeext, prefer_clang using Pkg -# @testset "Wrappers utilities" begin -# @test nbits(Platform("i686", "linux")) == 32 -# @test nbits(Platform("x86_64", "linux"; march="avx")) == 64 -# @test nbits(Platform("armv7l", "linux")) == 32 -# @test nbits(Platform("aarch64", "linux"; cuda="10.1")) == 64 -# @test nbits(Platform("powerpc64le", "linux")) == 64 -# @test nbits(Platform("riscv64", "linux")) == 64 -# @test nbits(AnyPlatform()) == 64 - -# @test proc_family(Platform("i686", "linux")) == "intel" -# @test proc_family(Platform("x86_64", "linux"; march="avx")) == "intel" -# @test proc_family(Platform("armv7l", "linux")) == "arm" -# @test proc_family(Platform("aarch64", "linux"; cuda="10.1")) == "arm" -# @test proc_family(Platform("powerpc64le", "linux")) == "power" -# @test proc_family(Platform("riscv64", "linux")) == "riscv" -# @test proc_family(AnyPlatform()) == "any" - -# @test platform_exeext(Platform("i686", "linux")) == "" -# @test platform_exeext(Platform("x86_64", "freebsd")) == "" -# @test platform_exeext(Platform("x86_64", "macos")) == "" -# @test platform_exeext(Platform("i686", "windows")) == ".exe" -# @test platform_exeext(Platform("x86_64", "linux"; march="avx512")) == "" - -# @test aatriplet(Platform("x86_64", "linux"; libc="glibc", libgfortran_version=v"4.0.0", march="avx", cuda="9.2")) == "x86_64-linux-gnu" - -# @test prefer_clang(Platform("x86_64", "freebsd")) -# @test prefer_clang(Platform("aarch64", "macos")) -# @test !prefer_clang(Platform("powerpc64le", "linux")) -# @test !prefer_clang(Platform("riscv64", "linux")) -# @test !prefer_clang(Platform("x86_64", "linux")) -# @test prefer_clang(Platform("x86_64", "linux"; sanitize="memory")) -# @test !prefer_clang(Platform("x86_64", "linux"; sanitize="thread")) -# end - -# @testset "with_logfile" begin -# mktempdir() do dir -# logfile = joinpath(dir, "dir", "logfile.txt") -# with_logfile(logfile) do io -# print(io, logfile) -# end -# @test readchomp(logfile) == logfile -# # Test writing on an existing file -# with_logfile(logfile) do io -# print(io, logfile * logfile) -# end -# @test readchomp(logfile) == logfile * logfile - -# # Test using a Prefix as argument -# prefix = Prefix(dir) -# subdir = "my_package" -# ldir = logdir(prefix; subdir) -# name = "logfile.txt" -# logfile = joinpath(ldir, name) -# with_logfile(prefix, name; subdir) do io -# print(io, logfile) -# end -# @test readchomp(logfile) == logfile -# end -# end +@testset "Wrappers utilities" begin + @test nbits(Platform("i686", "linux")) == 32 + @test nbits(Platform("x86_64", "linux"; march="avx")) == 64 + @test nbits(Platform("armv7l", "linux")) == 32 + @test nbits(Platform("aarch64", "linux"; cuda="10.1")) == 64 + @test nbits(Platform("powerpc64le", "linux")) == 64 + @test nbits(Platform("riscv64", "linux")) == 64 + @test nbits(AnyPlatform()) == 64 + + @test proc_family(Platform("i686", "linux")) == "intel" + @test proc_family(Platform("x86_64", "linux"; march="avx")) == "intel" + @test proc_family(Platform("armv7l", "linux")) == "arm" + @test proc_family(Platform("aarch64", "linux"; cuda="10.1")) == "arm" + @test proc_family(Platform("powerpc64le", "linux")) == "power" + @test proc_family(Platform("riscv64", "linux")) == "riscv" + @test proc_family(AnyPlatform()) == "any" + + @test platform_exeext(Platform("i686", "linux")) == "" + @test platform_exeext(Platform("x86_64", "freebsd")) == "" + @test platform_exeext(Platform("x86_64", "macos")) == "" + @test platform_exeext(Platform("i686", "windows")) == ".exe" + @test platform_exeext(Platform("x86_64", "linux"; march="avx512")) == "" + + @test aatriplet(Platform("x86_64", "linux"; libc="glibc", libgfortran_version=v"4.0.0", march="avx", cuda="9.2")) == "x86_64-linux-gnu" + + @test prefer_clang(Platform("x86_64", "freebsd")) + @test prefer_clang(Platform("aarch64", "macos")) + @test !prefer_clang(Platform("powerpc64le", "linux")) + @test !prefer_clang(Platform("riscv64", "linux")) + @test !prefer_clang(Platform("x86_64", "linux")) + @test prefer_clang(Platform("x86_64", "linux"; sanitize="memory")) + @test !prefer_clang(Platform("x86_64", "linux"; sanitize="thread")) +end + +@testset "with_logfile" begin + mktempdir() do dir + logfile = joinpath(dir, "dir", "logfile.txt") + with_logfile(logfile) do io + print(io, logfile) + end + @test readchomp(logfile) == logfile + # Test writing on an existing file + with_logfile(logfile) do io + print(io, logfile * logfile) + end + @test readchomp(logfile) == logfile * logfile + + # Test using a Prefix as argument + prefix = Prefix(dir) + subdir = "my_package" + ldir = logdir(prefix; subdir) + name = "logfile.txt" + logfile = joinpath(ldir, name) + with_logfile(prefix, name; subdir) do io + print(io, logfile) + end + @test readchomp(logfile) == logfile + end +end # Are we using docker? If so, test that the docker runner works... @testset "Runner utilities" begin # Test that is_ecryptfs works for something we're certain isn't encrypted - # if isdir("/proc") && Sys.islinux() - # isecfs = (false, "/proc/") - # @test_logs (:info, "Checking to see if /proc/ is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc"; verbose=true) == isecfs - # @test_logs (:info, "Checking to see if /proc/ is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc/"; verbose=true) == isecfs - # @test_logs (:info, "Checking to see if /proc/not_a_file is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc/not_a_file"; verbose=true) == isecfs - # elseif Sys.islinux() - # @test_logs (:info, "Checking to see if /proc/ is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc"; verbose=true) == (false, "/proc") - # @test_logs (:info, "Checking to see if /proc/ is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc/"; verbose=true) == (false, "/proc/") - # @test_logs (:info, "Checking to see if /proc/not_a_file is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc/not_a_file"; verbose=true) == (false, "/proc/not_a_file") - # end - - # if isa(preferred_runner(), BinaryBuilderBase.DockerRunner) - # @testset "Docker image importing" begin - # # First, delete the docker image, in case it already existed - # BinaryBuilderBase.delete_docker_image() - - # # Next, import it and ensure that doesn't throw - # rootfs = first(BinaryBuilderBase.choose_shards(platform)) - # mktempdir() do dir - # @test BinaryBuilderBase.import_docker_image(rootfs, dir; verbose=true) === nothing - # end - - # # Test that deleting the docker image suceeds, now that we know - # # it exists - # @test BinaryBuilderBase.delete_docker_image() - # end - # end - - # @testset "hello world" begin - # mktempdir() do dir - # # Make sure we can start a shell in a runner when the bootstrap list is non-empty - # @eval BinaryBuilderBase push!(bootstrap_list, :rootfs, :platform_support) - # ur = preferred_runner()(dir; platform=Platform("x86_64", "linux"; libc="musl")) - # iobuff = IOBuffer() - # @test run(ur, `/bin/bash -c "echo test"`, iobuff) - # seek(iobuff, 0) - # # Test that we get the output we expect (e.g. the second line is `test`) - # @test readlines(iobuff)[2] == "test" - # # Restore empty bootstrap list - # @eval BinaryBuilderBase empty!(bootstrap_list) - # end - # end - - # @testset "run_interactive" begin - # platform = default_host_platform - # io = IOBuffer() - # @test run_interactive(preferred_runner()(mktempdir(); platform), `/bin/bash -c "echo hello world"`, stdout=io) - # s = String(take!(io)) - # @test s == "hello world\n" - # # Make sure that `run_interactive` consistently throws an error when the process fails, - # # whatever is the type of `stdout`, or it consistently ignores failures if so requested. - # # Ref: https://github.com/JuliaPackaging/BinaryBuilderBase.jl/pull/201#issuecomment-1003192121 - # cmd = `/bin/bash -c "false"` - # @test_throws ProcessFailedException run_interactive(preferred_runner()(mktempdir(); platform), cmd) - # @test_throws ProcessFailedException run_interactive(preferred_runner()(mktempdir(); platform), cmd; stdout=IOBuffer()) - # cmd = Cmd(`/bin/bash -c "false"`; ignorestatus=true) - # @test !run_interactive(preferred_runner()(mktempdir(); platform), cmd) - # @test !run_interactive(preferred_runner()(mktempdir(); platform), cmd; stdout=IOBuffer()) - # end - - # if lowercase(get(ENV, "BINARYBUILDER_FULL_SHARD_TEST", "false")) == "true" - # @info("Beginning full shard test... (this can take a while)") - # platforms = supported_platforms() - # else - # platforms = (default_host_platform,) - # end - - # # Checks that the wrappers provide the correct C++ string ABI - # @testset "Compilation - C++ string ABI" begin - # mktempdir() do dir - # # Host is x86_64-linux-musl-cxx11 and target is x86_64-linux-musl-cxx03 - # ur = preferred_runner()(dir; platform=Platform("x86_64", "linux"; libc="musl", cxxstring_abi="cxx03"), preferred_gcc_version=v"5") - # iobuff = IOBuffer() - # test_script = raw""" - # set -e - - # # Building for the target uses C++03 string ABI - # echo 'int main() {return 0;}' | SUPER_VERBOSE=1 ${CC} -x c - 2>&1 | grep -- "-D_GLIBCXX_USE_CXX11_ABI=0" - - # # Building for the host uses C++11 string ABI - # echo 'int main() {return 0;}' | SUPER_VERBOSE=1 ${HOSTCC} -x c - 2>&1 | grep -v -- "-D_GLIBCXX_USE_CXX11_ABI=0" - # """ - # @test run(ur, `/bin/bash -c "$(test_script)"`, iobuff; tee_stream=devnull) - # end - # end - - # # This tests only that compilers for all platforms can build and link simple C code - # @testset "Compilation - $(platform) - $(compiler)" for platform in platforms, compiler in ("cc", "gcc", "clang") - # mktempdir() do dir - # # if compiler == "clang" - # # ur = preferred_runner()(dir; platform=platform, preferred_gcc_version=v"5") #TODO: Fix CI disk size issues to allow this - # # else - # # ur = preferred_runner()(dir; platform=platform) - # # end - # ur = preferred_runner()(dir; platform=platform) - # iobuff = IOBuffer() - # test_c = """ - # #include - # int test(void) { - # return 0; - # } - # """ - # main_c = """ - # int test(void); - # int main(void) { - # return test(); - # } - # """ - # test_script = """ - # set -e - # # Make sure setting `CCACHE` doesn't affect the compiler wrappers. - # export CCACHE=pwned - # export USE_CCACHE=false - # echo '$(test_c)' > test.c - # echo '$(main_c)' > main.c - # # Build object file - # $(compiler) -Werror -c test.c -o test.o - # # Build shared library - # $(compiler) -Werror -shared test.c -o libtest.\${dlext} - # # Build and link program with object file - # $(compiler) -Werror -o main main.c test.o - # # Build and link program with shared library - # $(compiler) -Werror -o main main.c -L. -ltest - # """ - # cmd = `/bin/bash -c "$(test_script)"` - # @test run(ur, cmd, iobuff) - # seekstart(iobuff) - # # Make sure `iobuff` contains only the input command, no other text - # @test readchomp(iobuff) == string(cmd) - # end - # end - - # # This tests only that compilers for all platforms can build and link simple C++ code - # # Note: we test the slightly weird `clang -x c++` as compiler driver because that's used - # # in some cases and we want to make sure it works correctly. - # @testset "Compilation - $(platform) - $(compiler)" for platform in platforms, (compiler, linker) in (("c++", "c++"), ("g++", "g++"), ("clang -x c++", "clang++")) - # mktempdir() do dir - # ur = preferred_runner()(dir; platform=platform) - # iobuff = IOBuffer() - # needfpic = Sys.iswindows(platform) ? "" : "-fPIC" - # test_cpp = """ - # #include - # std::complex add(std::complex a, std::complex b) { - # return a + b; - # } - # """ - # main_cpp = """ - # #include - # std::complex add(std::complex a, std::complex b); - # int main(void) { - # std::complex z3 = add(std::complex(1.,2.),std::complex(4.,2.)); - # return 0; - # } - # """ - # main_c = """ - # int main(void) { - # return 0; - # } - # """ - # test_script = """ - # set -e - # echo '$(test_cpp)' > test.cpp - # echo '$(main_cpp)' > main.cpp - # echo '$(main_c)' > main.c - # # Make sure setting `CCACHE` doesn't affect the compiler wrappers. - # export CCACHE=pwned - # export USE_CCACHE=true - # # Build object file - # $(compiler) $(needfpic) -Werror -std=c++11 -c test.cpp -o test.o - # # Link shared library - # $(linker) -shared test.o -o libtest.\${dlext} - # # Build and link program with object file - # $(compiler) $(needfpic) -Werror -std=c++11 -c main.cpp -o main.o - # # Link main program with test object file - # $(linker) -o main main.o test.o - # # Link main program with shared library - # $(linker) -o main main.o -L. -ltest - - # # Also make sure we can link to libtest (which may link to - # # libstdc++) with gcc (as in the C compiler). - # gcc -o main_c main.c -ltest -L. - # """ - # cmd = `/bin/bash -c "$(test_script)"` - # @test run(ur, cmd, iobuff; tee_stream=devnull) - # seekstart(iobuff) - # # Make sure `iobuff` contains only the input command, no other text - # is_broken = (compiler == "g++" && Sys.isapple(platform) && arch(platform) == "x86_64") # This gets fixed by using GCC7 or up - # @test readchomp(iobuff) == string(cmd) broken=is_broken - # end - # end + if isdir("/proc") && Sys.islinux() + isecfs = (false, "/proc/") + @test_logs (:info, "Checking to see if /proc/ is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc"; verbose=true) == isecfs + @test_logs (:info, "Checking to see if /proc/ is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc/"; verbose=true) == isecfs + @test_logs (:info, "Checking to see if /proc/not_a_file is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc/not_a_file"; verbose=true) == isecfs + elseif Sys.islinux() + @test_logs (:info, "Checking to see if /proc/ is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc"; verbose=true) == (false, "/proc") + @test_logs (:info, "Checking to see if /proc/ is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc/"; verbose=true) == (false, "/proc/") + @test_logs (:info, "Checking to see if /proc/not_a_file is encrypted...") @test BinaryBuilderBase.is_ecryptfs("/proc/not_a_file"; verbose=true) == (false, "/proc/not_a_file") + end + + if isa(preferred_runner(), BinaryBuilderBase.DockerRunner) + @testset "Docker image importing" begin + # First, delete the docker image, in case it already existed + BinaryBuilderBase.delete_docker_image() + + # Next, import it and ensure that doesn't throw + rootfs = first(BinaryBuilderBase.choose_shards(platform)) + mktempdir() do dir + @test BinaryBuilderBase.import_docker_image(rootfs, dir; verbose=true) === nothing + end + + # Test that deleting the docker image suceeds, now that we know + # it exists + @test BinaryBuilderBase.delete_docker_image() + end + end + + @testset "hello world" begin + mktempdir() do dir + # Make sure we can start a shell in a runner when the bootstrap list is non-empty + @eval BinaryBuilderBase push!(bootstrap_list, :rootfs, :platform_support) + ur = preferred_runner()(dir; platform=Platform("x86_64", "linux"; libc="musl")) + iobuff = IOBuffer() + @test run(ur, `/bin/bash -c "echo test"`, iobuff) + seek(iobuff, 0) + # Test that we get the output we expect (e.g. the second line is `test`) + @test readlines(iobuff)[2] == "test" + # Restore empty bootstrap list + @eval BinaryBuilderBase empty!(bootstrap_list) + end + end + + @testset "run_interactive" begin + platform = default_host_platform + io = IOBuffer() + @test run_interactive(preferred_runner()(mktempdir(); platform), `/bin/bash -c "echo hello world"`, stdout=io) + s = String(take!(io)) + @test s == "hello world\n" + # Make sure that `run_interactive` consistently throws an error when the process fails, + # whatever is the type of `stdout`, or it consistently ignores failures if so requested. + # Ref: https://github.com/JuliaPackaging/BinaryBuilderBase.jl/pull/201#issuecomment-1003192121 + cmd = `/bin/bash -c "false"` + @test_throws ProcessFailedException run_interactive(preferred_runner()(mktempdir(); platform), cmd) + @test_throws ProcessFailedException run_interactive(preferred_runner()(mktempdir(); platform), cmd; stdout=IOBuffer()) + cmd = Cmd(`/bin/bash -c "false"`; ignorestatus=true) + @test !run_interactive(preferred_runner()(mktempdir(); platform), cmd) + @test !run_interactive(preferred_runner()(mktempdir(); platform), cmd; stdout=IOBuffer()) + end + + if lowercase(get(ENV, "BINARYBUILDER_FULL_SHARD_TEST", "false")) == "true" + @info("Beginning full shard test... (this can take a while)") + platforms = supported_platforms() + else + platforms = (default_host_platform,) + end + + # Checks that the wrappers provide the correct C++ string ABI + @testset "Compilation - C++ string ABI" begin + mktempdir() do dir + # Host is x86_64-linux-musl-cxx11 and target is x86_64-linux-musl-cxx03 + ur = preferred_runner()(dir; platform=Platform("x86_64", "linux"; libc="musl", cxxstring_abi="cxx03"), preferred_gcc_version=v"5") + iobuff = IOBuffer() + test_script = raw""" + set -e + + # Building for the target uses C++03 string ABI + echo 'int main() {return 0;}' | SUPER_VERBOSE=1 ${CC} -x c - 2>&1 | grep -- "-D_GLIBCXX_USE_CXX11_ABI=0" + + # Building for the host uses C++11 string ABI + echo 'int main() {return 0;}' | SUPER_VERBOSE=1 ${HOSTCC} -x c - 2>&1 | grep -v -- "-D_GLIBCXX_USE_CXX11_ABI=0" + """ + @test run(ur, `/bin/bash -c "$(test_script)"`, iobuff; tee_stream=devnull) + end + end + + # This tests only that compilers for all platforms can build and link simple C code + @testset "Compilation - $(platform) - $(compiler)" for platform in platforms, compiler in ("cc", "gcc", "clang") + mktempdir() do dir + # if compiler == "clang" + # ur = preferred_runner()(dir; platform=platform, preferred_gcc_version=v"5") #TODO: Fix CI disk size issues to allow this + # else + # ur = preferred_runner()(dir; platform=platform) + # end + ur = preferred_runner()(dir; platform=platform) + iobuff = IOBuffer() + test_c = """ + #include + int test(void) { + return 0; + } + """ + main_c = """ + int test(void); + int main(void) { + return test(); + } + """ + test_script = """ + set -e + # Make sure setting `CCACHE` doesn't affect the compiler wrappers. + export CCACHE=pwned + export USE_CCACHE=false + echo '$(test_c)' > test.c + echo '$(main_c)' > main.c + # Build object file + $(compiler) -Werror -c test.c -o test.o + # Build shared library + $(compiler) -Werror -shared test.c -o libtest.\${dlext} + # Build and link program with object file + $(compiler) -Werror -o main main.c test.o + # Build and link program with shared library + $(compiler) -Werror -o main main.c -L. -ltest + """ + cmd = `/bin/bash -c "$(test_script)"` + @test run(ur, cmd, iobuff) + seekstart(iobuff) + # Make sure `iobuff` contains only the input command, no other text + @test readchomp(iobuff) == string(cmd) + end + end + + # This tests only that compilers for all platforms can build and link simple C++ code + # Note: we test the slightly weird `clang -x c++` as compiler driver because that's used + # in some cases and we want to make sure it works correctly. + @testset "Compilation - $(platform) - $(compiler)" for platform in platforms, (compiler, linker) in (("c++", "c++"), ("g++", "g++"), ("clang -x c++", "clang++")) + mktempdir() do dir + ur = preferred_runner()(dir; platform=platform) + iobuff = IOBuffer() + needfpic = Sys.iswindows(platform) ? "" : "-fPIC" + test_cpp = """ + #include + std::complex add(std::complex a, std::complex b) { + return a + b; + } + """ + main_cpp = """ + #include + std::complex add(std::complex a, std::complex b); + int main(void) { + std::complex z3 = add(std::complex(1.,2.),std::complex(4.,2.)); + return 0; + } + """ + main_c = """ + int main(void) { + return 0; + } + """ + test_script = """ + set -e + echo '$(test_cpp)' > test.cpp + echo '$(main_cpp)' > main.cpp + echo '$(main_c)' > main.c + # Make sure setting `CCACHE` doesn't affect the compiler wrappers. + export CCACHE=pwned + export USE_CCACHE=true + # Build object file + $(compiler) $(needfpic) -Werror -std=c++11 -c test.cpp -o test.o + # Link shared library + $(linker) -shared test.o -o libtest.\${dlext} + # Build and link program with object file + $(compiler) $(needfpic) -Werror -std=c++11 -c main.cpp -o main.o + # Link main program with test object file + $(linker) -o main main.o test.o + # Link main program with shared library + $(linker) -o main main.o -L. -ltest + + # Also make sure we can link to libtest (which may link to + # libstdc++) with gcc (as in the C compiler). + gcc -o main_c main.c -ltest -L. + """ + cmd = `/bin/bash -c "$(test_script)"` + @test run(ur, cmd, iobuff; tee_stream=devnull) + seekstart(iobuff) + # Make sure `iobuff` contains only the input command, no other text + is_broken = (compiler == "g++" && Sys.isapple(platform) && arch(platform) == "x86_64") # This gets fixed by using GCC7 or up + @test readchomp(iobuff) == string(cmd) broken=is_broken + end + end # This tests that compilers for all Intel Linux platforms can build simple # C, C++, Fortran programs that we can also run @testset "Compilation and running" begin platforms = filter(p -> Sys.islinux(p) && proc_family(p) == "intel", supported_platforms()) - # @testset "C - $(platform)" for platform in platforms - # mktempdir() do dir - # ur = preferred_runner()(dir; platform=platform) - # iobuff = IOBuffer() - # test_c = """ - # #include - # int main() { - # printf("Hello World!\\n"); - # return 0; - # } - # """ - # cmd = `/bin/bash -c "echo '$(test_c)' > test.c && cc -o test test.c && ./test 2>&1"` - # @test run(ur, cmd, iobuff; tee_stream=stdout) - # seekstart(iobuff) - # # Test that we get the output we expect - # @test endswith(readchomp(iobuff), "Hello World!") - # end - # end - - # @testset "C and link to quadmath - $(platform)" for platform in platforms - # mktempdir() do dir - # # Use a recent GCC with libgfortran5 - # options = (preferred_gcc_version=v"9", compilers=[:c]) - # shards = choose_shards(platform; options...) - # concrete_platform = get_concrete_platform(platform, shards) - # prefix = setup_workspace( - # dir, - # [], - # concrete_platform, - # default_host_platform; - # ) - # # Install `MPICH_jll` in the `${prefix}` to make sure we can link to - # # libquadmath without problems, see - # # https://github.com/JuliaPackaging/BinaryBuilderBase.jl/pull/157#issuecomment-879263820 - # version = VERSION≥v"1.9.0-" ? v"3.4.2+0" : v"3.4.2" # From Julia v1.9, JLLs need to specify the build number - # artifact_paths = - # setup_dependencies(prefix, - # [PackageSpec(; name="MPICH_jll", version)], - # concrete_platform, verbose=false) - # ur = preferred_runner()(prefix.path; - # platform=concrete_platform, - # shards = shards, - # options...) - # iobuff = IOBuffer() - # test_c = """ - # #include - # int main() { - # printf("Hello World!\\n"); - # return 0; - # } - # """ - # test_script = """ - # set -e - # echo '$(test_c)' > test.c - # # Make sure we can compile successfully also when linking to libmpifort - # cc -o test test.c -L\${libdir} -lmpifort -lquadmath - # ./test - # """ - # cmd = `/bin/bash -c "$(test_script)"` - # if arch(platform) == "i686" && libc(platform) == "musl" - # # We can't run this program for this platform - # @test_broken run(ur, cmd, iobuff; tee_stream=devnull) - # else - # @test run(ur, cmd, iobuff; tee_stream=devnull) - # seekstart(iobuff) - # # Test that we get the output we expect - # @test endswith(readchomp(iobuff), "Hello World!") - # end - # cleanup_dependencies(prefix, artifact_paths, concrete_platform) - # end - # end + @testset "C - $(platform)" for platform in platforms + mktempdir() do dir + ur = preferred_runner()(dir; platform=platform) + iobuff = IOBuffer() + test_c = """ + #include + int main() { + printf("Hello World!\\n"); + return 0; + } + """ + cmd = `/bin/bash -c "echo '$(test_c)' > test.c && cc -o test test.c && ./test"` + @test run(ur, cmd, iobuff; tee_stream=devnull) + seekstart(iobuff) + # Test that we get the output we expect + @test endswith(readchomp(iobuff), "Hello World!") + end + end + + @testset "C and link to quadmath - $(platform)" for platform in platforms + mktempdir() do dir + # Use a recent GCC with libgfortran5 + options = (preferred_gcc_version=v"9", compilers=[:c]) + shards = choose_shards(platform; options...) + concrete_platform = get_concrete_platform(platform, shards) + prefix = setup_workspace( + dir, + [], + concrete_platform, + default_host_platform; + ) + # Install `MPICH_jll` in the `${prefix}` to make sure we can link to + # libquadmath without problems, see + # https://github.com/JuliaPackaging/BinaryBuilderBase.jl/pull/157#issuecomment-879263820 + version = VERSION≥v"1.9.0-" ? v"3.4.2+0" : v"3.4.2" # From Julia v1.9, JLLs need to specify the build number + artifact_paths = + setup_dependencies(prefix, + [PackageSpec(; name="MPICH_jll", version)], + concrete_platform, verbose=false) + ur = preferred_runner()(prefix.path; + platform=concrete_platform, + shards = shards, + options...) + iobuff = IOBuffer() + test_c = """ + #include + int main() { + printf("Hello World!\\n"); + return 0; + } + """ + test_script = """ + set -e + echo '$(test_c)' > test.c + # Make sure we can compile successfully also when linking to libmpifort + cc -o test test.c -L\${libdir} -lmpifort -lquadmath + ./test + """ + cmd = `/bin/bash -c "$(test_script)"` + if arch(platform) == "i686" && libc(platform) == "musl" + # We can't run this program for this platform + @test_broken run(ur, cmd, iobuff; tee_stream=devnull) + else + @test run(ur, cmd, iobuff; tee_stream=devnull) + seekstart(iobuff) + # Test that we get the output we expect + @test endswith(readchomp(iobuff), "Hello World!") + end + cleanup_dependencies(prefix, artifact_paths, concrete_platform) + end + end @testset "C++ - $(platform)" for platform in platforms mktempdir() do dir @@ -374,7 +374,7 @@ using Pkg # Make sure we can compile successfully also when `\${libdir}` is in the # linker search path c++ -o test test.cpp -L\${libdir} - ./test 2>&1 + ./test """ cmd = `/bin/bash -c "$(test_script)"` if arch(platform) == "i686" && libc(platform) == "musl" @@ -390,193 +390,193 @@ using Pkg end end - # # This tests that compilers for all Intel Linux platforms can build a simple - # # Fortran program that we can also run - # @testset "Fortran - $(platform)" for platform in platforms - # mktempdir() do dir - # ur = preferred_runner()(dir; platform=platform) - # iobuff = IOBuffer() - # test_f = """ - # program hello - # print *, "Hello World!" - # end program - # """ - # cmd = `/bin/bash -c "echo '$(test_f)' > test.f && gfortran -o test test.f && ./test"` - # if arch(platform) == "i686" && libc(platform) == "musl" - # # We can't run Fortran programs for this platform - # @test_broken run(ur, cmd, iobuff; tee_stream=devnull) - # else - # @test run(ur, cmd, iobuff; tee_stream=devnull) - # seekstart(iobuff) - # # Test that we get the output we expect - # @test endswith(readchomp(iobuff), "Hello World!") - # end - # end - # end - # end - - # @testset "Locking microarchitecture" begin - # mktempdir() do dir - # platform = Platform("x86_64", "linux"; libc="musl") - # cmd = `/bin/bash -c "echo 'int main() {return 0;}' | cc -x c -march=native -"` - # ur = preferred_runner()(dir; platform=platform, lock_microarchitecture=true) - # iobuff = IOBuffer() - # @test !run(ur, cmd, iobuff; tee_stream=devnull) - # seekstart(iobuff) - # @test readlines(iobuff)[2] == "BinaryBuilder: Cannot force an architecture via -march" - - # ur = preferred_runner()(dir; platform=platform, lock_microarchitecture=false) - # iobuff = IOBuffer() - # @test run(ur, cmd, iobuff; tee_stream=devnull) - # seekstart(iobuff) - # @test split(String(read(iobuff)), "\n")[2] == "" - # end - # end - - # @testset "Unsafe flags" begin - # mktempdir() do dir - # platform = Platform("x86_64", "linux"; libc="musl") - # cmd = `/bin/bash -c "echo 'int main() {return 0;}' | cc -x c -Ofast -"` - # ur = preferred_runner()(dir; platform=platform, allow_unsafe_flags=false) - # iobuff = IOBuffer() - # @test !run(ur, cmd, iobuff; tee_stream=devnull) - # seekstart(iobuff) - # lines = readlines(iobuff) - # @test lines[2] == "BinaryBuilder error: You used one or more of the unsafe flags: -Ofast, -ffast-math, -funsafe-math-optimizations" - # @test lines[3] == "This is not allowed, please remove all unsafe flags from your build script to continue." - - # ur = preferred_runner()(dir; platform=platform, allow_unsafe_flags=true) - # iobuff = IOBuffer() - # @test run(ur, cmd, iobuff; tee_stream=devnull) - # seekstart(iobuff) - # @test split(String(read(iobuff)), "\n")[2] == "" - # end - # end - - # @testset "macOS SDK setting" begin - # mktempdir() do dir - # platform = Platform("x86_64", "macos") - # test_script = raw""" - # set -e - # prog='int main(void) { return 0; }' - # echo "${prog}" | clang -x c - -o test-clang - # otool -lV test-clang | grep sdk - # # Set `MACOSX_DEPLOYMENT_TARGET` to override the value of the SDK - # export MACOSX_DEPLOYMENT_TARGET=10.14 - # echo "${prog}" | gcc -x c - -o test-gcc - # otool -lV test-gcc | grep sdk - # """ - # cmd = `/bin/bash -c "$(test_script)"` - # ur = preferred_runner()(dir; platform=platform, allow_unsafe_flags=false) - # iobuff = IOBuffer() - # @test run(ur, cmd, iobuff; tee_stream=devnull) - # seekstart(iobuff) - # lines = readlines(iobuff) - # # Make sure the SDK for this platform is set to 10.10, instead of other wrong - # # values, and that we can set `MACOSX_DEPLOYMENT_TARGET` to control the value. - # @test contains(lines[end - 1], r"^ +sdk 10\.10$") - # @test contains(lines[end], r"^ +sdk 10\.14$") - # end - # end - - # @testset "Test lld usage" begin - # mktempdir() do dir - # ur = preferred_runner()(dir; platform=Platform("x86_64", "windows"), preferred_gcc_version=v"6") - # iobuff = IOBuffer() - # test_c = """ - # #include - # int test(void) { - # return 0; - # } - # """ - # test_script = """ - # set -e - # echo '$(test_c)' > test.c - # clang -Werror -shared test.c -o libtest.\${dlext} - # """ - # cmd = `/bin/bash -c "$(test_script)"` - # @test run(ur, cmd, iobuff) - - # test_script = """ - # set -e - # echo '$(test_c)' > test.c - # clang -Werror -v -shared test.c -o libtest.\${dlext} - # """ - # iobuff = IOBuffer() - # cmd = `/bin/bash -c "$(test_script)"` - # @test run(ur, cmd, iobuff) - # seekstart(iobuff) - # @test occursin(r"ld.lld", readchomp(iobuff)) - # end - - # mktempdir() do dir - # ur = preferred_runner()(dir; platform=Platform("x86_64", "linux", libc="musl"), preferred_gcc_version=v"9") - # iobuff = IOBuffer() - # test_c = """ - # #include - # int test(void) { - # return 0; - # } - # """ - # test_script = """ - # set -e - # echo '$(test_c)' > test.c - # gcc -Werror -shared test.c -fuse-ld=lld -o libtest.\${dlext} - # """ - # cmd = `/bin/bash -c "$(test_script)"` - # @test run(ur, cmd, iobuff) - - # test_script = """ - # set -e - # echo '$(test_c)' > test.c - # gcc -Werror -v -shared test.c -fuse-ld=lld -o libtest.\${dlext} - # """ - # iobuff = IOBuffer() - # cmd = `/bin/bash -c "$(test_script)"` - # @test run(ur, cmd, iobuff) - # seekstart(iobuff) - # @test occursin(r"lld", readchomp(iobuff)) - # end - - # mktempdir() do dir - # platform = Platform("x86_64", "linux", libc="musl") - # ur = preferred_runner()(dir; platform, preferred_gcc_version=v"9", clang_use_lld=false) - # iobuff = IOBuffer() - # test_script = raw""" - # cat $(which clang) - # """ - # cmd = `/bin/bash -c "$(test_script)"` - # @test run(ur, cmd, iobuff) - # seekstart(iobuff) - # @test occursin("-fuse-ld=$(aatriplet(platform))", readchomp(iobuff)) - # end + # This tests that compilers for all Intel Linux platforms can build a simple + # Fortran program that we can also run + @testset "Fortran - $(platform)" for platform in platforms + mktempdir() do dir + ur = preferred_runner()(dir; platform=platform) + iobuff = IOBuffer() + test_f = """ + program hello + print *, "Hello World!" + end program + """ + cmd = `/bin/bash -c "echo '$(test_f)' > test.f && gfortran -o test test.f && ./test"` + if arch(platform) == "i686" && libc(platform) == "musl" + # We can't run Fortran programs for this platform + @test_broken run(ur, cmd, iobuff; tee_stream=devnull) + else + @test run(ur, cmd, iobuff; tee_stream=devnull) + seekstart(iobuff) + # Test that we get the output we expect + @test endswith(readchomp(iobuff), "Hello World!") + end + end + end + end + + @testset "Locking microarchitecture" begin + mktempdir() do dir + platform = Platform("x86_64", "linux"; libc="musl") + cmd = `/bin/bash -c "echo 'int main() {return 0;}' | cc -x c -march=native -"` + ur = preferred_runner()(dir; platform=platform, lock_microarchitecture=true) + iobuff = IOBuffer() + @test !run(ur, cmd, iobuff; tee_stream=devnull) + seekstart(iobuff) + @test readlines(iobuff)[2] == "BinaryBuilder: Cannot force an architecture via -march" + + ur = preferred_runner()(dir; platform=platform, lock_microarchitecture=false) + iobuff = IOBuffer() + @test run(ur, cmd, iobuff; tee_stream=devnull) + seekstart(iobuff) + @test split(String(read(iobuff)), "\n")[2] == "" + end + end + + @testset "Unsafe flags" begin + mktempdir() do dir + platform = Platform("x86_64", "linux"; libc="musl") + cmd = `/bin/bash -c "echo 'int main() {return 0;}' | cc -x c -Ofast -"` + ur = preferred_runner()(dir; platform=platform, allow_unsafe_flags=false) + iobuff = IOBuffer() + @test !run(ur, cmd, iobuff; tee_stream=devnull) + seekstart(iobuff) + lines = readlines(iobuff) + @test lines[2] == "BinaryBuilder error: You used one or more of the unsafe flags: -Ofast, -ffast-math, -funsafe-math-optimizations" + @test lines[3] == "This is not allowed, please remove all unsafe flags from your build script to continue." + + ur = preferred_runner()(dir; platform=platform, allow_unsafe_flags=true) + iobuff = IOBuffer() + @test run(ur, cmd, iobuff; tee_stream=devnull) + seekstart(iobuff) + @test split(String(read(iobuff)), "\n")[2] == "" + end + end + + @testset "macOS SDK setting" begin + mktempdir() do dir + platform = Platform("x86_64", "macos") + test_script = raw""" + set -e + prog='int main(void) { return 0; }' + echo "${prog}" | clang -x c - -o test-clang + otool -lV test-clang | grep sdk + # Set `MACOSX_DEPLOYMENT_TARGET` to override the value of the SDK + export MACOSX_DEPLOYMENT_TARGET=10.14 + echo "${prog}" | gcc -x c - -o test-gcc + otool -lV test-gcc | grep sdk + """ + cmd = `/bin/bash -c "$(test_script)"` + ur = preferred_runner()(dir; platform=platform, allow_unsafe_flags=false) + iobuff = IOBuffer() + @test run(ur, cmd, iobuff; tee_stream=devnull) + seekstart(iobuff) + lines = readlines(iobuff) + # Make sure the SDK for this platform is set to 10.10, instead of other wrong + # values, and that we can set `MACOSX_DEPLOYMENT_TARGET` to control the value. + @test contains(lines[end - 1], r"^ +sdk 10\.10$") + @test contains(lines[end], r"^ +sdk 10\.14$") + end + end + + @testset "Test lld usage" begin + mktempdir() do dir + ur = preferred_runner()(dir; platform=Platform("x86_64", "windows"), preferred_gcc_version=v"6") + iobuff = IOBuffer() + test_c = """ + #include + int test(void) { + return 0; + } + """ + test_script = """ + set -e + echo '$(test_c)' > test.c + clang -Werror -shared test.c -o libtest.\${dlext} + """ + cmd = `/bin/bash -c "$(test_script)"` + @test run(ur, cmd, iobuff) + + test_script = """ + set -e + echo '$(test_c)' > test.c + clang -Werror -v -shared test.c -o libtest.\${dlext} + """ + iobuff = IOBuffer() + cmd = `/bin/bash -c "$(test_script)"` + @test run(ur, cmd, iobuff) + seekstart(iobuff) + @test occursin(r"ld.lld", readchomp(iobuff)) + end + + mktempdir() do dir + ur = preferred_runner()(dir; platform=Platform("x86_64", "linux", libc="musl"), preferred_gcc_version=v"9") + iobuff = IOBuffer() + test_c = """ + #include + int test(void) { + return 0; + } + """ + test_script = """ + set -e + echo '$(test_c)' > test.c + gcc -Werror -shared test.c -fuse-ld=lld -o libtest.\${dlext} + """ + cmd = `/bin/bash -c "$(test_script)"` + @test run(ur, cmd, iobuff) + + test_script = """ + set -e + echo '$(test_c)' > test.c + gcc -Werror -v -shared test.c -fuse-ld=lld -o libtest.\${dlext} + """ + iobuff = IOBuffer() + cmd = `/bin/bash -c "$(test_script)"` + @test run(ur, cmd, iobuff) + seekstart(iobuff) + @test occursin(r"lld", readchomp(iobuff)) + end + + mktempdir() do dir + platform = Platform("x86_64", "linux", libc="musl") + ur = preferred_runner()(dir; platform, preferred_gcc_version=v"9", clang_use_lld=false) + iobuff = IOBuffer() + test_script = raw""" + cat $(which clang) + """ + cmd = `/bin/bash -c "$(test_script)"` + @test run(ur, cmd, iobuff) + seekstart(iobuff) + @test occursin("-fuse-ld=$(aatriplet(platform))", readchomp(iobuff)) + end end end -# @testset "Shards" begin -# # Run the testsuite as sanity check -# @testset "testsuite" begin -# mktempdir() do dir -# # Skip Rust tests when they are broken. Ref: -# # https://github.com/JuliaPackaging/BinaryBuilderBase.jl/issues/395 -# compilers = if !BinaryBuilderBase.use_squashfs[] && get(ENV, "BINARYBUILDER_RUNNER", "") == "unprivileged" -# [:c, :go] -# else -# [:c, :rust, :go] -# end -# ur = preferred_runner()(dir; platform=Platform("x86_64", "linux"; libc="glibc"), preferred_gcc_version=v"5", compilers) -# # Make sure the runner platform is concrete even if the requested platform isn't -# @test !isnothing(libgfortran_version(ur.platform)) -# @test !isnothing(cxxstring_abi(ur.platform)) -# iobuff = IOBuffer() -# test_script = raw""" -# set -e -# make -j${nproc} -sC /usr/share/testsuite install -# """ -# @test run(ur, `/bin/bash -c "$(test_script)"`, iobuff) -# end -# end -# end +@testset "Shards" begin + # Run the testsuite as sanity check + @testset "testsuite" begin + mktempdir() do dir + # Skip Rust tests when they are broken. Ref: + # https://github.com/JuliaPackaging/BinaryBuilderBase.jl/issues/395 + compilers = if !BinaryBuilderBase.use_squashfs[] && get(ENV, "BINARYBUILDER_RUNNER", "") == "unprivileged" + [:c, :go] + else + [:c, :rust, :go] + end + ur = preferred_runner()(dir; platform=Platform("x86_64", "linux"; libc="glibc"), preferred_gcc_version=v"5", compilers) + # Make sure the runner platform is concrete even if the requested platform isn't + @test !isnothing(libgfortran_version(ur.platform)) + @test !isnothing(cxxstring_abi(ur.platform)) + iobuff = IOBuffer() + test_script = raw""" + set -e + make -j${nproc} -sC /usr/share/testsuite install + """ + @test run(ur, `/bin/bash -c "$(test_script)"`, iobuff) + end + end +end diff --git a/test/runtests.jl b/test/runtests.jl index 4ed9548e..51f6d96e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,10 +1,10 @@ # Run all our tests -# include("compat.jl") -# include("archive_utils.jl") -# include("dependencies.jl") -# include("platforms.jl") -# include("prefix.jl") -# include("products.jl") -# include("sources.jl") -# include("rootfs.jl") +include("compat.jl") +include("archive_utils.jl") +include("dependencies.jl") +include("platforms.jl") +include("prefix.jl") +include("products.jl") +include("sources.jl") +include("rootfs.jl") include("runners.jl") From 994ba38f3268659ce1c2602d6dffd871aae68e2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mos=C3=A8=20Giordano?= Date: Wed, 30 Apr 2025 18:47:29 +0100 Subject: [PATCH 5/5] [Runner] Fix order order of CSL libraries in `LD_LIBRARY_PATH` Move target before host. --- src/Runner.jl | 2 +- test/runners.jl | 26 ++++++++------------------ 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/Runner.jl b/src/Runner.jl index 7b2e0954..4544892d 100644 --- a/src/Runner.jl +++ b/src/Runner.jl @@ -75,7 +75,7 @@ function ld_library_path(target::AbstractPlatform, # that can natively run within this environment if csl_paths append!(paths, - unique("/usr/lib/csl-$(libc(p))-$(arch(p))" for p in (host, target) if Sys.islinux(p) && proc_family(p) == "intel"), + unique("/usr/lib/csl-$(libc(p))-$(arch(p))" for p in (target, host) if Sys.islinux(p) && proc_family(p) == "intel"), ) end diff --git a/test/runners.jl b/test/runners.jl index a2be2424..a8b9f515 100644 --- a/test/runners.jl +++ b/test/runners.jl @@ -322,15 +322,10 @@ end ./test """ cmd = `/bin/bash -c "$(test_script)"` - if arch(platform) == "i686" && libc(platform) == "musl" - # We can't run this program for this platform - @test_broken run(ur, cmd, iobuff; tee_stream=devnull) - else - @test run(ur, cmd, iobuff; tee_stream=devnull) - seekstart(iobuff) - # Test that we get the output we expect - @test endswith(readchomp(iobuff), "Hello World!") - end + @test run(ur, cmd, iobuff; tee_stream=devnull) + seekstart(iobuff) + # Test that we get the output we expect + @test endswith(readchomp(iobuff), "Hello World!") cleanup_dependencies(prefix, artifact_paths, concrete_platform) end end @@ -377,15 +372,10 @@ end ./test """ cmd = `/bin/bash -c "$(test_script)"` - if arch(platform) == "i686" && libc(platform) == "musl" - # We can't run C++ programs for this platform - @test_broken run(ur, cmd, iobuff; tee_stream=devnull) - else - @test run(ur, cmd, iobuff; tee_stream=stdout) - seekstart(iobuff) - # Test that we get the output we expect - @test endswith(readchomp(iobuff), "Hello World!") - end + @test run(ur, cmd, iobuff; tee_stream=stdout) + seekstart(iobuff) + # Test that we get the output we expect + @test endswith(readchomp(iobuff), "Hello World!") cleanup_dependencies(prefix, artifact_paths, concrete_platform) end end