diff --git a/.github/workflows/package_llvm.yml b/.github/workflows/package_llvm.yml index 27e88d9..99a0e63 100644 --- a/.github/workflows/package_llvm.yml +++ b/.github/workflows/package_llvm.yml @@ -10,7 +10,7 @@ on: jobs: - build: + build-linux: runs-on: ubuntu-18.04 strategy: fail-fast: false @@ -28,3 +28,18 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: ./package_llvm.py --target-architecture ${{ matrix.target }} ${{ github.event.inputs.version }} + build-macos: + runs-on: macos-10.15 + strategy: + fail-fast: false + matrix: + target: [ arm64 ] + steps: + - uses: actions/checkout@v2 + - name: install requirements + run: pip3 install -r requirements.txt + - name: Package + env: + GITHUB_USERNAME: ${{ github.actor }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: ./package_llvm.py --target-architecture ${{ matrix.target }} ${{ github.event.inputs.version }} diff --git a/package_llvm.py b/package_llvm.py index 05163f8..030d42a 100755 --- a/package_llvm.py +++ b/package_llvm.py @@ -39,25 +39,38 @@ OBJDUMP_VERSION_REGEX = re.compile( r'^ 0x[0-9a-f]+ 0x00 \d+ (?P.*)_(?P.*)$' ) -assert platform.system() == 'Linux', 'GNU/Linux only, for now' ENV_DATA = { - 'x86_64': { - 'host': 'x86_64-unknown-linux-gnu', - 'target': 'x86_64-unknown-linux-gnu', - 'archive': 'x86_64-unknown-linux-gnu' + 'Linux': { + 'x86_64': { + 'host': 'x86_64-unknown-linux-gnu', + 'target': 'x86_64-unknown-linux-gnu', + 'archive': 'x86_64-unknown-linux-gnu' + }, + 'arm': { + 'host': 'x86_64-unknown-linux-gnu', + 'target': 'arm-linux-gnueabihf', + 'archive': 'armv7a-linux-gnueabihf' + }, + 'aarch64': { + 'host': 'x86_64-unknown-linux-gnu', + 'target': 'aarch64-linux-gnu', + 'archive': 'aarch64-linux-gnu' + } }, - 'arm': { - 'host': 'x86_64-unknown-linux-gnu', - 'target': 'arm-linux-gnueabihf', - 'archive': 'armv7a-linux-gnueabihf' - }, - 'aarch64': { - 'host': 'x86_64-unknown-linux-gnu', - 'target': 'aarch64-linux-gnu', - 'archive': 'aarch64-linux-gnu' + 'Darwin': { + 'x86_64': { + 'host': 'x86_64-apple-darwin', + 'target': 'x86_64-apple-darwin', + 'archive': 'x86_64-apple-darwin' + }, + 'arm64': { + 'host': 'x86_64-apple-darwin', + 'target': 'arm64-apple-darwin', + 'archive': 'arm64-apple-darwin' + } } } - +assert platform.system() in ENV_DATA @contextlib.contextmanager def WorkingDirectory( cwd ): @@ -165,13 +178,21 @@ def DownloadSource( url, source ): Extract( archive ) +def GetLogicalCores(): + cmd = [ 'nproc' ] + if platform.system() == "Darwin": + cmd = [ 'sysctl', '-n', 'hw.logicalcpu' ] + + return subprocess.check_output( cmd ).decode( 'utf-8' ).strip() + + def BuildLlvm( build_dir, install_dir, llvm_source_dir, tblgen_root, target_architecture ): - host = ENV_DATA[ target_architecture ][ 'host' ] - target = ENV_DATA[ target_architecture ][ 'target' ] + host = ENV_DATA[ platform.system() ][ target_architecture ][ 'host' ] + target = ENV_DATA[ platform.system() ][ target_architecture ][ 'target' ] print( 'Host triple:', host ) print( 'Target triple:', target ) with WorkingDirectory( build_dir ): @@ -202,19 +223,19 @@ def BuildLlvm( build_dir, os.path.join( llvm_source_dir, 'llvm' ) ] if target != host: # We're cross compilinging and need a toolchain file. - cmake_configure_args.append( - '-DCMAKE_TOOLCHAIN_FILE={}'.format( - os.path.join( DIR_OF_THIS_SCRIPT, - 'toolchain_files', - target + '.cmake' ) ) - ) + toolchain_file = os.path.join( DIR_OF_THIS_SCRIPT, + 'toolchain_files', + target + '.cmake' ) + if os.path.exists( toolchain_file ): + cmake_configure_args.append( + '-DCMAKE_TOOLCHAIN_FILE={}'.format( toolchain_file ) ) subprocess.check_call( cmake_configure_args ) subprocess.check_call( [ cmake, '--build', '.', '--parallel', - subprocess.check_output( [ 'nproc' ] ).decode( 'utf-8' ).strip(), + GetLogicalCores(), '--target', 'install' ] ) @@ -231,7 +252,7 @@ def BuildTableGen( build_dir, llvm_source_dir ): cmake, '--build', '.', '--parallel', - subprocess.check_output( [ 'nproc' ] ).decode( 'utf-8' ).strip(), + GetLogicalCores(), '--target', 'llvm-tblgen', 'clang-tblgen' ] ) @@ -410,7 +431,9 @@ def ParseArguments(): def Main(): args = ParseArguments() - base_dir = os.path.abspath( args.base_dir ) + base_dir = os.path.join( + os.path.abspath( args.base_dir ), + ENV_DATA[ platform.system() ][ args.target_architecture ][ 'target' ] ) if not os.path.isdir( base_dir ): os.mkdir( base_dir ) @@ -440,9 +463,11 @@ def Main(): llvm_source_dir, tblgen_build_dir, args.target_architecture ) - CheckLlvm( llvm_install_dir ) - target = ENV_DATA[ args.target_architecture ][ 'archive' ] + if platform.system() == 'Linux': + CheckLlvm( llvm_install_dir ) + + target = ENV_DATA[ platform.system() ][ args.target_architecture ][ 'archive' ] bundle_version = GetBundleVersion( args ) bundle_name = BUNDLE_NAME.format( version = bundle_version, target = target ) archive_name = bundle_name + '.tar.xz' diff --git a/toolchain_files/arm64-apple-darwin.cmake b/toolchain_files/arm64-apple-darwin.cmake new file mode 100644 index 0000000..0814a06 --- /dev/null +++ b/toolchain_files/arm64-apple-darwin.cmake @@ -0,0 +1,5 @@ +set(CMAKE_SYSTEM_NAME Darwin) +set(CMAKE_SYSTEM_PROCESSOR arm64) + +set(CMAKE_C_FLAGS_INIT "-arch arm64") +set(CMAKE_CXX_FLAGS_INIT "-arch arm64") diff --git a/upload_clang.py b/upload_clang.py index 9f91b67..e729e10 100755 --- a/upload_clang.py +++ b/upload_clang.py @@ -85,6 +85,24 @@ def OnMac(): ], } }, + 'arm64-apple-darwin': { + 'url': 'https://github.com/ycm-core/llvm/' + 'releases/download/{llvm_version}/{llvm_package}', + 'format': 'lzma', + 'llvm_package': 'clang+llvm-{llvm_version}-{os_name}.tar.xz', + 'clangd_package': { + 'name': 'clangd-{llvm_version}-{os_name}.tar.bz2', + 'files_to_copy': [ + os.path.join( 'bin', 'clangd' ), + ] + }, + 'libclang_package': { + 'name': 'libclang-{llvm_version}-{os_name}.tar.bz2', + 'files_to_copy': [ + os.path.join( 'lib', 'libclang.dylib' ), + ], + } + }, 'x86_64-unknown-linux-gnu': { 'url': ( 'https://github.com/ycm-core/llvm/' 'releases/download/{llvm_version}/{llvm_package}' ),