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

Ben omp #7

Merged
merged 13 commits into from
Apr 13, 2024
2 changes: 1 addition & 1 deletion .github/workflows/package_llvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
run: ./package_llvm.py --target-architecture ${{ matrix.target }} ${{ github.event.inputs.version }}

build-macos:
runs-on: macos-11
runs-on: macos-13
strategy:
fail-fast: false
matrix:
Expand Down
61 changes: 46 additions & 15 deletions package_llvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@
},
'Darwin': {
'x86_64': {
'host': 'x86_64-apple-darwin',
'host': 'x86_64-apple-darwin'
if platform.processor() != 'arm' else 'arm64-apple-darwin',
'target': 'x86_64-apple-darwin',
'archive': 'x86_64-apple-darwin'
},
'arm64': {
'host': 'x86_64-apple-darwin',
'host': 'x86_64-apple-darwin'
if platform.processor() != 'arm' else 'arm64-apple-darwin',
'target': 'arm64-apple-darwin',
'archive': 'arm64-apple-darwin'
}
Expand Down Expand Up @@ -187,6 +189,19 @@ def GetLogicalCores():
return subprocess.check_output( cmd ).decode( 'utf-8' ).strip()


def GetGeneratorArgs():
return shutil.which( 'ninja' ) and [ '-G', 'Ninja' ] or []


def GetCacheArgs( build_dir ):
return shutil.which( 'ccache' ) and [
'-DLLVM_CCACHE_BUILD=ON',
'-DLLVM_CCACHE_MAXSIZE=5G',
'-DLLVM_CCACHE_DIR={}'.format(
os.path.abspath( os.path.join( build_dir, '..', 'ccache' ) ) ),
] or []


def BuildLlvm( build_dir,
install_dir,
llvm_source_dir,
Expand All @@ -202,10 +217,11 @@ def BuildLlvm( build_dir,
# variables defined by LLVM.
cmake_configure_args = [
cmake,
*GetGeneratorArgs(),
# A release build implies LLVM_ENABLE_ASSERTIONS=OFF.
'-DCMAKE_BUILD_TYPE=Release',
'-DCMAKE_INSTALL_PREFIX={}'.format( install_dir ),
'-DLLVM_ENABLE_PROJECTS=clang;clang-tools-extra',
'-DLLVM_ENABLE_PROJECTS=clang;clang-tools-extra;openmp',
'-DLLVM_DEFAULT_TARGET_TRIPLE={}'.format( target ),
'-DLLVM_TARGETS_TO_BUILD=all',
'-DLLVM_TABLEGEN={}'.format(
Expand All @@ -215,13 +231,13 @@ def BuildLlvm( build_dir,
'-DLLVM_TARGET_ARCH={}'.format( target_architecture ),
'-DLLVM_INCLUDE_EXAMPLES=OFF',
'-DLLVM_INCLUDE_TESTS=OFF',
'-DLLVM_INCLUDE_GO_TESTS=OFF',
'-DLLVM_INCLUDE_DOCS=OFF',
'-DLLVM_ENABLE_TERMINFO=OFF',
'-DLLVM_ENABLE_ZLIB=OFF',
'-DLLVM_ENABLE_LIBEDIT=OFF',
'-DLLVM_ENABLE_LIBXML2=OFF',
'-DLLVM_ENABLE_ZSTD=OFF',
*GetCacheArgs( build_dir ),
os.path.join( llvm_source_dir, 'llvm' )
]
if target != host: # We're cross compilinging and need a toolchain file.
Expand All @@ -231,6 +247,13 @@ def BuildLlvm( build_dir,
if os.path.exists( toolchain_file ):
cmake_configure_args.append(
'-DCMAKE_TOOLCHAIN_FILE={}'.format( toolchain_file ) )
else:
print( "WARNING: Cross compiling, but no toolchain file found for " +
toolchain_file )
sys.exit( 1 )

print( 'CMake Args: {}'.format( ' '.join( cmake_configure_args ) ) )

subprocess.check_call( cmake_configure_args )

subprocess.check_call( [
Expand All @@ -246,8 +269,10 @@ def BuildTableGen( build_dir, llvm_source_dir ):
cmake = shutil.which( 'cmake' )
subprocess.check_call( [
cmake,
*GetGeneratorArgs(),
'-DCMAKE_BUILD_TYPE=Release',
'-DLLVM_ENABLE_PROJECTS=clang',
*GetCacheArgs( build_dir ),
os.path.join( llvm_source_dir, 'llvm' ) ] )

subprocess.check_call( [
Expand Down Expand Up @@ -395,6 +420,9 @@ def ParseArguments():
parser.add_argument( '--release-candidate', type = int,
help = 'LLVM release candidate number.' )

parser.add_argument( '--no-upload', action = 'store_true',
help = "Don't upload the archive to GitHub." )

parser.add_argument( '--gh-user', action='store',
help = 'GitHub user name. Defaults to environment '
'variable: GITHUB_USERNAME' )
Expand All @@ -416,17 +444,18 @@ def ParseArguments():

args = parser.parse_args()

if not args.gh_user:
if 'GITHUB_USERNAME' not in os.environ:
sys.exit( 'ERROR: Must specify either --gh-user or '
'GITHUB_USERNAME in environment' )
args.gh_user = os.environ[ 'GITHUB_USERNAME' ]
if not args.no_upload:
if not args.gh_user:
if 'GITHUB_USERNAME' not in os.environ:
sys.exit( 'ERROR: Must specify either --gh-user or '
'GITHUB_USERNAME in environment' )
args.gh_user = os.environ[ 'GITHUB_USERNAME' ]

if not args.gh_token:
if 'GITHUB_TOKEN' not in os.environ:
sys.exit( 'ERROR: Must specify either --gh-token or '
'GITHUB_TOKEN in environment' )
args.gh_token = os.environ[ 'GITHUB_TOKEN' ]
if not args.gh_token:
if 'GITHUB_TOKEN' not in os.environ:
sys.exit( 'ERROR: Must specify either --gh-token or '
'GITHUB_TOKEN in environment' )
args.gh_token = os.environ[ 'GITHUB_TOKEN' ]

return args

Expand Down Expand Up @@ -478,7 +507,9 @@ def Main():
if not os.path.exists( bundle_path ):
with WorkingDirectory( base_dir ):
BundleLlvm( bundle_name, archive_name, llvm_install_dir, bundle_version )
UploadLlvm( args, bundle_path )

if not args.no_upload:
UploadLlvm( args, bundle_path )


if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions toolchain_files/arm64-apple-darwin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ set(CMAKE_SYSTEM_PROCESSOR arm64)

set(CMAKE_C_FLAGS_INIT "-arch arm64")
set(CMAKE_CXX_FLAGS_INIT "-arch arm64")
set(CMAKE_ASM_FLAGS_INIT "-arch arm64")
6 changes: 6 additions & 0 deletions toolchain_files/x86_64-apple-darwin.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set(CMAKE_SYSTEM_NAME Darwin)
set(CMAKE_SYSTEM_PROCESSOR x86_64)

set(CMAKE_C_FLAGS_INIT "-arch x86_64")
set(CMAKE_CXX_FLAGS_INIT "-arch x86_64")
set(CMAKE_ASM_FLAGS_INIT "-arch x86_64")