Skip to content

Commit

Permalink
llvm_bin uses same universal darwin archive for arm as for x86_64.
Browse files Browse the repository at this point in the history
Allow to override target architecture sufix in archive name in tgz_package.
tgz_package uses build platform for naming archives.
When build packages for multiple architectures like x86_64 and arm, then the archive name is not correct.
Update the script of tgz_package to check for configuration option `ohai['target_arch']` as target arch name.

It allows to specify architecture in project like:

```
ohai['target_arch'] = 'universal'
dependency 'tgz_package'
```

Also introduces Github Action to build llvm from scratch, similar to circle ci.
  • Loading branch information
miry committed Jan 5, 2024
1 parent 9d6e645 commit 5fe41d3
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 3 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/llvm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Darwin LLVM build

on:
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: false
default: 'warn'
type: choice
options:
- info
- warn
- debug
push:
branches:
- 267-llvm_bin-universal
- '*build-llvm*'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
LLVM_VERSION: 15.0.7
MACOSX_DEPLOYMENT_TARGET: 10.11
LOG_LEVEL: ${{ inputs.logLevel || 'warn' }}

jobs:
llvm-build:
runs-on: macos-11
defaults:
run:
working-directory: ./omnibus

steps:
- name: Select Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '13.2.1'

- name: Download sources
uses: actions/checkout@v4

- name: Update development environment
run: |
brew update
brew install --display-times pkgconfig libtool cmake
- name: Prepare folders
run: |
sudo mkdir -p /opt/llvm
sudo chown $(whoami) /opt/llvm/
sudo mkdir -p /var/cache
sudo chown $(whoami) /var/cache
- name: Install omnibus
run: bundle check || bundle install

- name: Build llvm
run: bundle exec omnibus build llvm --log-level ${{ env.LOG_LEVEL }} --override use_git_caching:false

# Reference: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#environment-files
- name: Extract the package name to be used for the artifact name
run: |
cd pkg
filename=$(ls -1 llvm-*.tar.gz)
echo "ARTIFACT_NAME=${filename%.tar.gz}" >> "$GITHUB_ENV"
# When an Artifact is uploaded, all the files are assembled into an immutable Zip archive.
# https://github.com/actions/upload-artifact#zip-archives
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: omnibus/pkg/*.tar.gz
retention-days: 1
if-no-files-found: error
compression-level: 0 # package is already compressed
8 changes: 7 additions & 1 deletion darwin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ The whole process is automated using a `Makefile`.
* `pkgconfig`, `libtool` (Can be installed by `$ brew install pkgconfig libtool`)
* Own `/opt/crystal`, `/var/cache`.

```
```shell
sudo mkdir -p /opt/crystal
sudo chown $(whoami) /opt/crystal/
sudo mkdir -p /var/cache
sudo chown $(whoami) /var/cache
```
* Optional: If you need to build LLVM, ensure the existence of the /opt/llvm directory.

```shell
sudo mkdir -p /opt/llvm
sudo chown $(whoami) /opt/llvm/
```

# Getting started

Expand Down
3 changes: 3 additions & 0 deletions omnibus/config/projects/llvm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ def valid_cmake_version?

dependency 'cmake' unless valid_cmake_version?
dependency 'llvm'

# Requires for tgz_package to generate a proper archive name with sufix universal.
ohai['target_arch'] = 'universal'
dependency 'tgz_package' if macos? || mac_os_x? || centos?

exclude '\.git*'
Expand Down
6 changes: 5 additions & 1 deletion omnibus/config/software/llvm_bin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
raise "llvm_bin not supported"
end

source url: "http://crystal-lang.s3.amazonaws.com/llvm/llvm-#{version}-#{ohai['os']}-#{ohai['kernel']['machine']}.tar.gz",
platform = ohai['os']
# Currently, it is considered `universal` based on the alterations made in the commit 'ed5f1f97e0a67157d886dd6675902e35199a1ab3'
arch = "x86_64"

source url: "http://crystal-lang.s3.amazonaws.com/llvm/llvm-#{version}-#{platform}-#{arch}.tar.gz",
md5: source_md5

relative_path "llvm-#{version}"
9 changes: 8 additions & 1 deletion omnibus/config/software/tgz_package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

build do
block do
platform = ohai['os']
target_arch = ohai['target_arch'] || ohai['kernel']['machine']
destination = File.expand_path('pkg', Omnibus::Config.project_root)
version = "#{project.build_version}-#{project.build_iteration}"
version.gsub!("/", "-")
tgz_name = "#{project.name}-#{version}-#{ohai['os']}-#{ohai['kernel']['machine']}.tar.gz"
tgz_name = "#{project.name}-#{version}-#{platform}-#{target_arch}.tar.gz"
if macos? || mac_os_x?
transform = "-s /./#{project.name}-#{version}/"
else
Expand All @@ -16,5 +18,10 @@

command "tar czf #{destination}/#{tgz_name} #{transform} -C #{install_dir} .",
env: {"COPYFILE_DISABLE" => "1"}

# NOTE: For environments not in English, git_cache function expected to see message
# from git `nothing to commit`, otherwise it raises the error.
# It creates a empty file to commit something.
command "date > #{install_dir}/tgz_package_done.log"
end
end

0 comments on commit 5fe41d3

Please sign in to comment.