Skip to content

Commit

Permalink
[Runner] Improve compile-only flags checks and fix objc wrapper
Browse files Browse the repository at this point in the history
The `objc` wrapper is currently roughly equivalent to `clang -x objective-c`,
the problem is that `-x <LANG>` can't be used when linking, otherwise the
compiler driver will assume that the input files are plain text source code
files.

As a simple rule, we assume that we are compiling (as opposed to linking) when
no argument is an object file (ending with `.o` extension) and make the `objc`
wrapper pass the `-x objective-c` flag only when compiling (and not linking),
instead of doing so unconditionally.
  • Loading branch information
giordano committed May 18, 2021
1 parent cd3f4d1 commit cf78aa0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
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")
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 -c "$(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(r"^test.dylib: Mach-O $(_arch) dynamically linked shared library", readchomp(iobuff))
end

end
end

Expand Down

0 comments on commit cf78aa0

Please sign in to comment.