Genymobile / scrcpy

Display and control your Android device
Apache License 2.0
112.05k stars 10.72k forks source link

OK, I gave up on scrcpy. Not computer illiterate but was expected easier install on Mac. #2256

Open itoldusoandso opened 3 years ago

itoldusoandso commented 3 years ago

MacOS 10.13 Have done as instructed.. CLT, Homebrew and scrcpy. The install process was sluggish, took 16 hours and decided to post on XDA to check sanity of what I am doing.

Sorry guys, this just didn't work out for me. Total fail ;(

Now two more hours later, the install process stayed hanging and still showing "make"... So now after 18 hours I am pulling the plug want to quit. I want to delete scrcpy and put my machine back where it was before start. However, it gives me error when I type in the command:

bash-3.2$ brew uninstall scrcpy Error: No available formula or cask with the name "scrcpy". bash-3.2$

So what do I do now.

See link to XDA post with picture. I don't see how to attach picture here.

https://forum.xda-developers.com/t/installing-scrcpy-now-already-more-than-16-hours-comman-line-tools-homebrew-is-this-normal.4262295/

PembaTamang commented 3 years ago

were you able to fix it ?

itoldusoandso commented 3 years ago

Unfortunately not and I am still waiting on instructions on how to get rid of the software. I don't know what to do at this point.

rom1v commented 3 years ago

MacOS 10.13

Probably related: #2059

In particular: https://github.com/Genymobile/scrcpy/issues/2059#issuecomment-767032047

macs that can't update their OS beyond 10.13 need to be warned that homebrew doesn't know or care if they try to update scrcpy it will install incompatible ffmpeg dependencies.

rom1v commented 3 years ago

As an alternative to Homebrew, you could try MacPorts on macOS (I don't know, I have no macOS).

itoldusoandso commented 3 years ago

Well, I looked at MacPorts but it seems to me it's the page doesn't seem to be safe for toddlers. I need the instructions to be for a 5-years old. It's Babylon language for me as far as this is concerned.

People mention the issue starting after 1.6_2? What are your thoughts if I try same steps but I try install 1.6_2 version. Can I do that somehow?

But first I guess I need to clean the mess on my machine. I have CLT, Homebrew and scrcpy installed. So I guess I need to start removing scrcpy but I don't know how, what and where. I don't want to start deleting the stuff in home directory as I said I it's not like regular apps so stuff seems to be spread around like birds feed.

harens commented 3 years ago

Hi there 👋, I'm a project member over at MacPorts. We have a port for scrcpy maintained by @MarcelBochtler that sorts out the adb tools for you.

sudo port install scrcpy

Well, I looked at MacPorts but it seems to me it's the page doesn't seem to be safe for toddlers. I need the instructions to be for a 5-years old. It's Babylon language for me as far as this is concerned.

The views expressed here are solely my own. I agree that things can certainly be improved, and we've been doing a lot of work recently to do so (see. the desolate condition thread on our mailing lists). Any suggestions you might have are warmly welcomed.

Just to help you get started, you can download MacPorts from here. Restart the terminal and then run the command I mentioned above to install scrcpy.

macs that can't update their OS beyond 10.13 need to be warned that homebrew doesn't know or care if they try to update scrcpy it will install incompatible ffmpeg dependencies.

We provide ffmpeg binaries all the way from 11 arm 64 to 10.5 ppc, and we take support of older hardware very seriously. We've had some issues building scrcpy pre-10.11 which we'll need to deal with, but we currrently provide pre-built binaries that work out the box for 10.12 upwards which should be fine for you @itoldusoandso.

If you have any questions, feel free to ask. Thanks @rom1v for maintaining this amazing project.

itoldusoandso commented 3 years ago

If you have any questions, feel free to ask. Thanks @rom1v for maintaining this amazing project.

harens, thank you. OK I get it so toddler needs to learn to walk by trying to walk.

So I found here is info on uninstall brew and scrcpy package.

https://github.com/homebrew/install#uninstall-homebrew

https://osxdaily.com/2018/07/29/uninstall-packages-homebrew-mac/

Just staying in the crib and crying will not get me anywhere. I decided to mess with this stuff on my machine so I got to go with it.

Once thats done I'll follow the MacPorts instructions.

itoldusoandso commented 2 years ago

Okay back here after a while. Uninstalled and cleaned Brew directories. Installed MacPorts. Do not know why I haven't tried it first it seems to me childsplay compared to installing Brew. Instsalled MacPorts and t's a quite small package compared to Brew downloaded 2 GB of stuff. Am I missing something. Anyhow, I am installing scrcpy but it doesn't work. I am getting message: "Port scrcpy not found"

So off to their forum to find out what is the matter. Followed exactly what it says here:

https://ports.macports.org/port/scrcpy/

bash-3.2$ sudo port install scrcpy Error: Port scrcpy not found

Should I ask there or is it question for scrcpy? Not sure what to think of it.

neverpanic commented 2 years ago

@itoldusoandso Usually, right after running the MacPorts installer, it downloads a copy of the Portfiles that are required so that sudo port install scrcpy works. It seems that didn't work in your case, possibly because you're on a network where rsync does not work.

Try running sudo port -v selfupdate - if that fails, that's probably the reason why sudo port install scrcpy does not work. In that case, I'd advise you to follow https://trac.macports.org/wiki/howto/SyncingWithGit; that should work on networks where rsync does not.

After that, sudo port install scrcpy should work.

itoldusoandso commented 2 years ago

Thank you. I've done the self update and it went on installing the ports.

I noticed following messages in the results:

Total number of ports parsed: 30067 Ports successfully parsed: 30067 Ports failed: 0 Up-to-date ports skipped: 0 ---> MacPorts base is already the latest version. The ports tree has been updated. To upgrade your installed ports, you should run port upgrade outdated

When it was downloading the packages, there were a couple of lines with a message... ---> "Computing dependencies for scrcpy Warning: All compilers are either blacklisted or unavailable; defaulting to first fallback option"

Error: No Xcode installation was found. Error: Please install Xcode and/or run xcode-select to specify its location.

Error: Port gd2 requires a full Xcode installation, which was not found on your system. Error: You can install Xcode from the Mac App Store or https://developer.apple.com/xcode/ Error: See /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_graphics_gd2/gd2/main.log for details.

Error: Follow https://guide.macports.org/#project.tickets if you believe there is a bug. Error: Processing of port scrcpy failed

---> Some of the ports you installed have notes: libomp has the following notes: To use this OpenMP library:

=======

When I try to run scrcpy I get following:

scrcpy: command not found

=========================

From what I see is it tells me I need to install full Xcode? Not enough to install Command Line Tools?
I never use Xcode nor command line tools. I had it once and deleted the folder Command line tools to save 1gb space.

Is Xcode still required after Scrcpy is installed?

neverpanic commented 2 years ago

Xcode will not be required after scrcpy is installed. I am, however, a bit confused by the message you're getting, since gd2 (the port that failed to build) definitely builds without Xcode and only needs the Command Line Tools.

Make sure xcode-select -print-path prints /Library/Developer/CommandLineTools. If it doesn't, try sudo xcode-select -s /Library/Developer/CommandLineTools.

rom1v commented 2 years ago

Isn't there a version of homebrew/macports/other package manager on MacOS which distributes binary packages, so that users don't have to build on install?

neverpanic commented 2 years ago

There is, and MacPorts has precompiled binaries for scrcpy: https://packages.macports.org/scrcpy/

Those may or may not be used depending on the user's setup, e.g., installations in locations other than /opt/local will not use binaries, or systems older than macOS 10.12 (where scrcpy doesn't build according to https://ports.macports.org/port/scrcpy/details/ because it doesn't have clock_gettime).

LeeBinder commented 2 years ago

The MacPorts precompiled scrcpy binaries are pretty much useless for the average user because they do require all the dependencies, too!!

scrcpy simply does require tons of dependencies to run in macOS at this point. scrcpy via MacPorts via (in the Terminal app) sudo port install scrcpy installs the exact same ones as brew!

I can share a comparison tomorrow.

LeeBinder commented 2 years ago

I can't report anything new here, so just for the records:

macOS Catalina with Xcode Command Line Tools (2,53 GB), homebrew as non-shallow clone (1.45 GB), adb Platform Tools (33 MB) + a few dependencies scrcpy also uses already pre-installed, because for me these are standard/ default tools I use all the time, already pre-scrcpy.

Right after running brew install scrcpy, the size of the /usr/local/ folder grew by 724 MB, almost all in /usr/local/Cellar = dependencies (98):

click to expand ```javascript $ brew deps scrcpy aom bdw-gc brotli ca-certificates cairo cjson cmocka dav1d ffmpeg flac fontconfig freetype frei0r fribidi gdbm gettext giflib glib gmp gnutls gobject-introspection graphite2 guile harfbuzz icu4c imath jpeg jpeg-xl lame leptonica libarchive libass libb2 libbluray libevent libffi libidn2 libnghttp2 libogg libpng libpthread-stubs librist libsamplerate libsndfile libsodium libsoxr libtasn1 libtiff libtool libunistring libusb libvidstab libvmaf libvorbis libvpx libx11 libxau libxcb libxdmcp libxext libxrender little-cms2 lz4 lzo m4 mbedtls mpdecimal nettle opencore-amr openexr openjpeg openssl@1.1 opus p11-kit pcre pixman pkg-config python@3.9 rav1e readline rubberband sdl2 snappy speex sqlite srt tesseract theora unbound webp x264 x265 xorgproto xvid xz zeromq zimg zstd $ brew deps scrcpy | wc -l 98 ```

sudo port install scrcpy: "The following dependencies will be installed (105)":

click to expand ```javascript android-platform-tools aom autoconf autoconf-archive automake brotli cairo curl-ca-bundle dav1d db48 ffmpeg fontconfig freetype fribidi gd2 gdbm gdk-pixbuf2 gettext gettext-tools-libs giflib glib2 gmp gnutls gobject-introspection graphite2 graphviz gts harfbuzz icu jbigkit lame lcms2 lerc libLASi libass libbluray libde265 libheif libidn2 libjpeg-turbo libmodplug libnetpbm libogg libopus libpixman libpng librsvg libsdl2 libtasn1 libtextstyle libtheora libtool libunistring libvorbis libvpx libxml2 libxslt lz4 m4 nettle openjpeg ossp-uuid p11-kit pango pcre perl5.28 pkgconfig py310-mako py310-markdown py310-markupsafe py310-setuptools python310 python3_select rav1e readline shared-mime-info soxr speex tiff urw-fonts vala webp x264 x265 xorg-libX11 xorg-libXau xorg-libXaw xorg-libXdmcp xorg-libXext xorg-libXmu xorg-libXt xorg-libice xorg-libpthread-stubs xorg-libsm xorg-libxcb xorg-xcb-proto xorg-xcb-util xorg-xorgproto xpm xrender zimg zstd zvbi Xft2 XviD ```

so I didn't even bother (MacPorts also lists the modules which I have already installed in brew which it doesn't see, therefore the diff in # of dependencies).

Sizes and numbers for 11.x Big Sur and 12.x Monterey will differ somewhat.

Again, this is not Romain's @rom1v fault because he currently doesn't have macOS at his fingertips, like he stated before. Therefore any package manager will simply follow its guidelines for installing.

No matter what, it's only a question of time that a nicely small stand-alone package for macOS can be created, one way or the other 👍 💯 Because looking at the Windows version, it's only a tiny number of required runtime libraries:

Bildschirmfoto 2022-05-12 um 22 26 08

neverpanic commented 2 years ago

port rdeps --index scrcpy will give you an idea where all those dependencies are coming from.

You'll see that a lot of them are required by librsvg, which is a dependency of ffmpeg. Assuming scrcpy does not need SVG support in ffmpeg, one could build a copy of ffmpeg that does not use librsvg using the --disable-librsvg configure flag.

However, it isn't MacPorts (or Homebrew's) goal to provide a specific version of ffmpeg that works for scrcpy – both are general purpose package managers that will provide a reasonable configuration of ffmpeg when its installation is requested, and that includes librsvg and its dependencies.

The MacPorts precompiled scrcpy binaries are pretty much useless for the average user because they do require all the dependencies, too!!

Yes. These precompiled binaries are not meant to be used outside of MacPorts, which will ensure that the required dependencies are also available. They simply save compilation time. I'm not intimately familiar with Homebrew's "bottles" concept, but I think they have the same approach.

What those binaries give you is avoiding local compilation, though. For example, there's no need to install & compile rust, because MacPorts has a precompiled copy of librsvg available: https://ports.macports.org/port/librsvg/details/.

No matter what, it's only a question of time that a nicely small stand-alone package for macOS can be created, one way or the other

You can do this using dylibbundler from the MacPorts scrcpy package:

$> mkdir /tmp/scrcpy
$> cp /opt/local/bin/scrcpy /tmp/scrcpy
$> cd /tmp/scrcpy
$> dylibbundler -b --create-dir --dest-dir libs --install-path '@executable_path/libs' -x scrcpy
$> cp /opt/local/bin/adb .
$> cp /opt/local/share/scrcpy/scrcpy-server .
$> ADB=/tmp/scrcpy/adb SCRCPY_SERVER_PATH=/tmp/scrcpy/scrcpy-server ./scrcpy

You'd probably also have to ship a copy of adb, processed using the same method (although it seems that adb does not actually link against any external libraries that aren't usually present on macOS).

Such a package will also be quite large, though:

$> du -sh /tmp/scrcpy
103M    /tmp/scrcpy/

Additionally, you'd have to comply with the licenses of all bundled binaries when re-distributing, which is also why I will not provide the one I just built anywhere.

LeeBinder commented 2 years ago

very nice, great info - thanks for sharing it all.

So your self-compiled 103 MB package of scrcpy contains all required dependencies and is working fine for you even after removing scrcpy with all its dependencies via both, MacPorts and homebrew = is true stand-alone?

neverpanic commented 2 years ago

So your self-compiled 103 MB package of scrcpy contains all required dependencies and is working fine for you even after removing scrcpy with all its dependencies via both, MacPorts and homebrew = is true stand-alone?

I don't have a phone available at the machine I'm currently at, so I didn't actually test the functionality. It does start successfully (and then fails to find a phone), though. I had the MacPorts scrcpy port deactivated when I tested this, but all other dependencies still installed. I did check the scrcpy binary with otool -L and it used the copy of the dependencies from the libs/ directory, not the MacPorts-installed ones. That should make it stand-alone.

LeeBinder commented 2 years ago

great, thank you, neverpanic! Installing scrcpy via MacPorts right now, then will execute your script. Will leave the house now so it'll be a while before I report back if all went well.

LeeBinder commented 2 years ago

one more install command was necessary here for me so dylibbundler -b ... would run:

sudo port install libusb

full report follows later

LeeBinder commented 2 years ago

It's running 100% fine form what I can tell so far 👍 🥇

Now we can clean-up:

sudo port uninstall --follow-dependencies scrcpy
sudo port uninstall inactive

.. and here's the icon for the app (3kb 8-bit PNG 256x256) :): Icon

LeeBinder commented 2 years ago

scrcpy v1.24 (Catalina).dmg w/o adb compressed with max. compression only weighs 39,1 MB (44,2 MB with adb), so we're pretty much on-par with the 64bit Windows archive now 👍

Additionally, you'd have to comply with the licenses of all bundled binaries when re-distributing, which is also why I will not provide the one I just built anywhere.

@neverpanic @rom1v same would apply to the Windows package which is being supplied here. So basically all that's left for official stand-alone releases for macOS Catalina, Big Sur and Monterey is to add the complying license(s) agreement(s)? (haven't checked the Windows zip how you devs have handled it there)

LeeBinder commented 2 years ago

The launcher script to be placed on the same level as scrcpy, scrcpy-server and adb:

#!/bin/bash
clear
cd "$(dirname "$0")"
ADB=./adb SCRCPY_SERVER_PATH=./scrcpy-server SCRCPY_ICON_PATH=./scrcpy.png ./scrcpy
echo

attached already executable and with icon: run scrcpy.zip

Needless to say one can opt to use pre-installed system-wide adb.

LeeBinder commented 2 years ago

One tiny cosmetic error:

2022-05-13 19:50:33.762 scrcpy[68514:288281] ERROR: Could not open image codec: /opt/local/share/icons/hicolor/256x256/apps/scrcpy.png
2022-05-13 19:50:33.762 scrcpy[68514:288281] WARN: Could not load icon

Could that path also be set in the launcher script? I copied scrcpy.png on the same level as scrcpy, but neither ICON=./scrcpy.png nor IMAGE_CODEC=./scrcpy.png worked - the path error remains the same and scrcpy launches w/o an icon. Final touch-ups :)

[EDIT]: figured it out: SCRCPY_ICON_PATH=./scrcpy.png .. ;)

LeeBinder commented 2 years ago

scrcpy runs fine via the launcher script even from within the mounted .dmg - very cool!

So from my side I'm done, and happy 💯

Genxster1998 commented 2 years ago

@LeeBinder I think @rom1v can still provide better result compiling scrcpy against static avcodec avutil sdl et al. similar to windows than bundling full fat ffmpeg I guess , it's been doing here which pulls tons of dependencies. He might have not testing machine or interest in this platform 😔

LeeBinder commented 2 years ago

I don't see a "full fat ffmpeg" in there:

screenshot

Current ffmpeg binary for mac weighs 77,9 MB.

Genxster1998 commented 2 years ago

@LeeBinder :+1:

Thanks for detailed dependencies list most of them are indeed not related but not heavy . This is feasible indeed a lot. I think python pip package manager can be other way .

LeeBinder commented 2 years ago

@Genxster1998 You're welcome. You're apparently very knowledgeable. Scrcpy's source code is open. When you download and compile it against static avcodec avutil sdl et al., how large is the resulting folder of/with the stand-alone package?

LeeBinder commented 2 years ago

Additionally, you'd have to comply with the licenses of all bundled binaries when re-distributing, which is also why I will not provide the one I just built anywhere.

@neverpanic I just peeked inside the Windows package - no license agreement(s) in there (screenshot):

Bildschirmfoto 2022-05-15 um 22 40 26

I doubt that what would be a requirement for the Mac package is none for the Windows one. In other words, the license compliance has been missing from the Windows package. It would be the same for Mac and Windows, wouldn't it. So once you have compiled that file, it can be added to both packages, making them legal to distribute.

@rom1v if it's of negligible significance to you, the Mac versions could be published.

dur-randir commented 2 years ago

1) If on Apple Silicon, ensure that you shell is under arm mode - type arch, and if the output is i386, execute arch -arm64e `which zsh` 2) Install build deps (can be safely removed after) - sudo port install meson ninja py310-setuptools python310 sqlite3 3) Install runtime deps - sudo port install libsdl2 libusb 4) Check out ffmpeg git clone https://github.com/FFmpeg/FFmpeg && cd FFmpeg && git checkout n4.4.2 (or any other release version you prefer) 5) Build static libraries for ffmpeg into a temporary location (can be safely removed after) - ./configure --prefix=/tmp/ffmpeg --enable-static --disable-runtime-cpudetect --disable-doc --disable-swresample --disable-swscale --disable-postproc --disable-avfilter --disable-avresample --disable-fast-unaligned --disable-debug --enable-audiotoolbox --disable-sdl2 --enable-videotoolbox --enable-opencl --enable-gpl --disable-shared --disable-iconv && make -j10 install 6) Check out scrcpy - git clone https://github.com/Genymobile/scrcpy && cd scrcpy 7) Patch sources for macport's pkgconfig paths - sed -i '' 's!libusb-1.0/libusb.h!libusb.h!g' ./**/*.h && sed -i '' 's!<SDL2/!<!g' ./**/*.h && sed -i '' 's!<SDL2/!<!g' ./**/*.c 8) Build scrcpy PKG_CONFIG_PATH=/tmp/ffmpeg/lib/pkgconfig:/opt/local/lib/pkgconfig meson build-auto --buildtype=release --strip -Db_lto=true -Dprebuilt_server=scrcpy-server --prefix=/opt/local && cd build-auto && ninja 9) Resulting app/scrcpy binary is just 14M, not depending on any large runtime libraries.

LeeBinder commented 2 years ago

@dur-randir awesome instructions, thank you! Two questions:

  1. do your instructions (starting at line two) also work on an Intel Mac, as long as I've updated my account to use zsh rather than bash by first having run chsh -s /bin/zsh?
  2. is the resulting scrcpy an app package with dependent libraries inside, or just one binary executable file with all dependencies compiled right into the single/ stand-alone binary?
dur-randir commented 2 years ago

do your instructions (starting at line two) also work on an Intel Mac, as long as I've updated my account to use zsh rather than bash by first having run chsh -s /bin/zsh?

They should, but you might want to also install nasm as a build dep and remove --disable-fast-unaligned option from the configure call. Also, chsh is not needed, you can just switch to zsh with a simple zsh. It's only used for shell expansions in a sed call and it could be rewritten for bash compatibility.

is the resulting scrcpy an app package with dependent libraries inside, or just one binary executable file with all dependencies compiled right into the single/ stand-alone binary?

It's not a package, it's a single binary. It depends only on system libraries + the following two:

    /opt/local/lib/libSDL2-2.0.0.dylib (compatibility version 23.0.0, current version 23.0.0)
    /opt/local/lib/libusb-1.0.0.dylib (compatibility version 4.0.0, current version 4.0.0)

which are listed in (3). I've tried to patch meson build files to include them statically (as .a library files are present, so it should be possible), but gave up due to some linking errors. I found the result "good enough" to share it, but if you can bundle them into .app together or modify build files to statically link them - great!

LeeBinder commented 2 years ago

Superb info, @dur-randir - respect! I'll provide some time on the week-end to run a compile with your neat commands 👍

(I also learn to appreciate MacPorts more and more)

Coool commented 2 years ago

macs that can't update their OS beyond 10.13 need to be warned that homebrew doesn't know or care if they try to update scrcpy it will install incompatible ffmpeg dependencies.

We provide ffmpeg binaries all the way from 11 arm 64 to 10.5 ppc, and we take support of older hardware very seriously. We've had some issues building scrcpy pre-10.11 which we'll need to deal with, but we currrently provide pre-built binaries that work out the box for 10.12 upwards which should be fine for you @itoldusoandso.

If you have any questions, feel free to ask. Thanks @rom1v for maintaining this amazing project.

^ref.

As said at #1733. To use scrcpy on macOS you don't need to install all unnecessary packages and tools. 👍 that trying to support old OS. Homebrew is a crappy package manager for lazy people.

LeeBinder commented 1 year ago

@dur-randir @neverpanic have you already tried if your instructions still work for the new v.1.25 release? Or would modifications be necessary? I'm out of time right now but am curious.

dur-randir commented 1 year ago

No modifications needed, just tested.

LeeBinder commented 1 year ago

@dur-randir great, will try (on an Intel Mac, right now still on macOS Catalina 10.15.7, latest MacPorts 2.8.0, Xcode Command Line Tools 12.4 [not the full Xcode suite]).

Which version ffmpeg did you checkout with - n4.4.2 as in your instructions? Latest appears to be n5.1.2

[EDIT]: errors compiling in step 7., 'Build scrcpy':

Did not find CMake 'cmake'
Found CMake: NO
Run-time dependency libavformat found: NO (tried pkgconfig and framework)

app/meson.build:96:4: ERROR: Dependency "libavformat" not found, tried pkgconfig and framework

meson-log.txt:

click to expand ```javascript Build started at 2022-12-23T20:19:58.162992 Main binary: /opt/local/Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11 Build Options: -Db_lto=true -Dprebuilt_server=scrcpy-server -Dprefix=/opt/local -Dbuildtype=release -Dstrip=True Python system: Darwin The Meson build system Version: 0.63.3 Source dir: /Users/lee/scrcpy Build dir: /Users/lee/scrcpy/build-auto Build type: native build Project name: scrcpy Project version: 1.25 ----- Detecting compiler via: cc --version compiler returned compiler stdout: Apple clang version 12.0.0 (clang-1200.0.32.29) Target: x86_64-apple-darwin19.6.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin compiler stderr: Running command: cc -E -dM - ----- Detecting linker via: cc -Wl,--version linker returned linker stdout: linker stderr: ld: unknown option: --version clang: error: linker command failed with exit code 1 (use -v to see invocation) ----- Detecting Apple linker via: cc -Wl,-v linker stdout: linker stderr: @(#)PROGRAM:ld PROJECT:ld64-609.8 BUILD 15:07:46 Dec 18 2020 configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em Library search paths: /usr/local/lib /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/lib Framework search paths: /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/ Undefined symbols for architecture x86_64: "_main", referenced from: implicit entry/start for main executable ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) Sanity testing C compiler: cc Is cross compiler: False. Sanity check compiler command line: cc sanitycheckc.c -o sanitycheckc.exe Sanity check compile stdout: ----- Sanity check compile stderr: ----- Running test binary command: /Users/lee/scrcpy/build-auto/meson-private/sanitycheckc.exe C compiler for the host machine: cc (clang 12.0.0 "Apple clang version 12.0.0 (clang-1200.0.32.29)") C linker for the host machine: cc ld64 609.8 ----- Detecting compiler via: cc --version compiler returned compiler stdout: Apple clang version 12.0.0 (clang-1200.0.32.29) Target: x86_64-apple-darwin19.6.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin compiler stderr: Running command: cc -E -dM - ----- Detecting linker via: cc -Wl,--version linker returned linker stdout: linker stderr: ld: unknown option: --version clang: error: linker command failed with exit code 1 (use -v to see invocation) ----- Detecting Apple linker via: cc -Wl,-v linker stdout: linker stderr: @(#)PROGRAM:ld PROJECT:ld64-609.8 BUILD 15:07:46 Dec 18 2020 configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em Library search paths: /usr/local/lib /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/lib Framework search paths: /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/ Undefined symbols for architecture x86_64: "_main", referenced from: implicit entry/start for main executable ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) Sanity testing C compiler: cc Is cross compiler: False. Sanity check compiler command line: cc sanitycheckc.c -o sanitycheckc.exe Sanity check compile stdout: ----- Sanity check compile stderr: ----- Running test binary command: /Users/lee/scrcpy/build-auto/meson-private/sanitycheckc.exe C compiler for the build machine: cc (clang 12.0.0 "Apple clang version 12.0.0 (clang-1200.0.32.29)") C linker for the build machine: cc ld64 609.8 Build machine cpu family: x86_64 Build machine cpu: x86_64 Host machine cpu family: x86_64 Host machine cpu: x86_64 Target machine cpu family: x86_64 Target machine cpu: x86_64 Pkg-config binary for 1 is not cached. Pkg-config binary missing from cross or native file, or env var undefined. Trying a default Pkg-config fallback at pkg-config Found pkg-config: /usr/local/bin/pkg-config (0.29.2) Determining dependency 'libavformat' with pkg-config executable '/usr/local/bin/pkg-config' env[PKG_CONFIG_PATH]: /tmp/ffmpeg/lib/pkgconfig:/opt/local/lib/pkgconfig Called `/usr/local/bin/pkg-config --modversion libavformat` -> 1 Finding framework path by running: cc -v -E - Looking for framework libavformat in /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks CMake binary for 1 is not cached CMake binary missing from cross or native file, or env var undefined. Trying a default CMake fallback at cmake Did not find CMake 'cmake' Found CMake: NO CMake binary for machine 1 not found. Giving up. Run-time dependency libavformat found: NO (tried pkgconfig and framework) app/meson.build:96:4: ERROR: Dependency "libavformat" not found, tried pkgconfig and framework ```
dur-randir commented 1 year ago

I have cmake installed, probably from some other packages. As for libavformat, check that you correctly have it in /tmp/ffmpeg/lib/libavformat.a and that you didn't forgot to set PKG_CONFIG_PATH.

LeeBinder commented 1 year ago

@dur-randir using your script adapted for Intel as per your instructions.

I'm beyond the cmake error by installing it from https://cmake.org/download, then sudo "/Applications/CMake.app/Contents/bin/cmake-gui" --install ->

Found pkg-config: /usr/local/bin/pkg-config (0.29.2)
Found CMake: /usr/local/bin/cmake (3.25.1)

libavformat: I checked out with the latest FFmpeg n5.1.2

git clone https://github.com/FFmpeg/FFmpeg && cd FFmpeg && git checkout n5.1.2

which didn't even create a folder /tmp/ffmpeg/ and therefore neither /tmp/ffmpeg/lib/libavformat.a, but only a folder in my user folder FFmpeg/libavformat, inside a file libavformat.v. Resulting error:

Run-time dependency libavformat found: NO (tried pkgconfig, framework and cmake)
app/meson.build:96:4: ERROR: Dependency "libavformat" not found, tried pkgconfig, framework and cmake

Next I used n4.4.2 as checkout switch to see if it's required to build /tmp/ffmpeg/ and consecutively lib/libavformat.a to be created, but that gave me a new error in step 4. (build static libraries for ffmpeg into a temporary location):

nasm/yasm not found or too old. Use --disable-x86asm for a crippled build.

+ the libavformat.a error next. (same with the latest from the 4.4.x line = 4.4.3)

So if this is a PKG_CONFIG_PATH error: how do I set it correctly? Right now I use the unmodifief line from your script

PKG_CONFIG_PATH=/tmp/ffmpeg/lib/pkgconfig:/opt/local/lib/pkgconfig meson build-auto --buildtype=release --strip -Db_lto=true -Dprebuilt_server=scrcpy-server --prefix=/opt/local && cd build-auto && ninja

FYI, I only have Xcode Command Line Tools 12.4 (latest for Catalina) installed. Is the full Xcode suite required for the source code in ~/FFmpeg/.. to compile to /tmp/ffmpeg/..? Or did you possibly previously also run

sudo port install ffmpeg

but accidentally missed to include that as a requirement in your script?

Anyway, it would be awesome and so much appreciated if you could create a stand-alone folder with the scrcpy + scrcpy-server binaries + the dependent libs bundled via dylibbundler from the MacPorts scrcpy package as per neverpanic's instructions, package (zip/ tar.xz/ dmg as per your liking) the small folder up and upload it here 🥇

Thanks Sergey for your kind help 👍

dur-randir commented 1 year ago

nasm/yasm not found or too old. Use --disable-x86asm for a crippled build.

This happens if you didn't switch to arm64 arch at step 1. If you're building for x86, install nasm.

I've build n5.1.2 tag for the test, and the only change had to be made was removing --disable-avresample from the configure line:

$ /tmp/ffmpeg/bin/ffprobe --version
ffprobe version n5.1.2 Copyright (c) 2007-2022 the FFmpeg developers
  built with Apple clang version 14.0.0 (clang-1400.0.29.102)
  configuration: --prefix=/tmp/ffmpeg --enable-static --disable-runtime-cpudetect --disable-doc --disable-swresample --disable-swscale --disable-postproc --disable-avfilter --disable-fast-unaligned --disable-debug --enable-audiotoolbox --disable-sdl2 --enable-videotoolbox --enable-opencl --enable-gpl --disable-shared --disable-iconv
  libavutil      57. 28.100 / 57. 28.100
  libavcodec     59. 37.100 / 59. 37.100
  libavformat    59. 27.100 / 59. 27.100
  libavdevice    59.  7.100 / 59.  7.100
Missing argument for option '-version'

Re-check that the ffmpeg build is successful, i'd suggest adding set -e at the beginning of your script.

dur-randir commented 1 year ago

scrcpy + scrcpy-server binaries + the dependent libs bundled via [dylibbundler (https://ports.macports.org/port/dylibbundler/)

https://drive.google.com/file/d/13u79SF2tBphFC9EiUDt8S0BgnMDBRxQl/view?usp=sharing This is arm64 build for Monterey. If you're on x86, I can build it too, but I'm not sure about framework compatibility if you're on Catalina - do you have /usr/lib/libSystem.B.dylib present? If not, even if i build it for x86, it won't run - as dylibbundler doesn't bundle it.

LeeBinder commented 1 year ago

great, those with Apple Silicon CPUs will be happy 👍

I should be able to test your additional instructions from your previous post later on.

Yes, /usr/lib/libSystem.B.dylib is present even on Catalina (I also have all higher macOS up to Ventura installed in the same APFS container so can test there, too). So until I manage to compile successfully here, I'd be very appreciative if you could create and share a Intel 64bit bundle, too 🥇

LeeBinder commented 1 year ago

yes, much closer now: in Terminal, compiling ffmpeg goes on for quite a while, and /tmp/ffmpeg is getting created. On next and final step (7. Build scrcpy), however, the (hopefully final) error to be resolved is:

server/meson.build:19:4: ERROR: File ../scrcpy-server does not exist.

and before (just a red NO but no error):

Header "sys/socket.h" has symbol "SOCK_CLOEXEC" : NO 
Configuring config.h using configuration

Where exactly do you place the scrcpy-server v1.25 binary? Before compiling, I placed it into ~(root of my user folder), but obviously that's not the right spot.

dur-randir commented 1 year ago

Header "sys/socket.h" has symbol "SOCK_CLOEXEC" : NO

You can safely ignore it.

server/meson.build:19:4: ERROR: File ../scrcpy-server does not exist.

Place it to the scrcpy checkout directory.

LeeBinder commented 1 year ago

you mean, during compile? Because before that directory doesn't exist, does it. Or can I simply adapt

-Dprebuilt_server=scrcpy-server

to

-Dprebuilt_server=~/scrcpy-server

?

dur-randir commented 1 year ago

No, no, it's not a directory. It's a scrcpy-server file from release section (it's named scrcpy-server-1.25, just rename it after download).

LeeBinder commented 1 year ago

yes, at https://github.com/Genymobile/scrcpy/releases/download/v1.25/scrcpy-server-v1.25

So it would need to first get curl'ed to local hard drive, renamed, then moved into the correct directory so it can be found by the command -Dprebuilt_server=scrcpy-server. If it's not in the right spot, there will be that "not found" error.

curl -L http://github.com/Genymobile/scrcpy/releases/download/v1.25/scrcpy-server-v1.25 -o correct/path/to/scrcpy-server

I've not been able to figure out the appropriate string or path variable to replace correct/path/to/ with

LeeBinder commented 1 year ago

[EDIT]: me stupid - SOLVED! simply

curl -L http://github.com/Genymobile/scrcpy/releases/download/v1.25/scrcpy-server-v1.25 -o scrcpy-server

right before

PKG_CONFIG_PATH=/tmp/ffmpeg/lib/pkgconfig:/opt/local/lib/pkgconfig meson build-auto --buildtype=release --strip -Db_lto=true -Dprebuilt_server=scrcpy-server --prefix=/opt/local && cd build-auto && ninja

places scrcpy-server right where it needs to be for the script to build all the way thru now into ~/FFmpeg/scrcpy/build-auto:

Bildschirmfoto 2022-12-25 um 00 34 40

Resulting scrcpy binary for Intel is just roughly 19 MB, and running fine as supposed 👍

Below script should automate everything (apart from first installing the known prerequisites):

build scrcpy (Intel) v1.25.command (v.2022-12-29) - click to expand ```zsh #!/bin/zsh clear osascript -e 'tell application "Terminal" set current settings of tabs of windows to settings set "Homebrew" # Theme name #set current settings of tabs of windows to (first settings set whose name is "Homebrew") # Theme name #set current settings of selected tab of window 1 to settings set "Homebrew" # Theme name end tell' #===============================================================================## ## USER ABORTS SCRIPT # ##==============================================================================## function _clean_up() { printf "User aborted!" clear } #===============================================================================## ## START # ##==============================================================================## function main() { echo "0. Starting fresh: removing any remnants in case a previous compilation attempt left some cache" rm -rf ~/FFmpeg && rm -rf /tmp/ffmpeg echo echo "1. Install build deps (can be safely removed afterwards) " #sudo port -N install meson ninja py310-setuptools python310 sqlite3 cmake pkgconfig nasm sudo port -N install meson ninja py311-setuptools python311 sqlite3 cmake pkgconfig nasm echo echo "2. Install runtime dependencies" sudo port install libsdl2 libusb echo echo "3. Download and checkout ffmpeg" git clone https://github.com/FFmpeg/FFmpeg && cd FFmpeg && git checkout n5.1.2 #git clone https://github.com/FFmpeg/FFmpeg && cd FFmpeg && git checkout n4.4.3 #git clone https://github.com/FFmpeg/FFmpeg && cd FFmpeg && git checkout n4.4.2 # (or another release version you prefer) echo set -e echo "4. Build static libraries for ffmpeg into a temporary location (will be removed afterwards)" ./configure --prefix=/tmp/ffmpeg --enable-static --disable-runtime-cpudetect --disable-doc --disable-swresample --disable-swscale --disable-postproc --disable-avfilter --disable-debug --enable-audiotoolbox --disable-sdl2 --enable-videotoolbox --enable-opencl --enable-gpl --disable-shared --disable-iconv && make -j10 install echo echo "5. Download scrcpy source code" git clone https://github.com/Genymobile/scrcpy && cd scrcpy echo echo "6. Patch sources for macport's pkgconfig paths" sed -i '' 's!libusb-1.0/libusb.h!libusb.h!g' ./**/*.h && sed -i '' 's!/dev/null && sudo cp scrcpy-server /opt/local/share/scrcpy/scrcpy-server echo echo "7. Build scrcpy" PKG_CONFIG_PATH=/tmp/ffmpeg/lib/pkgconfig:/opt/local/lib/pkgconfig meson build-auto --buildtype=release --strip -Db_lto=true -Dprebuilt_server=scrcpy-server --prefix=/opt/local && cd build-auto && ninja echo echo "8. Copy scrcpy binary into its folder specified by MacPorts" #ls && echo # we're in ~/FFmpeg/scrcpy/build-auto now! sudo cp app/scrcpy /opt/local/bin/ echo echo "9. Attach icon and creating SymLinks" echo curl -L https://raw.githubusercontent.com/Genymobile/scrcpy/master/app/data/icon.png -o icon.png echo # Covert Icon.png to tmpicons.icns: sips -s format icns Icon.png --out tmpicns.icns > /dev/null 2>&1 # Create temporary resource file which points to tmpicns.icns: echo "read 'icns' (-16455) \"tmpicns.icns\";" >> tmpicns.rsrc # append this resource to the file you want to icon-ize. sudo Rez -a tmpicns.rsrc -o /opt/local/bin/scrcpy # Use the resource to set the icon. sudo SetFile -a C /opt/local/bin/scrcpy # providing the icon for the binary app sudo curl -L https://raw.githubusercontent.com/Genymobile/scrcpy/master/app/data/icon.png --create-dirs -o /opt/local/share/icons/hicolor/256x256/apps/scrcpy.png sudo chmod -R 755 /opt/local/share/icons ln -sf /opt/local/bin/scrcpy /Applications/scrcpy echo "10. Clean up temporary files and folders" rm -rf ~/FFmpeg && rm -rf /tmp/ffmpeg echo osascript -e "set alertResult to display alert \"NOTICE: 1. To also remove packages used for compiling, run the separate script file 'Unstall ALL build deps'. 2. You can now either launch scrcpy.. a) from Terminal by typing scrcpy, then press ENTER b) via the scrcpy icon in your Applications folder Do you have your phone connected and want to run scrcpy now?\" buttons {\"No\", \"YES\"} as warning default button \"YES\" cancel button \"No\" try do shell script \"open /opt/local/bin/scrcpy\" end try" echo } trap '{ _clean_up; exit 1; }' INT if [[ `id -u` -ne 0 ]]; then echo "This script should compile and build scrcpy for your version of macOS. The resulting binary "weighs" only roughly 19 MB and is not depending on any large runtime libraries." echo echo "The process can take a few winks so while it runs, enjoy your daily outside exercise along the way.. ;)" echo echo "This script must be run as root. When you're ready, enter" sudo --prompt "your password then press ENTER (Ctrl. C to quit): " "$0" else main fi #===============================================================================## ## EOF # ##==============================================================================## ```
dur-randir commented 1 year ago

Congrats!