TelegramMessenger / Telegram-iOS

Telegram-iOS
6.28k stars 1.64k forks source link

Building project on M1 Mac #520

Open bohlool opened 3 years ago

bohlool commented 3 years ago

Description

I have M1 Macbook and I'm trying to build this project using instructions that is provided here but I'm getting following error.

Screen Shot 2021-04-14 at 6 56 56 PM

Steps to Reproduce

Full list of steps done so far:

Download bazel 4.0.0 curl -O -L https://github.com/bazelbuild/bazel/releases/download/4.0.0/bazel-4.0.0-darwin-x86_64 (or there'll be a newer version). I downloaded it to ~/bazel-dist-4.0.0 mv bazel-4.0.0-darwin-x86_64 bazel chmod +x bazel download bazel source (git clone https://github.com/bazelbuild/bazel.git or whatever). It should contain this commit bazelbuild/bazel@8c7e11a do the patches you need: download https://gist.github.com/indragiek/e14162c0098d97ee976bceae9441f04d (it's from this comment bazelbuild/rules_apple#980 (comment)) go to bazel source directory, run git apply ~/patches/ios_sim_arm64.patch build new bazel from source using bazel 4.0.0 ~/bazel-dist-4.0.0/bazel build --cpu=darwin_arm64 //src:bazel Your build will be in bazel-bin/src/bazel. Copy it where you need it and run chmod +x bazel

Note that this build's version will be no_version:

➜ ./bazel --version bazel no_version So you'll need to use flag --overrideBazelVersion. So the full command for me was:

python3 build-system/Make/Make.py \ --overrideBazelVersion \ --bazel="$HOME/bazel-arm/bazel" \ --cacheDir="$HOME/telegram-bazel-cache" \ generateProject \ --configurationPath="$HOME/telegram-configuration" \ --disableExtensions \ --disableProvisioningProfiles Also note that --bazel uses new arm version, but --bazel_x86_64 is still that old x86 v4.0.0

Environment

Device: Apple MacBook Pro (13-inch, M1, 2020)

App version: 7.6

ali-fareed commented 3 years ago

What does xcode-select -p give you?

ali-fareed commented 3 years ago

Assuming you have resolved the issue.

bohlool commented 3 years ago

xcode-select -p returns:

/Applications/Xcode.app/Contents/Developer

ali-fareed commented 3 years ago

Are you able to build for a real device?

bohlool commented 3 years ago

I dont have a real iPhone device.

ali-fareed commented 3 years ago

Do you have access to an x86_64 Mac?

bohlool commented 3 years ago

Yes, I have no problem with that mac. It works like a charm.

ali-fareed commented 3 years ago

Does building the app work?

python3 build-system/Make/Make.py \
    --bazel="...path to arm64 bazel binary..." \
    build \
    --configurationPath="...path to configuration..." \
    --buildNumber=100001 \
    --configuration=debug_arm64
bohlool commented 3 years ago

No, It gives following error:

/Users/damavand/Development/Telegram-iOS/submodules/RaiseToListen/BUILD:3:14: Generating derived files for Swift module RaiseToListen failed: (Exit 1): worker failed: error executing command 
  (cd /private/var/tmp/_bazel_damavand/71125416429e706ef4e11cd6e45e246e/execroot/__main__ && \
  exec env - \
    APPLE_SDK_PLATFORM=iPhoneOS \
    APPLE_SDK_VERSION_OVERRIDE=14.4 \
    XCODE_VERSION_OVERRIDE=12.4.0.12D4e \
  bazel-out/host/bin/external/build_bazel_rules_swift/tools/worker/worker swiftc @bazel-out/ios-arm64-min9.0-applebin_ios-ios_arm64-dbg-ST-34f7b9bdf313/bin/submodules/RaiseToListen/RaiseToListen.swiftmodule-0.params)
Execution platform: @local_config_platform//:host
/private/var/tmp/_bazel_damavand/71125416429e706ef4e11cd6e45e246e/execroot/__main__/bazel-out/ios-arm64-min9.0-applebin_ios-ios_arm64-dbg-ST-34f7b9bdf313/bin/submodules/RaiseToListen/Impl/RaiseToListenImpl.modulemaps/module.modulemap:7:1: note: in file included from /private/var/tmp/_bazel_damavand/71125416429e706ef4e11cd6e45e246e/execroot/__main__/bazel-out/ios-arm64-min9.0-applebin_ios-ios_arm64-dbg-ST-34f7b9bdf313/bin/submodules/RaiseToListen/Impl/RaiseToListenImpl.modulemaps/module.modulemap:7:
extern module "DeviceProximity" "../../../../../../../bazel-out/ios-arm64-min9.0-applebin_ios-ios_arm64-dbg-ST-34f7b9bdf313/bin/submodules/DeviceProximity/DeviceProximity.internal.cppmap"
^
/private/var/tmp/_bazel_damavand/71125416429e706ef4e11cd6e45e246e/execroot/__main__/bazel-out/ios-arm64-min9.0-applebin_ios-ios_arm64-dbg-ST-34f7b9bdf313/bin/submodules/RaiseToListen/Impl/RaiseToListenImpl.modulemaps/../../../../../../../bazel-out/ios-arm64-min9.0-applebin_ios-ios_arm64-dbg-ST-34f7b9bdf313/bin/submodules/DeviceProximity/DeviceProximity.internal.cppmap:1:8: error: redefinition of module 'DeviceProximity'
module "DeviceProximity" {
       ^
/private/var/tmp/_bazel_damavand/71125416429e706ef4e11cd6e45e246e/execroot/__main__/bazel-out/ios-arm64-min9.0-applebin_ios-ios_arm64-dbg-ST-34f7b9bdf313/bin/submodules/DeviceProximity/DeviceProximity.modulemaps/module.modulemap:1:8: note: previously defined here
module "DeviceProximity" {
       ^
/private/var/tmp/_bazel_damavand/71125416429e706ef4e11cd6e45e246e/execroot/__main__/bazel-out/ios-arm64-min9.0-applebin_ios-ios_arm64-dbg-ST-34f7b9bdf313/bin/submodules/DeviceProximity/DeviceProximity.modulemaps/module.modulemap:1:8: error: redefinition of module 'DeviceProximity'
module "DeviceProximity" {
       ^
/private/var/tmp/_bazel_damavand/71125416429e706ef4e11cd6e45e246e/execroot/__main__/bazel-out/ios-arm64-min9.0-applebin_ios-ios_arm64-dbg-ST-34f7b9bdf313/bin/submodules/RaiseToListen/Impl/RaiseToListenImpl.modulemaps/../../../../../../../bazel-out/ios-arm64-min9.0-applebin_ios-ios_arm64-dbg-ST-34f7b9bdf313/bin/submodules/DeviceProximity/DeviceProximity.internal.cppmap:1:8: note: previously defined here
module "DeviceProximity" {
       ^
submodules/RaiseToListen/Sources/RaiseToListen.swift:3:8: error: could not build Objective-C module 'RaiseToListenImpl'
import RaiseToListenImpl
       ^
Target //Telegram:Telegram failed to build
ERROR: /Users/damavand/Development/Telegram-iOS/Telegram/BUILD:207:14 Compiling Swift module Telegram_Lib failed: (Exit 1): worker failed: error executing command 
  (cd /private/var/tmp/_bazel_damavand/71125416429e706ef4e11cd6e45e246e/execroot/__main__ && \
  exec env - \
    APPLE_SDK_PLATFORM=iPhoneOS \
    APPLE_SDK_VERSION_OVERRIDE=14.4 \
    XCODE_VERSION_OVERRIDE=12.4.0.12D4e \
  bazel-out/host/bin/external/build_bazel_rules_swift/tools/worker/worker swiftc @bazel-out/ios-arm64-min9.0-applebin_ios-ios_arm64-dbg-ST-34f7b9bdf313/bin/submodules/RaiseToListen/RaiseToListen.swiftmodule-0.params)
Execution platform: @local_config_platform//:host
INFO: Elapsed time: 77.796s, Critical Path: 51.03s
INFO: 1229 processes: 476 internal, 753 local.
FAILED: Build did NOT complete successfully
Traceback (most recent call last):
  File "/Users/damavand/Development/Telegram-iOS/build-system/Make/Make.py", line 562, in 
    build(arguments=args)
  File "/Users/damavand/Development/Telegram-iOS/build-system/Make/Make.py", line 392, in build
    bazel_command_line.invoke_build()
  File "/Users/damavand/Development/Telegram-iOS/build-system/Make/Make.py", line 294, in invoke_build
    call_executable(combined_arguments)
  File "/Users/damavand/Development/Telegram-iOS/build-system/Make/BuildEnvironment.py", line 60, in call_executable
    subprocess.check_call(resolved_arguments, env=resolved_env)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 373, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/Users/damavand/bazel-arm/bazel', 'build', 'Telegram/Telegram', '--override_repository=build_configuration=/Users/damavand/telegram-configuration', '--announce_rc', '--features=swift.use_global_module_cache', '--verbose_failures', '--features=swift.skip_function_bodies_for_derived_files', '--jobs=8', '--define=buildNumber=100001', '--define=telegramVersion=7.6', '--features=swift.split_derived_files_generation', '-c', 'dbg', '--ios_multi_cpus=arm64', '--watchos_cpus=armv7k,arm64_32', '--features=swift.enable_batch_mode', '--swiftcopt=-j7']' returned non-zero exit status 1.
ali-fareed commented 3 years ago

Is your APFS case-sensitive?

bohlool commented 3 years ago

No, It isn't.

cybernet commented 3 years ago

might be related #532

sysbol commented 3 years ago

Hello, my problem is the same as yours. How can you solve it? Thank you #534 I'm using Xcode version 12.5 (12e262)

zeinali0 commented 3 years ago

I have same problem. I cannot build app-version 7.6 on M1 Mac. And the error is not always on MozjpegBinding module. Everytime I get error on a new Objective-C module.

python3 build-system/Make/Make.py \
    --overrideBazelVersion \
    --bazel="$HOME/bazel-arm/bazel" \
    build \
    --configurationPath="$HOME/telegram-configuration" \
    --configuration=debug_arm64 --buildNumber=100001
Overriding the required bazel version 4.0.0 with no_version as reported by /Users/macbook/bazel-arm/bazel
TelegramBuild: running
/Users/macbook/bazel-arm/bazel build Telegram/Telegram --override_repository=build_configuration=/Users/macbook/telegram-configuration --announce_rc --features=swift.use_global_module_cache --verbose_failures --features=swift.skip_function_bodies_for_derived_files --jobs=8 --define=buildNumber=100001 --define=telegramVersion=7.6 --features=swift.split_derived_files_generation -c dbg --ios_multi_cpus=arm64 --watchos_cpus=armv7k,arm64_32 --features=swift.enable_batch_mode --swiftcopt=-j7
INFO: Options provided by the client:
  Inherited 'common' options: --isatty=1 --terminal_columns=204
INFO: Reading rc options for 'build' from /Users/macbook/Development/Telegram-iOS-2/.bazelrc:
  'build' options: --action_env=ZERO_AR_DATE=1 --apple_platform_type=ios --cxxopt=-std=c++14 --per_file_copt=third-party/webrtc/.*.cpp$,@-std=c++14 --per_file_copt=third-party/webrtc/.*.cc$,@-std=c++14 --per_file_copt=third-party/webrtc/.*.mm$,@-std=c++14 --features=debug_prefix_map_pwd_is_dot --features=swift.cacheable_swiftmodules --features=swift.debug_prefix_map --features=swift.enable_vfsoverlays --strategy=Genrule=standalone --spawn_strategy=standalone --strategy=SwiftCompile=standalone --define RULES_SWIFT_BUILD_DUMMY_WORKER=1
INFO: Build options --//Telegram:disableExtensions, --//Telegram:disableProvisioningProfiles, --apple_generate_dsym, and 6 more have changed, discarding analysis cache.
DEBUG: /private/var/tmp/_bazel_macbook/aa07a60705882d316c7c348bfd72602d/external/build_bazel_rules_apple/apple/internal/partials/extension_safe_validation.bzl:42:22: The target //Telegram:NotificationServiceExtension is for an extension but its framework dependency //Telegram:MtProtoKitFramework is not marked extension-safe. Specify 'extension_safe = 1' on the framework target. This will soon cause a build failure.
DEBUG: /private/var/tmp/_bazel_macbook/aa07a60705882d316c7c348bfd72602d/external/build_bazel_rules_apple/apple/internal/partials/extension_safe_validation.bzl:42:22: The target //Telegram:NotificationServiceExtension is for an extension but its framework dependency //Telegram:SwiftSignalKitFramework is not marked extension-safe. Specify 'extension_safe = 1' on the framework target. This will soon cause a build failure.
DEBUG: /private/var/tmp/_bazel_macbook/aa07a60705882d316c7c348bfd72602d/external/build_bazel_rules_apple/apple/internal/partials/extension_safe_validation.bzl:42:22: The target //Telegram:NotificationServiceExtension is for an extension but its framework dependency //Telegram:PostboxFramework is not marked extension-safe. Specify 'extension_safe = 1' on the framework target. This will soon cause a build failure.
DEBUG: /private/var/tmp/_bazel_macbook/aa07a60705882d316c7c348bfd72602d/external/build_bazel_rules_apple/apple/internal/partials/extension_safe_validation.bzl:42:22: The target //Telegram:WidgetExtension is for an extension but its framework dependency //Telegram:SwiftSignalKitFramework is not marked extension-safe. Specify 'extension_safe = 1' on the framework target. This will soon cause a build failure.
DEBUG: /private/var/tmp/_bazel_macbook/aa07a60705882d316c7c348bfd72602d/external/build_bazel_rules_apple/apple/internal/partials/extension_safe_validation.bzl:42:22: The target //Telegram:WidgetExtension is for an extension but its framework dependency //Telegram:PostboxFramework is not marked extension-safe. Specify 'extension_safe = 1' on the framework target. This will soon cause a build failure.
DEBUG: /private/var/tmp/_bazel_macbook/aa07a60705882d316c7c348bfd72602d/external/build_bazel_rules_apple/apple/internal/partials/extension_safe_validation.bzl:42:22: The target //Telegram:WidgetExtension is for an extension but its framework dependency //Telegram:SyncCoreFramework is not marked extension-safe. Specify 'extension_safe = 1' on the framework target. This will soon cause a build failure.
DEBUG: /private/var/tmp/_bazel_macbook/aa07a60705882d316c7c348bfd72602d/external/build_bazel_rules_apple/apple/internal/partials/extension_safe_validation.bzl:42:22: The target //Telegram:WidgetExtension is for an extension but its framework dependency //Telegram:TelegramCoreFramework is not marked extension-safe. Specify 'extension_safe = 1' on the framework target. This will soon cause a build failure.
DEBUG: /private/var/tmp/_bazel_macbook/aa07a60705882d316c7c348bfd72602d/external/build_bazel_rules_apple/apple/internal/partials/extension_safe_validation.bzl:42:22: The target //Telegram:IntentsExtension is for an extension but its framework dependency //Telegram:SwiftSignalKitFramework is not marked extension-safe. Specify 'extension_safe = 1' on the framework target. This will soon cause a build failure.
DEBUG: /private/var/tmp/_bazel_macbook/aa07a60705882d316c7c348bfd72602d/external/build_bazel_rules_apple/apple/internal/partials/extension_safe_validation.bzl:42:22: The target //Telegram:IntentsExtension is for an extension but its framework dependency //Telegram:PostboxFramework is not marked extension-safe. Specify 'extension_safe = 1' on the framework target. This will soon cause a build failure.
DEBUG: /private/var/tmp/_bazel_macbook/aa07a60705882d316c7c348bfd72602d/external/build_bazel_rules_apple/apple/internal/partials/extension_safe_validation.bzl:42:22: The target //Telegram:IntentsExtension is for an extension but its framework dependency //Telegram:TelegramCoreFramework is not marked extension-safe. Specify 'extension_safe = 1' on the framework target. This will soon cause a build failure.
DEBUG: /private/var/tmp/_bazel_macbook/aa07a60705882d316c7c348bfd72602d/external/build_bazel_rules_apple/apple/internal/partials/extension_safe_validation.bzl:42:22: The target //Telegram:IntentsExtension is for an extension but its framework dependency //Telegram:SyncCoreFramework is not marked extension-safe. Specify 'extension_safe = 1' on the framework target. This will soon cause a build failure.
DEBUG: /private/var/tmp/_bazel_macbook/aa07a60705882d316c7c348bfd72602d/external/build_bazel_rules_apple/apple/internal/partials/extension_safe_validation.bzl:42:22: The target //Telegram:NotificationContentExtension is for an extension but its framework dependency //Telegram:TelegramUIFramework is not marked extension-safe. Specify 'extension_safe = 1' on the framework target. This will soon cause a build failure.
DEBUG: /private/var/tmp/_bazel_macbook/aa07a60705882d316c7c348bfd72602d/external/build_bazel_rules_apple/apple/internal/partials/extension_safe_validation.bzl:42:22: The target //Telegram:ShareExtension is for an extension but its framework dependency //Telegram:TelegramUIFramework is not marked extension-safe. Specify 'extension_safe = 1' on the framework target. This will soon cause a build failure.
INFO: Analyzed target //Telegram:Telegram (308 packages loaded, 20661 targets configured).
INFO: Found 1 target...
ERROR: /Users/macbook/Development/Telegram-iOS-2/submodules/ImageCompression/BUILD:3:14: Generating derived files for Swift module ImageCompression failed: (Exit 1): worker failed: error executing command 
  (cd /private/var/tmp/_bazel_macbook/aa07a60705882d316c7c348bfd72602d/execroot/__main__ && \
  exec env - \
    APPLE_SDK_PLATFORM=iPhoneOS \
    APPLE_SDK_VERSION_OVERRIDE=14.4 \
    XCODE_VERSION_OVERRIDE=12.4.0.12D4e \
  bazel-out/host/bin/external/build_bazel_rules_swift/tools/worker/worker swiftc @bazel-out/ios-arm64-min9.0-applebin_ios-ios_arm64-dbg-ST-34fda1233dfa/bin/submodules/ImageCompression/ImageCompression.swiftmodule-0.params)
Execution platform: @local_config_platform//:host
/private/var/tmp/_bazel_macbook/aa07a60705882d316c7c348bfd72602d/execroot/__main__/bazel-out/ios-arm64-min9.0-applebin_ios-ios_arm64-dbg-ST-34fda1233dfa/bin/submodules/MozjpegBinding/MozjpegBinding.modulemaps/module.modulemap:6:1: note: in file included from /private/var/tmp/_bazel_macbook/aa07a60705882d316c7c348bfd72602d/execroot/__main__/bazel-out/ios-arm64-min9.0-applebin_ios-ios_arm64-dbg-ST-34fda1233dfa/bin/submodules/MozjpegBinding/MozjpegBinding.modulemaps/module.modulemap:6:
extern module "mozjpeg" "../../../../../../bazel-out/ios-arm64-min9.0-applebin_ios-ios_arm64-dbg-ST-34fda1233dfa/bin/third-party/mozjpeg/mozjpeg.internal.cppmap"
^
/private/var/tmp/_bazel_macbook/aa07a60705882d316c7c348bfd72602d/execroot/__main__/bazel-out/ios-arm64-min9.0-applebin_ios-ios_arm64-dbg-ST-34fda1233dfa/bin/submodules/MozjpegBinding/MozjpegBinding.modulemaps/../../../../../../bazel-out/ios-arm64-min9.0-applebin_ios-ios_arm64-dbg-ST-34fda1233dfa/bin/third-party/mozjpeg/mozjpeg.internal.cppmap:1:8: error: redefinition of module 'mozjpeg'
module "mozjpeg" {
       ^
/private/var/tmp/_bazel_macbook/aa07a60705882d316c7c348bfd72602d/execroot/__main__/bazel-out/ios-arm64-min9.0-applebin_ios-ios_arm64-dbg-ST-34fda1233dfa/bin/third-party/mozjpeg/mozjpeg.modulemaps/module.modulemap:1:8: note: previously defined here
module "mozjpeg" {
       ^
/private/var/tmp/_bazel_macbook/aa07a60705882d316c7c348bfd72602d/execroot/__main__/bazel-out/ios-arm64-min9.0-applebin_ios-ios_arm64-dbg-ST-34fda1233dfa/bin/third-party/mozjpeg/mozjpeg.modulemaps/module.modulemap:1:8: error: redefinition of module 'mozjpeg'
module "mozjpeg" {
       ^
/private/var/tmp/_bazel_macbook/aa07a60705882d316c7c348bfd72602d/execroot/__main__/bazel-out/ios-arm64-min9.0-applebin_ios-ios_arm64-dbg-ST-34fda1233dfa/bin/submodules/MozjpegBinding/MozjpegBinding.modulemaps/../../../../../../bazel-out/ios-arm64-min9.0-applebin_ios-ios_arm64-dbg-ST-34fda1233dfa/bin/third-party/mozjpeg/mozjpeg.internal.cppmap:1:8: note: previously defined here
module "mozjpeg" {
       ^
submodules/ImageCompression/Sources/ImageCompression.swift:4:8: error: could not build Objective-C module 'MozjpegBinding'
import MozjpegBinding
       ^
Target //Telegram:Telegram failed to build
ERROR: /Users/macbook/Development/Telegram-iOS-2/Telegram/BUILD:207:14 Compiling Swift module Telegram_Lib failed: (Exit 1): worker failed: error executing command 
  (cd /private/var/tmp/_bazel_macbook/aa07a60705882d316c7c348bfd72602d/execroot/__main__ && \
  exec env - \
    APPLE_SDK_PLATFORM=iPhoneOS \
    APPLE_SDK_VERSION_OVERRIDE=14.4 \
    XCODE_VERSION_OVERRIDE=12.4.0.12D4e \
  bazel-out/host/bin/external/build_bazel_rules_swift/tools/worker/worker swiftc @bazel-out/ios-arm64-min9.0-applebin_ios-ios_arm64-dbg-ST-34fda1233dfa/bin/submodules/ImageCompression/ImageCompression.swiftmodule-0.params)
Execution platform: @local_config_platform//:host
INFO: Elapsed time: 7.720s, Critical Path: 2.17s
INFO: 46 processes: 14 internal, 32 local.
FAILED: Build did NOT complete successfully
Traceback (most recent call last):
  File "/Users/macbook/Development/Telegram-iOS-2/build-system/Make/Make.py", line 562, in <module>
    build(arguments=args)
  File "/Users/macbook/Development/Telegram-iOS-2/build-system/Make/Make.py", line 392, in build
    bazel_command_line.invoke_build()
  File "/Users/macbook/Development/Telegram-iOS-2/build-system/Make/Make.py", line 294, in invoke_build
    call_executable(combined_arguments)
  File "/Users/macbook/Development/Telegram-iOS-2/build-system/Make/BuildEnvironment.py", line 60, in call_executable
    subprocess.check_call(resolved_arguments, env=resolved_env)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 373, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/Users/macbook/bazel-arm/bazel', 'build', 'Telegram/Telegram', '--override_repository=build_configuration=/Users/macbook/telegram-configuration', '--announce_rc', '--features=swift.use_global_module_cache', '--verbose_failures', '--features=swift.skip_function_bodies_for_derived_files', '--jobs=8', '--define=buildNumber=100001', '--define=telegramVersion=7.6', '--features=swift.split_derived_files_generation', '-c', 'dbg', '--ios_multi_cpus=arm64', '--watchos_cpus=armv7k,arm64_32', '--features=swift.enable_batch_mode', '--swiftcopt=-j7']' returned non-zero exit status 1.
Rotemy commented 2 years ago

try this: For anyone that has M1 Max, what I did is downloaded version 5 from here https://github.com/bazelbuild/bazel/releases/tag/5.0.0 and used that. Nothing else worked for me.

jingsongshen commented 2 years ago

@Rotemy bazel-5.0.0-darwin-arm64 or bazel-5.0.0-darwin-x86_64 ? thanks

Rotemy commented 2 years ago

bazel-5.0.0-darwin-arm64

bazel-5.0.0-darwin-arm64