Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Runner] Improve compile-only flags checks and fix objc wrapper #148

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BinaryBuilderBase"
uuid = "7f725544-6523-48cd-82d1-3fa08ff4056e"
authors = ["Elliot Saba <[email protected]>"]
version = "0.6.5"
version = "0.6.6"

[deps]
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"
Expand Down
10 changes: 5 additions & 5 deletions src/Runner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
println(io)
end

# If we're given compile-only flags, include them only if `-x assembler` is not provided
# If we're given compile-only flags, include them only if `-x assembler` is not provided,
# or no object files (*.o) are passed in input
if !isempty(compile_only_flags)
println(io)
println(io, "if [[ \" \${ARGS[@]} \" != *' -x assembler '* ]]; then")
println(io, "if [[ \" \${ARGS[@]} \" != *' -x assembler '* ]] && [[ \" \${ARGS[@]} \" != *'.o '* ]]; then")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a hard problem to solve. I'm honestly not sure what to do here.

On the one hand, we need a way to tell clang that it should be in -x objc mode, but it throws an error if we're linking..... On modern macs, the objc executable doesn't even exist, so perhaps this whole compiler wrapper is just a bad idea. What software are you building that needs this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meson needs it...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this is the problem: we need to specify an Objective-C compiler in the Meson cross-file:

objc = '/opt/bin/$(target)/$(aatarget)-objc'

Meson is very strict in many ways, I'm 99% sure it won't accept something like clang -x objective-c, and anyways it uses the compiler also as linker (which is what's happening in JuliaPackaging/Yggdrasil#91 (comment)).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhm, let me see if I can do it with

objc = '/opt/bin/$(target)/$(aatarget)-clang'
# ...
objc_args = ['-x objective-c']

for cf in compile_only_flags
println(io, " PRE_FLAGS+=( $cf )")
end
Expand Down Expand Up @@ -389,13 +390,12 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
)
end

function clang_wrapper(io::IO, tool::String, p::AbstractPlatform, extra_flags::Vector{String} = String[])
function clang_wrapper(io::IO, tool::String, p::AbstractPlatform, compile_flags::Vector{String} = String[])
flags = clang_flags!(p)
append!(flags, extra_flags)
return wrapper(io,
"/opt/$(host_target)/bin/$(tool)";
flags=flags,
compile_only_flags=clang_compile_flags!(p),
compile_only_flags=clang_compile_flags!(p, compile_flags),
link_only_flags=clang_link_flags!(p),
no_soft_float=arch(p) in ("armv6l", "armv7l"),
)
Expand Down
28 changes: 28 additions & 0 deletions test/runners.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,34 @@ end
@test endswith(readchomp(iobuff), "Hello World!")
end
end

@testset "Objective-C - $(platform)" for platform in filter(Sys.isapple, supported_platforms())
ur = preferred_runner()(dir; platform=platform)
iobuff = IOBuffer()
test_objc = """
#import <Foundation/Foundation.h>
void test() {
@autoreleasepool {
NSLog(@"Hello, World!");
}
}
"""
script = """
echo '$(test_objc)' > test.m
# Build the shared library in two steps: first compile object file...
objc -c -o test.o test.m
# ...and then link it to a shared library.
objc -shared -o test.dylib -framework Foundation test.o
file test.dylib
"""
cmd = `/bin/bash -ec "$(script)"`
@test run(ur, cmd, iobuff; tee_stream=devnull)
seekstart(iobuff)
# Test that we get the output we expect
_arch = arch(platform) == "aarch64" ? "arm64" : arch(platform)
@test occursin("test.dylib: Mach-O 64-bit $(_arch) dynamically linked shared library", readchomp(iobuff))
end

end
end

Expand Down