holochain / tx5

Holochain WebRTC P2P Communication Ecosystem
Apache License 2.0
67 stars 6 forks source link

`error running go build` when targeting `aarch64-apple-ios-sim` #53

Closed guillemcordoba closed 1 year ago

guillemcordoba commented 1 year ago

When building tx5 targeting an iPhone simulator in a MacOs host, I get this error:

   Compiling num_enum v0.5.11
   Compiling contrafact v0.2.0-rc.1
   Compiling quinn v0.8.5
The following warnings were emitted during compilation:

warning: NOTE:running go build: cd "/Users/guillemcordoba/rostanga-test/target/aarch64-apple-ios-sim/debug/build/tx5-go-pion-sys-fd5046261ca1ecbc/out" && GOARCH="arm64" GOCACHE="/Users/guillemcordoba/rostanga-test/target/aarch64-apple-ios-sim/debug/build/tx5-go-pion-sys-fd5046261ca1ecbc/out/go-build" "go" "build" "-ldflags" "-s -w" "-o" "/Users/guillemcordoba/rostanga-test/target/aarch64-apple-ios-sim/debug/build/tx5-go-pion-sys-fd5046261ca1ecbc/out/go-pion-webrtc.dylib" "-mod=vendor" "-buildmode=c-shared"

error: failed to run custom build command for `tx5-go-pion-sys v0.0.2-alpha`

Caused by:
  process didn't exit successfully: `/Users/guillemcordoba/rostanga-test/target/debug/build/tx5-go-pion-sys-d981e43f8395b85b/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-changed=go.mod
  cargo:rerun-if-changed=go.sum
  cargo:rerun-if-changed=buffer.go
  cargo:rerun-if-changed=const.go
  cargo:rerun-if-changed=datachannel.go
  cargo:rerun-if-changed=peerconnection.go
  cargo:rerun-if-changed=main.go
  cargo:rerun-if-changed=vendor.zip
  cargo:warning=NOTE:running go build: cd "/Users/guillemcordoba/rostanga-test/target/aarch64-apple-ios-sim/debug/build/tx5-go-pion-sys-fd5046261ca1ecbc/out" && GOARCH="arm64" GOCACHE="/Users/guillemcordoba/rostanga-test/target/aarch64-apple-ios-sim/debug/build/tx5-go-pion-sys-fd5046261ca1ecbc/out/go-build" "go" "build" "-ldflags" "-s -w" "-o" "/Users/guillemcordoba/rostanga-test/target/aarch64-apple-ios-sim/debug/build/tx5-go-pion-sys-fd5046261ca1ecbc/out/go-pion-webrtc.dylib" "-mod=vendor" "-buildmode=c-shared"

  --- stderr
  # github.com/holochain/tx4-go-pion-sys
  /nix/store/xl220d87dlnq05kiz1pjqa9snhlvr1rs-go-1.20.8/share/go/pkg/tool/darwin_arm64/link: running clang failed: exit status 1
  ld: warning: '/private/tmp/nix-shell.Sr1T2r/go-link-866172347/go.o' has malformed LC_DYSYMTAB, expected 111 undefined symbols to start at index 14939, found 121 undefined symbols starting at index 70
  ld: Undefined symbols:
    _darwin_arm_init_mach_exception_handler, referenced from:
        _x_cgo_init in 000005.o
    _darwin_arm_init_thread_exception_port, referenced from:
        _threadentry in 000005.o
        _x_cgo_init in 000005.o
  clang: error: linker command failed with exit code 1 (use -v to see invocation)

  thread 'main' panicked at 'error running go build', /Users/guillemcordoba/rostanga-test/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tx5-go-pion-sys-0.0.2-alpha/build.rs:129:5
  stack backtrace:
     0: rust_begin_unwind
               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:593:5
     1: core::panicking::panic_fmt
               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/panicking.rs:67:14
     2: build_script_build::go_build
               at ./build.rs:129:5
     3: build_script_build::main
               at ./build.rs:17:5
     4: core::ops::function::FnOnce::call_once
               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/ops/function.rs:250:5
  note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
warning: build failed, waiting for other jobs to finish...

I'm really confused... I don't know for sure that this is an error from tx5 or elsewhere. @Connoropolous have you found this error?

This is my flake.nix file:

{
  description = "Template for Holochain app development";

  inputs = {
    nixpkgs.follows = "holochain/nixpkgs";

    versions.url = "github:holochain/holochain?dir=versions/0_2";

    holochain = {
      url = "github:holochain/holochain";
      inputs.versions.follows = "versions";
    };

    rust-overlay.url = "github:oxalica/rust-overlay";
  };

  outputs = inputs:
    inputs.holochain.inputs.flake-parts.lib.mkFlake
      {
        inherit inputs;
      }
      {
        systems = builtins.attrNames inputs.holochain.devShells;
        perSystem =
          { inputs'
          , config
          , pkgs
          , system
          , lib
          , self'
          , ...
          }:      
          let
            overlays = [ (import inputs.rust-overlay) ];
            rustPkgs = import pkgs.path {
              inherit system overlays;
            };
            rust = rustPkgs.rust-bin.stable.latest.default.override {
              extensions = [ "rust-src" ];
              targets = [ 
                "armv7-linux-androideabi"
                "x86_64-linux-android"
                "i686-linux-android"
                "aarch64-unknown-linux-musl"
                "wasm32-unknown-unknown"
                "x86_64-pc-windows-gnu"
                "x86_64-unknown-linux-musl"
                "x86_64-apple-darwin"
                "aarch64-linux-android"
                "aarch64-apple-ios"
                "x86_64-apple-ios"
                "aarch64-apple-ios-sim"
              ];
            };

            s = if system == "aarch64-darwin" then "x86_64-darwin"
                else system;

            androidPkgs = import pkgs.path {
              system = s;
              config = {
                android_sdk.accept_license = true;
                allowUnfree = true;
              };
            };

            buildToolsVersion = "30.0.3";
            ndkVersion = "25.2.9519653";
            androidComposition = androidPkgs.androidenv.composeAndroidPackages {
              buildToolsVersions = [ buildToolsVersion ];
              platformVersions = [ "33" ];
              abiVersions = [ "x86_64" ];
              includeEmulator = true;
              includeNDK = true;
              ndkVersions = [ ndkVersion ];
              includeSystemImages = true;
              systemImageTypes = [ "google_apis" ];
              useGoogleAPIs = true;
            };
            androidSdk = androidComposition.androidsdk;

            xcodeBaseDir = "/Applications/Xcode.app";
          in {
            devShells.default = pkgs.mkShell {
              ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk";
              ANDROID_HOME = "${androidSdk}/libexec/android-sdk";
              ANDROID_NDK_ROOT = "${androidSdk}/libexec/android-sdk/ndk/${ndkVersion}";
              NDK_HOME = "${androidSdk}/libexec/android-sdk/ndk/${ndkVersion}";

              inputsFrom = [ inputs'.holochain.devShells.holonix ];
              packages = (with pkgs; [
                nodejs-18_x
                # more packages go here
                cargo-nextest
                upx
                libtool
              ])
              ++ ([
                rust
              ])
              ++ (lib.optionals pkgs.stdenv.isDarwin
                (with pkgs; [
                  cocoapods
                ])
              )
              ;

              buildInputs = (with pkgs; [
                openssl
                # this is required for glib-networking
                glib
                jdk17
              ])
              ++ [ androidSdk ]
              ++ (lib.optionals pkgs.stdenv.isLinux
                (with pkgs; [
                  webkitgtk_4_1.dev
                  gdk-pixbuf
                  gtk3
                  # Video/Audio data composition framework tools like "gst-inspect", "gst-launch" ...
                  gst_all_1.gstreamer
                  # Common plugins like "filesrc" to combine within e.g. gst-launch
                  gst_all_1.gst-plugins-base
                  # Specialized plugins separated by quality
                  gst_all_1.gst-plugins-good
                  gst_all_1.gst-plugins-bad
                  gst_all_1.gst-plugins-ugly
                  # Plugins to reuse ffmpeg to play almost every video format
                  gst_all_1.gst-libav
                  # Support the Video Audio (Hardware) Acceleration API
                  gst_all_1.gst-vaapi
                  libsoup_3
                ]))
              ++ lib.optionals pkgs.stdenv.isDarwin
                (with pkgs; [
                  darwin.apple_sdk.frameworks.Security
                  darwin.apple_sdk.frameworks.CoreServices
                  darwin.apple_sdk.frameworks.CoreFoundation
                  darwin.apple_sdk.frameworks.Foundation
                  darwin.apple_sdk.frameworks.AppKit
                  darwin.apple_sdk.frameworks.WebKit
                  darwin.apple_sdk.frameworks.Cocoa
                ])
              ;

              nativeBuildInputs = (with pkgs; [
                perl
                pkg-config
                makeWrapper
              ])
              ++ (lib.optionals pkgs.stdenv.isLinux
                (with pkgs; [
                  wrapGAppsHook
                ]))
              ++ (lib.optionals pkgs.stdenv.isDarwin [
                pkgs.xcbuild
                pkgs.libiconv
              ])
              ;

              shellHook = ''
                export GIO_MODULE_DIR=${pkgs.glib-networking}/lib/gio/modules/
                export GIO_EXTRA_MODULES=${pkgs.glib-networking}/lib/gio/modules
                export WEBKIT_DISABLE_COMPOSITING_MODE=1
                echo "no" | avdmanager -s create avd -n Pixel -k "system-images;android-33;google_apis;x86_64" --force

              '';
            };
          };
      };
}

@neonphog let me know if you need me to provide any other useful information about this.

Connoropolous commented 1 year ago

haven't seen before no, but a quick check through chatgpt4 got me to focus on: tx5-go-pion-sys-0.0.2-alpha/build.rs:129:5 line 129 of the crate tx5-go-pion-sys. can you confirm if the SHA you've got checked out has the same line 129 as develop right now? https://github.com/holochain/tx5/blob/da9a8fdd3fc8cbfc62c3d319c01449a595f69e16/crates/tx5-go-pion-sys/build.rs#L129

it summarized:

Here’s a summary of the main problems highlighted in the error message:

    The linker (ld) is warning about malformed LC_DYSYMTAB. It expected 111 undefined symbols to start at index 14939 but found 121 undefined symbols starting at index 70.
    The linker (ld) is unable to find the symbols _darwin_arm_init_mach_exception_handler and _darwin_arm_init_thread_exception_port, leading to undefined symbols errors.
    The Go build command is failing with exit status 1 due to the linker errors, causing the Rust build script to panic.

so I did a google for: "unable to find the symbols _darwin_arm_init_mach_exception_handler" and one interesting result is: https://github.com/golang/go/issues/46032#issuecomment-1356019920 this -tags=ios might be necessary but not sufficient to fix

Connoropolous commented 1 year ago

ah, I assume line 129 for you is: https://github.com/holochain/tx5/blame/8d0e74387d8aa541ef283db770541ff933f52b26/crates/tx5-go-pion-sys/build.rs#L129

using the latest may actually help https://github.com/holochain/tx5/blame/main/crates/tx5-go-pion-sys/build.rs#L129 given that there's some additional env vars per platform that are set.

neonphog commented 1 year ago

@guillemcordoba - Awesome. Yeah, ideally we'd get the ios simulator running in CI as well. Unfortunately I don't have as much experience with ios dev as android so it's not going to be as easy for me.

When cross-compiling did you specify the cross-compile linker in the build command?

guillemcordoba commented 1 year ago

Thanks @Connoropolous , pointing to the latest main gives a different error:

The following warnings were emitted during compilation:

warning: NOTE:running go build: cd "/Users/guillemcordoba/rostanga-test/target/aarch64-apple-ios-sim/debug/build/tx5-go-pion-sys-2584f61e307c2d38/out" && GOARCH="arm64" GOCACHE="/Users/guillemcordoba/rostanga-test/target/aarch64-apple-ios-sim/debug/build/tx5-go-pion-sys-2584f61e307c2d38/out/go-build" GOOS="ios" "go" "build" "-ldflags" "-s -w" "-o" "/Users/guillemcordoba/rostanga-test/target/aarch64-apple-ios-sim/debug/build/tx5-go-pion-sys-2584f61e307c2d38/out/go-pion-webrtc.dylib" "-mod=vendor" "-buildmode=c-shared"

error: failed to run custom build command for `tx5-go-pion-sys v0.0.2-alpha (https://github.com/holochain/tx5?branch=main#da9a8fdd)`

Caused by:
  process didn't exit successfully: `/Users/guillemcordoba/rostanga-test/target/debug/build/tx5-go-pion-sys-ea6e511c91bde17d/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-changed=go.mod
  cargo:rerun-if-changed=go.sum
  cargo:rerun-if-changed=buffer.go
  cargo:rerun-if-changed=const.go
  cargo:rerun-if-changed=datachannel.go
  cargo:rerun-if-changed=peerconnection.go
  cargo:rerun-if-changed=main.go
  cargo:rerun-if-changed=vendor.zip
  cargo:warning=NOTE:running go build: cd "/Users/guillemcordoba/rostanga-test/target/aarch64-apple-ios-sim/debug/build/tx5-go-pion-sys-2584f61e307c2d38/out" && GOARCH="arm64" GOCACHE="/Users/guillemcordoba/rostanga-test/target/aarch64-apple-ios-sim/debug/build/tx5-go-pion-sys-2584f61e307c2d38/out/go-build" GOOS="ios" "go" "build" "-ldflags" "-s -w" "-o" "/Users/guillemcordoba/rostanga-test/target/aarch64-apple-ios-sim/debug/build/tx5-go-pion-sys-2584f61e307c2d38/out/go-pion-webrtc.dylib" "-mod=vendor" "-buildmode=c-shared"

  --- stderr
  -buildmode=c-shared not supported on ios/arm64
  thread 'main' panicked at 'error running go build', /Users/guillemcordoba/rostanga-test/.cargo/git/checkouts/tx5-bc868c796fa5599f/da9a8fd/crates/tx5-go-pion-sys/build.rs:178:5
  stack backtrace:
     0: rust_begin_unwind
               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:593:5
     1: core::panicking::panic_fmt
               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/panicking.rs:67:14
     2: build_script_build::go_build
               at ./build.rs:178:5
     3: build_script_build::main
               at ./build.rs:17:5
     4: core::ops::function::FnOnce::call_once
               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/ops/function.rs:250:5
  note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
warning: build failed, waiting for other jobs to finish...

@neonphog I don't run the compilation command manually (I don't have any iOS experience either), tauri runs everything for me. These are the commands I think tauri is running:

/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -scheme rostangatest_iOS -workspace /Users/guillemcordoba/rostanga-test/src-tauri/gen/apple/rostangatest.xcodeproj/project.xcworkspace/ -sdk iphonesimulator -configuration debug -arch arm64-sim -allowProvisioningUpdates build
tauri ios xcode-script -v --platform iOS Simulator --sdk-root /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.0.sdk --framework-search-paths /Users/guillemcordoba/Library/Developer/Xcode/DerivedData/rostangatest-bovehlqdustugiesclixeelluihr/Build/Products/debug-iphonesimulator  "." --header-search-paths /Users/guillemcordoba/Library/Developer/Xcode/DerivedData/rostangatest-bovehlqdustugiesclixeelluihr/Build/Products/debug-iphonesimulator/include  --gcc-preprocessor-definitions  DEBUG=1 --configuration debug arm64-sim
neonphog commented 1 year ago

-buildmode=c-shared not supported on ios/arm64 -- ahh, right, we ran into this before, didn't we @Connoropolous -- yep, we're going to need to use c-archive on everything except windows. Unfortunately, that's going to be a bit of an effort.

@guillemcordoba - what is the priority of this so we can get it scheduled?

neonphog commented 1 year ago

https://github.com/holochain/tx5/issues/40#issuecomment-1572634563

Connoropolous commented 1 year ago

yes exactly those comments. was just going to link to them

guillemcordoba commented 1 year ago

Okey thanks! It's good to know I'm now up to speed with iOS as well. It's not really urgent to me - ideally I would want to be able to deliver a HC mobile app to users in the next 3-5 months. It seems clear that this is blocking for holochain mobile, which I know is a priority for the HC core team, so I think it's your decision on how you want to weight this.

neonphog commented 1 year ago

I've renamed https://github.com/holochain/tx5/issues/40 so it makes more sense. I'll close this now as a duplicate of that.