Skip to content

Commit

Permalink
MacOS / Aarch64 support WIP
Browse files Browse the repository at this point in the history
*	Add MacOS build scripts under `scripts/`

*	Renamed Linux Build-and-test workflow

*	Added MacOS Build-and-test workflow

*	Updated lit configuration for OS and arch support

*	Updated expectedly failing tests

*	Fixed bug in `tests/lit-llvm/option_notarget.calc`

*	Update license for container files
  • Loading branch information
e3m3 committed Sep 14, 2024
1 parent 0b65a54 commit a8e8323
Show file tree
Hide file tree
Showing 26 changed files with 303 additions and 33 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/build-and-test-macos14.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2024, Giordano Salvador
# SPDX-License-Identifier: BSD-3-Clause

name: Build-and-test

on:

workflow_call:
inputs:
build_mode:
description: Build optimization level
required: true
type: string
distro:
description: OS distribution name
required: true
type: string
os_ver:
description: OS distribution version
required: true
type: string
os:
description: OS string identifier
required: true
type: string
script_type:
description: Script type ("-container" | "-native")
required: true
type: string

jobs:

build-and-test:
runs-on: macos-14
defaults:
run:
working-directory: ${{ github.workspace }}
steps:

- name: Checkout homebrew
uses: Homebrew/actions/setup-homebrew@master

- name: Checkout source
uses: actions/checkout@v4

- name: Build source and test
run: |
export BUILD_MODE=${{ inputs.build_mode }}
export DISTRO=${{ inputs.distro }}
export OS=${{ inputs.os }}
export OS_VER=${{ inputs.os_ver }}
bash -c "./scripts/build-and-test-macos14-${{ inputs.script_type }}.sh"
File renamed without changes.
2 changes: 1 addition & 1 deletion .github/workflows/fedora-40.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ on:
jobs:

run:
uses: e3m3/calcc-rust/.github/workflows/build-and-test.yaml@main
uses: e3m3/calcc-rust/.github/workflows/build-and-test-ubuntu2404.yaml@main
with:
build_mode: ${{ inputs.build_mode }}
distro: fedora
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/macos-14-container.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2024, Giordano Salvador
# SPDX-License-Identifier: BSD-3-Clause

name: MacOS 14 (Container)

on:

workflow_dispatch:
branches: [ "main" ]
inputs:
build_mode:
description: Build optimization level
required: true
default: debug
type: choice
options:
- debug
- release

jobs:

run:
uses: e3m3/calcc-rust/.github/workflows/build-and-test-macos14.yaml@main
with:
build_mode: ${{ inputs.build_mode }}
distro: fedora
os_ver: 40
os: fedora-40
script_type: container
29 changes: 29 additions & 0 deletions .github/workflows/macos-14-native.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2024, Giordano Salvador
# SPDX-License-Identifier: BSD-3-Clause

name: MacOS 14 (Native)

on:

workflow_dispatch:
branches: [ "main" ]
inputs:
build_mode:
description: Build optimization level
required: true
default: debug
type: choice
options:
- debug
- release

jobs:

run:
uses: e3m3/calcc-rust/.github/workflows/build-and-test-macos14.yaml@main
with:
build_mode: ${{ inputs.build_mode }}
distro: fedora
os_ver: 40
os: fedora-40
script_type: native
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu-2204.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ on:
jobs:

run:
uses: e3m3/calcc-rust/.github/workflows/build-and-test.yaml@main
uses: e3m3/calcc-rust/.github/workflows/build-and-test-ubuntu2404.yaml@main
with:
build_mode: ${{ inputs.build_mode }}
distro: ubuntu
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu-2404.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ on:
jobs:

run:
uses: e3m3/calcc-rust/.github/workflows/build-and-test.yaml@main
uses: e3m3/calcc-rust/.github/workflows/build-and-test-ubuntu2404.yaml@main
with:
build_mode: ${{ inputs.build_mode }}
distro: ubuntu
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Author/Maintainer: Giordano Salvador <[email protected]>
[![Ubuntu 22.04](https://github.com/e3m3/calcc-rust/actions/workflows/ubuntu-2204.yaml/badge.svg?event=workflow_dispatch)](https://github.com/e3m3/calcc-rust/actions/workflows/ubuntu-2204.yaml)
[![Ubuntu 24.04](https://github.com/e3m3/calcc-rust/actions/workflows/ubuntu-2404.yaml/badge.svg?event=workflow_dispatch)](https://github.com/e3m3/calcc-rust/actions/workflows/ubuntu-2404.yaml)
[![Fedora 40](https://github.com/e3m3/calcc-rust/actions/workflows/fedora-40.yaml/badge.svg?event=workflow_dispatch)](https://github.com/e3m3/calcc-rust/actions/workflows/fedora-40.yaml)
[![MacOS 14 (Container)](https://github.com/e3m3/calcc-rust/actions/workflows/macos-14-container.yaml/badge.svg?event=workflow_dispatch)](https://github.com/e3m3/calcc-rust/actions/workflows/macos-14-container.yaml)
[![MacOS 14 (Native)](https://github.com/e3m3/calcc-rust/actions/workflows/macos-14-native.yaml/badge.svg?event=workflow_dispatch)](https://github.com/e3m3/calcc-rust/actions/workflows/macos-14-native.yaml)

Learning [Rust][1] [[1]] by implementing the calc langauge using the [llvm-sys][2] [[2]] crate.
Implements the calc language, inspired by the [C++][3] [[3]] implementation presented by Macke and Kwan in [[4]] and [[5]].
Expand Down
3 changes: 3 additions & 0 deletions container/Containerfile.fedora40
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright 2024, Giordano Salvador
# SPDX-License-Identifier: BSD-3-Clause

FROM registry.fedoraproject.org/fedora:40

LABEL maintainer="Giordano Salvador <[email protected]>"
Expand Down
3 changes: 3 additions & 0 deletions container/Containerfile.ubuntu22
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright 2024, Giordano Salvador
# SPDX-License-Identifier: BSD-3-Clause

FROM docker.io/ubuntu:22.04

LABEL maintainer="Giordano Salvador <[email protected]>"
Expand Down
3 changes: 3 additions & 0 deletions container/Containerfile.ubuntu22-build-llvm
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright 2024, Giordano Salvador
# SPDX-License-Identifier: BSD-3-Clause

FROM docker.io/ubuntu:22.04

LABEL maintainer="Giordano Salvador <[email protected]>"
Expand Down
3 changes: 3 additions & 0 deletions container/Containerfile.ubuntu24
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright 2024, Giordano Salvador
# SPDX-License-Identifier: BSD-3-Clause

FROM docker.io/ubuntu:24.04

LABEL maintainer="Giordano Salvador <[email protected]>"
Expand Down
23 changes: 23 additions & 0 deletions scripts/build-and-test-macos14-container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
# Copyright 2024, Giordano Salvador
# SPDX-License-Identifier: BSD-3-Clause

HOMEBREW_HOME=/opt/homebrew
eval "$(${HOMEBREW_HOME}/bin/brew shellenv)"

brew install -y podman
podman

case ${BUILD_MODE}
debug) build_mode=
release) build_mode=--release
*) echo "Error: BUILD_MODE=$BUILD_MODE" >2 && exit 1
esac

podman machine init
podman machine start
podman build \
-f container/Containerfile.${DISTRO}${OS_VER} \
-t ${OS}-calcc-${build_mode} \
--build-arg=BUILD_MODE=${build_mode} \
.
42 changes: 42 additions & 0 deletions scripts/build-and-test-macos14-native.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
# Copyright 2024, Giordano Salvador
# SPDX-License-Identifier: BSD-3-Clause

HOMEBREW_HOME=/opt/homebrew
eval "$(${HOMEBREW_HOME}/bin/brew shellenv)"

LLVM_VER=18
PYTHON_VER=3.12

brew install -y python@${PYTHON_VER} llvm@${LLVM_VER} lit rustup

RUSTUP_CHANNEL=stable
RUSTUP_HOME=/root/.rustup
RUSTUP_TOOLCHAIN=${RUSTUP_CHANNEL}-aarch64-apple-darwin
PATH=${RUSTUP_HOME}/toolchains/${RUSTUP_TOOLCHAIN}/bin${PATH:+:$PATH}
LD_LIBRARY_PATH=${RUSTUP_HOME}/toolchains/${RUSTUP_TOOLCHAIN}/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}

rustup default ${RUSTUP_CHANNEL}

LLVM_HOME=${HOMEBREW_HOME}/opt/llvm@${LLVM_VER}
PATH=${LLVM_HOME}/bin${PATH:+:$PATH}
LD_LIBRARY_PATH=${LLVM_HOME}/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
C_INCLUDE_PATH=${LLVM_HOME}/include${C_INCLUDE_PATH:+:$C_INCLUDE_PATH}
CPLUS_INCLUDE_PATH=${LLVM_HOME}/include${CPLUS_INCLUDE_PATH:+:$CPLUS_INCLUDE_PATH}

PYTHON_VENV_PATH=/root/.python/venv
python3 -m venv ${PYTHON_VENV_PATH}
PATH=${PYTHON_VENV_PATH}/bin${PATH:+:$PATH}

export HOMEBREW_HOME
export LLVM_HOME
export PYTHON_VENV_PATH

case ${BUILD_MODE}
debug) build_mode=
release) build_mode=--release
*) echo "Error: BUILD_MODE=$BUILD_MODE" >2 && exit 1
esac

cargo build --verbose ${BUILD_MODE}
cargo test --verbose ${BUILD_MODE} -- --nocapture
2 changes: 2 additions & 0 deletions tests/lit-llvm/codegen_type.calc
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
// CHECK_B: Bytecode file type (missing '-S' flag) should match output name ('.bc' extension)

// CHECK_C-NOT: ^0

// XFAIL: ARCH_X86_64 && OS_LINUX
3 changes: 3 additions & 0 deletions tests/lit-llvm/end_to_end1.calc
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
// RUN: @calcc -e "with: a: 1024*32/a" -o %t4.bc && @clang -O0 -o %t4.out %t4.bc && %t4.out 8 | @filecheck %s

// CHECK: calcc_main result: 4096

// XFAIL: ARCH_AARCH64 && OS_MACOS
// XFAIL: ARCH_AARCH64 && OS_LINUX
3 changes: 3 additions & 0 deletions tests/lit-llvm/end_to_end2.calc
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@

// CHECK_E: calcc_main result: -3
// CHECK_F: calcc_main result: 0

// XFAIL: ARCH_AARCH64 && OS_MACOS
// XFAIL: ARCH_AARCH64 && OS_LINUX
3 changes: 3 additions & 0 deletions tests/lit-llvm/input_file1.calc
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@

// Implement Pythagorean theorem check (for integer triangles): 0 result => passing check
with: a,b,c: c*c - (a*a + b*b)

// XFAIL: ARCH_AARCH64 && OS_MACOS
// XFAIL: ARCH_AARCH64 && OS_LINUX
2 changes: 2 additions & 0 deletions tests/lit-llvm/irgen1.calc
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
// CHECK: %v3 = add nsw i64 %v2, 10
// CHECK: ret i64 %v3
// CHECK: }

// XFAIL: ARCH_X86_64 && OS_LINUX
2 changes: 2 additions & 0 deletions tests/lit-llvm/irgen2.calc
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
// CHECK-LABEL: entry:
// CHECK: ret i64 4096
// CHECK: }

// XFAIL: ARCH_X86_64 && OS_LINUX
20 changes: 19 additions & 1 deletion tests/lit-llvm/lit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ config.substitutions.append(("@clang", "clang"))
config.substitutions.append(("@calcc", "calcc"))
config.substitutions.append(("@count", "wc"))
config.substitutions.append(("@diff", "diff"))
config.substitutions.append(("@filecheck", "FileCheck --color"))
config.substitutions.append(("@filecheck", "FileCheck --color --vv"))
config.substitutions.append(("@head", "head"))
config.substitutions.append(("@llc", "llc"))
config.substitutions.append(("@llvm-as", "llvm-as"))
Expand All @@ -17,6 +17,24 @@ config.substitutions.append(("@llvm-opt", "opt"))
config.substitutions.append(("@tail", "tail"))
config.substitutions.append(("@tee", "tee"))

if "OS_NAME" in lit_config.params:
os_name = lit_config.params["OS_NAME"]
if os_name == "linux":
config.available_features.add("OS_LINUX")
elif os_name == "macos":
config.available_features.add("OS_MACOS")
elif os_name == "windows":
config.available_features.add("OS_WINDOWS")

if "ARCH" in lit_config.params:
arch = lit_config.params["OS_NAME"]
if arch == "x86":
config.available_features.add("ARCH_X86")
elif arch == "x86_64":
config.available_features.add("ARCH_X86_64")
elif arch == "aarch64":
config.available_features.add("ARCH_AARCH64")

config.test_format = lit.formats.ShTest(False)
config.test_source_root = os.path.dirname(__file__)

Expand Down
2 changes: 2 additions & 0 deletions tests/lit-llvm/maingen1.calc
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,5 @@
// CHECK: %v3 = add nsw i64 %v2, 10
// CHECK: ret i64 %v3
// CHECK: }

// XFAIL: ARCH_X86_64 && OS_LINUX
2 changes: 2 additions & 0 deletions tests/lit-llvm/maingen2.calc
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@
// CHECK-LABEL: entry:
// CHECK: ret i64 4096
// CHECK: }

// XFAIL: ARCH_X86_64 && OS_LINUX
6 changes: 4 additions & 2 deletions tests/lit-llvm/option_notarget.calc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// CHECK_TARGET-LABEL: ; ModuleID = 'calcc'
// CHECK_TARGET: source_filename = "calcc"
// CHECK_TARGET: target datalayout = "{{[a-zA-Z0-9\:\-]+}}"
// CHECK_TARGET: target triple = "{{[_a-zA-Z0-9\-]+}}"
// CHECK_TARGET: target triple = "{{[\.a-zA-Z0-9\-]+}}"

// CHECK_TARGET-LABEL: define i64 @calcc_main() {
// CHECK_TARGET-LABEL: entry:
Expand All @@ -14,9 +14,11 @@
// CHECK_NOTARGET-LABEL: ; ModuleID = 'calcc'
// CHECK_NOTARGET: source_filename = "calcc"
// CHECK_NOTARGET-NOT: target datalayout = "{{[a-zA-Z0-9\:\-]+}}"
// CHECK_NOTARGET-NOT: target triple = "{{[a-zA-Z0-9\-]+}}"
// CHECK_NOTARGET-NOT: target triple = "{{[\.a-zA-Z0-9\-]+}}"

// CHECK_NOTARGET-LABEL: define i64 @calcc_main() {
// CHECK_NOTARGET-LABEL: entry:
// CHECK_NOTARGET: ret i64 4096
// CHECK_NOTARGET: }

// XFAIL: ARCH_X86_64 && OS_LINUX
1 change: 1 addition & 0 deletions tests/lit-llvm/option_opt.calc
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@
// CHECK_O1: ret i64 %v[[REG]]
// CHECK_O1: }

// XFAIL: ARCH_X86_64 && OS_LINUX
Loading

0 comments on commit a8e8323

Please sign in to comment.