Disable objc interop


(Scott Knight) #1

I've been trying to look if there's a way with swift build or swiftc itself
to disable objective-c interoperability. I've gotten as far as inspecting
the IR output with the disable-obc-interop flag with this command

swiftc -emit-ir -Xfrontend -disable-llvm-optzns -Xfrontend
-disable-objc-interop -O Sources/main.swift

But I haven't been able to figure out if there's a way to do this with
swift build. No matter what I do when I inspect the compiled binary

otool -L .build/debug/Test
.build/debug/Hello:
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version
228.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version
1226.10.1)
@rpath/libswiftCore.dylib (compatibility version 0.0.0, current version
0.0.0)

libobjc is always linked in. I ran the emit-ir command above both with and
without disable-obc-interop and could see in the emitted IR that this line
was removed when using the disable-obc-interop flag

!7 = !{!"-lobjc"}

Is there something I'm missing or is this just not supported currently? I
don't have a practical use case currently for this but was just curious to
better understand the swift runtime and internals.

Thanks,
Scott Knight


(Joe Groff) #2

This is just a bug. In theory you should be able to just remove the emission of that autolink entry. However, not much energy has been put into supporting ObjC-less Swift on Darwin, so expect other problems.

-Joe

···

On Feb 10, 2016, at 12:07 PM, Scott Knight via swift-dev <swift-dev@swift.org> wrote:

I've been trying to look if there's a way with swift build or swiftc itself to disable objective-c interoperability. I've gotten as far as inspecting the IR output with the disable-obc-interop flag with this command

swiftc -emit-ir -Xfrontend -disable-llvm-optzns -Xfrontend -disable-objc-interop -O Sources/main.swift

But I haven't been able to figure out if there's a way to do this with swift build. No matter what I do when I inspect the compiled binary

otool -L .build/debug/Test
.build/debug/Hello:
  /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
  /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
  @rpath/libswiftCore.dylib (compatibility version 0.0.0, current version 0.0.0)

libobjc is always linked in. I ran the emit-ir command above both with and without disable-obc-interop and could see in the emitted IR that this line was removed when using the disable-obc-interop flag

!7 = !{!"-lobjc"}

Is there something I'm missing or is this just not supported currently? I don't have a practical use case currently for this but was just curious to better understand the swift runtime and internals.