I’ve just starting adding libvips for the C interop example, which you can see in nb sox_integration_example.ipynb. First you’ll need to install libvips, following SwiftVips/install.sh docs.
After I import SwiftVips or import vips I get the dreaded expression failed to parse, unknown error. @marcrasi any chance you could take a look since this is a blocker for this part of the next lesson? @pcuenq do you have any insights on what might be happening here?
I got a previous error while linking. String(cString: dlerror()) reports that libvips.so.42 cannot be found, but it does exist in my machine. Did you have that error?
I got rid of that but I still get the parse error. What I’ve seen so far is that libvips depends on glib and glib-object. I’ve tried to define explicit system library dependencies for them; or link them inside the vips module map file, but I’ve had no success so far.
Interesting. I had a similar problem when I tried to use a glib-requiring lib a while ago and didn’t use spm - instead I tried to use an objc bridging header. I never figured out how to get it working.
More specifically, this is the error message from the REPL:
Welcome to Swift version 5.0-dev (LLVM dcb9eb74a7, Clang 95cdf7c9af, Swift ec27d9b99d).
Type :help for assistance.
1>
2>
3>
4> import Glibc
5> let h = dlopen("package/.build/x86_64-unknown-linux/debug/libjupyterInstalledPackages.so", RTLD_NOW)
h: UnsafeMutableRawPointer? = (_rawValue = 0x000000000134cb70)
6> import vips
warning: Swift error in fallback scratch context: <module-includes>:1:10: note: in file included from <module-includes>
:1:
#include "/home/pedro/code/s4tf/fastai_docs/dev_swift/SwiftVips/Sources/vips/shim.h"
^
/home/pedro/code/s4tf/fastai_docs/dev_swift/SwiftVips/Sources/vips/shim.h:1:10: note: in file included from /home/pedro
/code/s4tf/fastai_docs/dev_swift/SwiftVips/Sources/vips/shim.h:1:
#include <vips/vips.h>
^
error: /usr/local/include/vips/vips.h:87:10: error: 'glib.h' file not found
#include <glib.h>
^
error: repl.swift:6:8: error: could not build C module 'vips'
import vips
^
note: This error message is displayed only once. If the error displayed above is due to conflicting search paths to Cla
ng modules in different images of the debugged executable, this can slow down debugging of Swift code significantly, si
nce a fresh Swift context has to be created every time a conflict is encountered.
expression failed to parse, unknown error
I’m guessing there are some system module maps that are not being correctly prepared in the install directory. I tried to force it by defining pkg-config dependencies for them, but it didn’t work. I’ll see if I can get some info from the build.db database, maybe we can whitelist them.
So why aren’t those headers available? Shouldn’t they have been compiled in to the swiftmodule somehow? I don’t understand how swiftmodules work - but I thought they had the symbol info in them?..
According to the source, the arguments has to be a list. Is there another way you know of to pass command-line arguments to the swift process? Or is repl_swift perhaps ignoring them?
@jeremy This ugly workaround does indeed work in my system:
cd /usr/include
for f in /usr/include/glib-2.0/*; do sudo ln -s $f .; done
for f in /usr/lib/x86_64-linux-gnu/glib-2.0/include/*; do sudo ln -s $f .; done
Nevertheless we need to figure out how to make it work inside the jupyter kernel, now that we know that there are additional arguments that need to be observed.
It is not possible to pass commandline arguments to the swift compiler in the Jupyter kernel, because it invokes the compiler stages directly without going through any commandline flag processing code. (This “LaunchSimple” method passes commandline arguments to the “Swift program” itself, not to the compiler.)
It is just a few extra -I arguments that we need? The SWIFT_IMPORT_SEARCH_PATH env variable that I recently added (https://github.com/apple/swift-lldb/commit/bdb96e8b352f7cb18e2b3b66f2d3f75d92f81dcd) does the same thing as -I, except that it works in the Jupyter kernel. Unfortunately, it can only do one and it’s already being used for package installation. But I could add support for more pretty easily if that’s all we need.
^ Those are all the thoughts that I have without having actually tried this out myself. I will try it out myself Monday morning and see if I can figure anything out!