-
Notifications
You must be signed in to change notification settings - Fork 31
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
Conversation
d4bddee
to
f0e76f2
Compare
How to reproduce the error: % julia -e 'using BinaryBuilderBase; BinaryBuilderBase.runshell(Platform("x86_64", "macos"))'
sandbox:${WORKSPACE} # cat > test.m << EOF
> #import <Foundation/Foundation.h>
> void test() {
> @autoreleasepool {
> NSLog(@"Hello, World!");
> }
> }
> EOF
sandbox:${WORKSPACE} # objc -c -o test.o test.m
sandbox:${WORKSPACE} # objc -shared -o test.dylib -framework Foundation test.o
test.o:1:1: error: source file is not valid UTF-8
[...] # watch the input object file being dumped to the screen
fatal error: too many errors emitted, stopping now [-ferror-limit=]
522 warnings and 20 errors generated.
|
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.
if !isempty(compile_only_flags) | ||
println(io) | ||
println(io, "if [[ \" \${ARGS[@]} \" != *' -x assembler '* ]]; then") | ||
println(io, "if [[ \" \${ARGS[@]} \" != *' -x assembler '* ]] && [[ \" \${ARGS[@]} \" != *'.o '* ]]; then") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meson needs it...
There was a problem hiding this comment.
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:
BinaryBuilderBase.jl/src/BuildToolchains.jl
Line 167 in cd3f4d1
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)).
There was a problem hiding this comment.
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']
The
objc
wrapper is currently roughly equivalent toclang -x objective-c
,the problem is that
-x <LANG>
can't be used when linking, otherwise thecompiler 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 theobjc
wrapper pass the
-x objective-c
flag only when compiling (and not linking),instead of doing so unconditionally.
Issue spotted while building Glib: JuliaPackaging/Yggdrasil#91 (comment)