Skip to content

Commit

Permalink
Merge pull request #6 from ycm-core/m1
Browse files Browse the repository at this point in the history
Build for Apple Silicon
  • Loading branch information
puremourning authored Nov 19, 2021
2 parents df10e1a + 02d1fa3 commit 38140b7
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 29 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/package_llvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:


jobs:
build:
build-linux:
runs-on: ubuntu-18.04
strategy:
fail-fast: false
Expand All @@ -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 }}
81 changes: 53 additions & 28 deletions package_llvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,38 @@
OBJDUMP_VERSION_REGEX = re.compile(
r'^ 0x[0-9a-f]+ 0x00 \d+ (?P<library>.*)_(?P<version>.*)$' )

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 ):
Expand Down Expand Up @@ -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 ):
Expand Down Expand Up @@ -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' ] )


Expand All @@ -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' ] )


Expand Down Expand Up @@ -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 )

Expand Down Expand Up @@ -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'
Expand Down
5 changes: 5 additions & 0 deletions toolchain_files/arm64-apple-darwin.cmake
Original file line number Diff line number Diff line change
@@ -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")
18 changes: 18 additions & 0 deletions upload_clang.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}' ),
Expand Down

0 comments on commit 38140b7

Please sign in to comment.