Skip to content
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

macos: enable static binaries #5517

Closed
wants to merge 3 commits into from

Conversation

muvaf
Copy link
Contributor

@muvaf muvaf commented Nov 23, 2024

Here is the build log, ran on macOS arm64 15.1.1 (24B91).

release/build_macos.sh 2&>1 > build_log.txt

build_log.txt

I saw some warnings about objc which might be useful:

WARNING: Static library 'objc' not found for dependency 'sdl2', may not be statically linked

When I run it against a locally running emulator, I had to copy scrcpy-server into the folder the binary exists.

curl -Lo release/work/build-macos/dist/scrcpy-server https://github.com/Genymobile/scrcpy/releases/download/v2.7/scrcpy-server-v2.7
$ ./scrcpy_bin
scrcpy 2.7 <https://github.com/Genymobile/scrcpy>
INFO: ADB device found:
INFO:     --> (tcpip)  emulator-5554                   device  sdk_gphone64_arm64
ERROR: Could not get local file path, using scrcpy-server from current directory
scrcpy-server: 1 file pushed, 0 skipped. 46.9 MB/s (71200 bytes in 0.001s)
[server] INFO: Device: [Google] google sdk_gphone64_arm64 (Android 15)
ERROR: Could not get icon path
WARN: Could not load icon
INFO: Renderer: metal
INFO: Texture: 1080x2400
2024-11-23 18:17:09.632 scrcpy_bin[4677:907645] +[IMKClient subclass]: chose IMKClient_Modern
2024-11-23 18:17:09.632 scrcpy_bin[4677:907645] +[IMKInputSession subclass]: chose IMKInputSession_Modern
WARN: Killing the server...
image

rom1v and others added 3 commits November 22, 2024 22:23
Provide a prebuilt binary for Linux.
Signed-off-by: Muvaffak Onus <me@muvaf.com>
@rom1v
Copy link
Collaborator

rom1v commented Nov 23, 2024

Thank you! 👍

WARNING: Static library 'iconv' not found for dependency 'libavformat', may not be statically linked
WARNING: Static library 'z' not found for dependency 'libavformat', may not be statically linked

Maybe installing libiconv and zlib with brew can fix the problem?

For objc, I don't know what to do.

@muvaf
Copy link
Contributor Author

muvaf commented Nov 23, 2024

@rom1v When I install those, I see the following in the brew logs:

==> Caveats
zlib is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

For compilers to find zlib you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/zlib/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/zlib/include"

For pkg-config to find zlib you may need to set:
  export PKG_CONFIG_PATH="/opt/homebrew/opt/zlib/lib/pkgconfig"
==> Caveats
libiconv is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have libiconv first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/libiconv/bin:$PATH"' >> ~/.zshrc

For compilers to find libiconv you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/libiconv/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/libiconv/include"

So, these are probably expected to be present on all macOS systems, hence not needed to be statically linked. Still, I tried adding the following to before the meson command:

LDFLAGS="$LDFLAGS -L/opt/homebrew/opt/zlib/lib"
CPPFLAGS="$CPPFLAGS -I/opt/homebrew/opt/zlib/include"

LDFLAGS="$LDFLAGS-L/opt/homebrew/opt/libiconv/lib"
CPPFLAGS="$CPPFLAGS -I/opt/homebrew/opt/libiconv/include"

Still got the same warnings.
build_log.txt

Adding the following didn't make any difference either:

PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/opt/homebrew/opt/zlib/lib/pkgconfig"

@rom1v
Copy link
Collaborator

rom1v commented Nov 23, 2024

Still, I tried adding the following to before the meson command:

It should probably be added before the configure call for FFmpeg in app/deps/ffmpeg.sh. There are already specific LDFLAGS and CFLAGS for Windows.

@muvaf
Copy link
Contributor Author

muvaf commented Nov 23, 2024

@rom1v No change. Here is the latest script:

#!/bin/bash
set -ex
cd "$(dirname ${BASH_SOURCE[0]})"
. build_common
cd .. # root project dir

MACOS_BUILD_DIR="$WORK_DIR/build-macos"
LDFLAGS="$LDFLAGS -L/opt/homebrew/opt/zlib/lib"
CPPFLAGS="$CPPFLAGS -I/opt/homebrew/opt/zlib/include"

LDFLAGS="$LDFLAGS-L/opt/homebrew/opt/libiconv/lib"
CPPFLAGS="$CPPFLAGS -I/opt/homebrew/opt/libiconv/include"

app/deps/adb_macos.sh
app/deps/sdl.sh macos native static
app/deps/ffmpeg.sh macos native static
app/deps/libusb.sh macos native static

DEPS_INSTALL_DIR="$PWD/app/deps/work/install/macos-native-static"
ADB_INSTALL_DIR="$PWD/app/deps/work/install/adb-macos"

rm -rf "$MACOS_BUILD_DIR"
meson setup "$MACOS_BUILD_DIR" \
    --pkg-config-path="$DEPS_INSTALL_DIR/lib/pkgconfig" \
    -Dc_args="-I$DEPS_INSTALL_DIR/include" \
    -Dc_link_args="-L$DEPS_INSTALL_DIR/lib" \
    --buildtype=release \
    --strip \
    -Db_lto=true \
    -Dcompile_server=false \
    -Dportable=true \
    -Dstatic=true
ninja -C "$MACOS_BUILD_DIR"

# Group intermediate outputs into a 'dist' directory
mkdir -p "$MACOS_BUILD_DIR/dist"
cp "$MACOS_BUILD_DIR"/app/scrcpy "$MACOS_BUILD_DIR/dist/scrcpy_bin"
cp app/data/icon.png "$MACOS_BUILD_DIR/dist/"
cp app/data/scrcpy_static_wrapper.sh "$MACOS_BUILD_DIR/dist/scrcpy"
cp -r "$ADB_INSTALL_DIR"/. "$MACOS_BUILD_DIR/dist/"

This is the logs:
macos_build.3.txt

@rom1v
Copy link
Collaborator

rom1v commented Nov 23, 2024

This is not app/deps/ffmeg.sh 😉

@muvaf
Copy link
Contributor Author

muvaf commented Nov 23, 2024

OK so I added the following right before the configure call of both ffmpeg and sdl:

    export LDFLAGS="$LDFLAGS -L/opt/homebrew/opt/zlib/lib"
    export CPPFLAGS="$CPPFLAGS -I/opt/homebrew/opt/zlib/include"

    export LDFLAGS="$LDFLAGS-L/opt/homebrew/opt/libiconv/lib"
    export CPPFLAGS="$CPPFLAGS -I/opt/homebrew/opt/libiconv/include"

In the logs, I see that the ones warning about iconv are gone, so we're down to 4 from 6.
macos_build.4.txt

@rom1v FWIW, I think you may be able to get faster feedback if you manually trigger the workflow in GH actions after making changes. You may not be able to test it but seeing logs should help with these warnings.

@rom1v
Copy link
Collaborator

rom1v commented Nov 23, 2024

In the logs, I see that the ones warning about iconv are gone, so we're down to 4 from 6.

With this line in addition:

export PKG_CONFIG_PATH="/opt/homebrew/opt/zlib/lib/pkgconfig"

the logs about zlib are also gone 👍

FWIW, I think you may be able to get faster feedback if you manually trigger the workflow in GH actions after making changes. You may not be able to test it but seeing logs should help with these warnings.

Yes, I'm doing that a lot 👍

@muvaf
Copy link
Contributor Author

muvaf commented Nov 23, 2024

Incorporated into #5515

@muvaf muvaf closed this Nov 23, 2024
rom1v added a commit to rom1v/scrcpy that referenced this pull request Dec 9, 2024
Due to a typo (a space was missing before the second '-L'), the
resulting LDFLAGS value was broken:

    "-L/opt/homebrew/opt/zlib/lib-L/opt/homebrew/opt/libiconv/lib"

This proves that the flag was useless. Remove it.

Refs Genymobile#5517 comment <Genymobile#5517 (comment)>
rom1v added a commit to rom1v/scrcpy that referenced this pull request Dec 9, 2024
Due to a typo (a space was missing before the second '-L'), the
resulting LDFLAGS value was broken:

    "-L/opt/homebrew/opt/zlib/lib-L/opt/homebrew/opt/libiconv/lib"

This proves that the flag was useless. Remove it.

Refs Genymobile#5517 comment <Genymobile#5517 (comment)>
rom1v added a commit that referenced this pull request Dec 9, 2024
Due to a typo (a space was missing before the second '-L'), the
resulting LDFLAGS value was broken:

    "-L/opt/homebrew/opt/zlib/lib-L/opt/homebrew/opt/libiconv/lib"

This proves that the flag was useless. Remove it.

Refs #5517 comment <#5517 (comment)>
PR #5644 <#5644>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants