Mac OS Error
Hey, I would like to help you to make this project of yours work on MacOS too. I can help you with Testing and Error Reporting.
I tried and got the following error:
shabinder@Shabinders-MacBook-Pro spotify-adblock % make
# cargo build --profile release
cargo build --release
Updating crates.io index
Downloaded serde v1.0.125
Downloaded memchr v2.4.0
Downloaded regex v1.5.3
Downloaded serde_derive v1.0.125
Downloaded regex-syntax v0.6.25
Downloaded toml v0.5.8
Downloaded aho-corasick v0.7.18
Downloaded quote v1.0.9
Downloaded libc v0.2.94
Downloaded unicode-xid v0.2.2
Downloaded lazy_static v1.4.0
Downloaded proc-macro2 v1.0.26
Downloaded syn v1.0.72
Downloaded 13 crates (1.7 MB) in 1.77s
Compiling proc-macro2 v1.0.26
Compiling unicode-xid v0.2.2
Compiling syn v1.0.72
Compiling serde_derive v1.0.125
Compiling memchr v2.4.0
Compiling serde v1.0.125
Compiling libc v0.2.94
Compiling regex-syntax v0.6.25
Compiling lazy_static v1.4.0
Compiling aho-corasick v0.7.18
Compiling quote v1.0.9
Compiling regex v1.5.3
Compiling toml v0.5.8
Compiling spotify-adblock v1.0.0 (/Users/shabinder/Tools/spotify-adblock)
error: linking with `cc` failed: exit code: 1
|
= note: "cc" "-m64" "-arch" "x86_64" "-L" "/Users/shabinder/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/shabinder/Tools/spotify-adblock/target/release/deps/spotifyadblock.spotifyadblock.vnzrytk8-cgu.0.rcgu.o" "-o" "/Users/shabinder/Tools/spotify-adblock/target/release/deps/libspotifyadblock.dylib" "-Wl,-exported_symbols_list,/var/folders/95/yh3p7nfd1s7bgm_p58hvskh40000gn/T/rustcNpEzvF/list" "-Wl,-dead_strip" "-dynamiclib" "-Wl,-dylib" "-nodefaultlibs" "-L" "/Users/shabinder/Tools/spotify-adblock/target/release/deps" "-L" "/Users/shabinder/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/shabinder/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-f86ac61d31791301.rlib" "-liconv" "-lSystem" "-lresolv" "-lc" "-lm" "-liconv"
= note: Undefined symbols for architecture x86_64:
"_cef_string_userfree_utf16_free", referenced from:
_cef_urlrequest_create in spotifyadblock.spotifyadblock.vnzrytk8-cgu.0.rcgu.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: aborting due to previous error
error: could not compile `spotify-adblock`
To learn more, run the command again with --verbose.
make: *** [target/release/libspotifyadblock.so] Error 101
Thanks for offering to help! I've got no idea what's going on there, but there's also still some code missing to make this work on macOS anyway and I'll probably have to figure out a way to cross compile to macOS to work on and debug it. Can't really say when I'll have time to do that though.
I originally mentioned macOS in the readme, because I used redhook, which supposedly also works on macOS. I later removed that dependency, because it can only produce dylibs (not cdylibs), which are very large (~8 MB in this case) and should apparently only be linked with other Rust binaries.
maybe this repo can help, but unfortunately it based on previous version
I have found that adding
[target.x86_64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]
to your ./cargo/config successfully compiles the project. But on macOS it creates a .dylib instead of a .so file . Also
make install doesn't work because BSD install and GNU install doesn't have the same flags.
Hey @shoccho . Have you tried using the .dylib like this?
DYLD_INSERT_LIBRARIES=spotify-adblock.dylib /Applications/Spotify.app/Contents/MacOS/Spotify
Also, if it works, may I ask you to please share your compiled dylib with me? 😬
Hey @shoccho . Have you tried using the .dylib like this?
DYLD_INSERT_LIBRARIES=spotify-adblock.dylib /Applications/Spotify.app/Contents/MacOS/SpotifyAlso, if it works, may I ask you to please share your compiled dylib with me? 😬
Hey @alcmoraes - I've tried this solution and it did not work. We need a .so lib. It wont work without that.
Hey @shoccho . Have you tried using the .dylib like this?
DYLD_INSERT_LIBRARIES=spotify-adblock.dylib /Applications/Spotify.app/Contents/MacOS/SpotifyAlso, if it works, may I ask you to please share your compiled dylib with me? 😬
Hey @alcmoraes - I've tried this solution and it did not work. We need a
.solib. It wont work without that.
Likewise, there doesn't seem to be a great substitute for installing, but creating the .dylib file seems to be okay with a tweak? I didn't manage to get the build to compile with @shoccho solution exactly, but manually running this command did (almost the same thing, specifically referring to release and not target made it work?):
spotify-adblock % cargo rustc --release -- -C link-arg=-undefined -C link-arg=dynamic_lookup
(Somehow I also end up with a .d file which... I think means I've messed up some code somewhere.)
I genuinely do not have anywhere near the coding understanding required to try and allow 'sudo make install' to work or get a way around it, and as stated earlier, GNU and BSD conflict in certain commands. Best I could do was basically strip the makefile of its soul to remove errors when testing the command but that's not really helpful. Any other way to insert or run the .dylib file didn't lead to anything
Also, if it works, may I ask you to please share your compiled dylib with me?
I don't have access to any mac right now so can't test anything further or give you the dylib file. I tried inserting the dylib file but it didn't work. I really don't have enough experience in macOs to figure out what went wrong.
I genuinely do not have anywhere near the coding understanding required to try and allow 'sudo make install' to work or get a way around it, and as stated earlier, GNU and BSD conflict in certain commands. Best I could do was basically strip the makefile of its soul to remove errors when testing the command but that's not really helpful. Any other way to insert or run the .dylib file didn't lead to anything
I am clueless here too. in this case make install just copies the file to some directories so I manually copied the files. didn't work. tried injecting dylib still didn't work. maybe for security reasons ? I tried to "code sign" by following this blog ( I actually don't know wtf I tried to do ) maybe someone else can figure it out.
As I already said, this won't work anyway without some code changes. We essentially need a macro like this. I've been trying to write this second macro and abstract away the differences between how the overriding works on Linux and macOS, so we don't need to duplicate any of the other code, but haven't succeeded yet.
Spotify for macOS loads symbols from Chromium Embedded Framework with a call to dlopen first and then subsequent calls to dlsym using that same handle. This means it is impossible to redirect url_request_create using DYLD_INSERT_LIBRARIES. I guess one option would be to create a "fake" Chromium Embedded Framework that exposes all the symbols and loads the real one under the hood.
Also, to even enable the use of DYLD_INSERT_LIBRARIES Spotify must be re-signed with the entitlement com.apple.security.cs.allow-dyld-environment-variables. The loader ignores the variable otherwise.
Update: This is the final thing. I have only tested this on Apple Silicon though.
I've been following this for a while as an alternative to my own project. I just wanted to link it here for anyone who is looking for something that is confirmed to work on MacOS x86.