Skip to content

Commit

Permalink
add llvm - clangd;lldb (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
valord577 authored Dec 23, 2024
1 parent 65b48b1 commit f28c40b
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 77 deletions.
35 changes: 21 additions & 14 deletions .github/workflows/_matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ env:
GH_OSSUTIL_REGION: ${{ secrets.GH_OSSUTIL_REGION }}
GH_OSSUTIL_PKGS: ${{ secrets.GH_OSSUTIL_PKGS }}
GH_OSSUTIL_CNAME: ${{ secrets.GH_OSSUTIL_CNAME }}
INST_DIR: ${{ github.workspace }}/${{ github.workflow }}
CCACHE_DIR: ${{ github.workspace }}/.ccache

jobs:
_preset:
Expand Down Expand Up @@ -64,6 +66,10 @@ jobs:
matrix=$(cat .github/matrix.json | jq -c -M "map(. | select($jq_expr) )")
matrix=$(echo ${matrix} | jq -c -M "map(if ${host_macos} then . + {os: \"macos-14\"} else . end)")
[ "${{ github.workflow }}" == "llvm" ] && \
{ matrix=$(echo ${matrix} | jq -c -M 'map(. | select((.platform=="macosx")) )'); }
printf "\e[1m\e[33m%s\e[0m\n" "matrix: $matrix"
echo "matrix={\"include\":$(echo $matrix)}" >> "$GITHUB_OUTPUT"
- name: set matrix container
Expand Down Expand Up @@ -91,8 +97,6 @@ jobs:
shell: ${{ startsWith(matrix.os, 'windows') && 'pwsh' || 'bash' }}
working-directory: ${{ github.workspace }}
env:
INST_DIR: ${{ github.workspace }}/${{ github.workflow }}
CCACHE_DIR: ${{ github.workspace }}/.ccache
CCACHE_GHA_KEY: ${{ github.workflow }}-${{ matrix.pkg_type }}-${{ matrix.platform }}-${{ matrix.arch }}-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}
CCACHE_GHA_KEY_RESTORE: ${{ github.workflow }}-${{ matrix.pkg_type }}-${{ matrix.platform }}-${{ matrix.arch }}
PKG_ZIP_NAME: ${{ github.workflow }}_${{ matrix.platform }}_${{ matrix.arch }}_${{ needs._preset.outputs.pkgver }}_${{ matrix.pkg_type }}
Expand All @@ -116,6 +120,9 @@ jobs:
- name: buildx library - ${{ github.workflow }}
run: |
./build_${{ matrix.platform }}_${{ matrix.arch }}.sh ${{ github.workflow }} ${{ matrix.pkg_type }}
# keep file permissions and case sensitivity
tar -cvf ${{ env.PKG_ZIP_NAME }}.tar ${{ github.workflow }}
- name: gh action ccache save
uses: actions/cache/save@v4
with:
Expand All @@ -125,7 +132,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: ${{ env.PKG_ZIP_NAME }}
path: ${{ env.INST_DIR }}
path: ${{ env.PKG_ZIP_NAME }}.tar
- name: commit to pre-compiled storage
if: ${{ github.event_name == 'push' && (! inputs.disable_upload) }}
run: |
Expand All @@ -145,19 +152,16 @@ jobs:
shell: bash
working-directory: ${{ github.workspace }}
env:
INST_DIR: ${{ github.workspace }}/${{ github.workflow }}
CCACHE_DIR: ${{ github.workspace }}/.ccache
CCACHE_GHA_KEY: ${{ github.workflow }}-${{ matrix.pkg_type }}-${{ matrix.platform }}-${{ matrix.arch }}-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}
CCACHE_GHA_KEY_RESTORE: ${{ github.workflow }}-${{ matrix.pkg_type }}-${{ matrix.platform }}-${{ matrix.arch }}
PKG_ZIP_NAME: ${{ github.workflow }}_${{ matrix.platform }}_${{ matrix.arch }}_${{ needs._preset.outputs.pkgver }}_${{ matrix.pkg_type }}
steps:
- name: set required env
if: ${{ matrix.platform == 'linux' }}
run: |
CCACHE_GHA_KEY='${{ github.workflow }}-${{ matrix.pkg_type }}-${{ matrix.platform }}-${{ matrix.arch }}-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}'
CCACHE_GHA_KEY_RESTORE='${{ github.workflow }}-${{ matrix.pkg_type }}-${{ matrix.platform }}-${{ matrix.arch }}'
PKG_ZIP_NAME='${{ github.workflow }}_${{ matrix.platform }}_${{ matrix.arch }}_${{ needs._preset.outputs.pkgver }}_${{ matrix.pkg_type }}'
if [[ ${{ matrix.platform == 'linux' }} ]]; then
CCACHE_GHA_KEY='${{ github.workflow }}-${{ matrix.pkg_type }}-${{ matrix.platform }}-${{ matrix.arch }}-${{ matrix.lib_impl }}-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}'
CCACHE_GHA_KEY_RESTORE='${{ github.workflow }}-${{ matrix.pkg_type }}-${{ matrix.platform }}-${{ matrix.arch }}-${{ matrix.lib_impl }}'
PKG_ZIP_NAME='${{ github.workflow }}_${{ matrix.platform }}_${{ matrix.arch }}-${{ matrix.lib_impl }}_${{ needs._preset.outputs.pkgver }}_${{ matrix.pkg_type }}'
fi
CCACHE_GHA_KEY='${{ github.workflow }}-${{ matrix.pkg_type }}-${{ matrix.platform }}-${{ matrix.arch }}-${{ matrix.lib_impl }}-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}'
CCACHE_GHA_KEY_RESTORE='${{ github.workflow }}-${{ matrix.pkg_type }}-${{ matrix.platform }}-${{ matrix.arch }}-${{ matrix.lib_impl }}'
PKG_ZIP_NAME='${{ github.workflow }}_${{ matrix.platform }}_${{ matrix.arch }}-${{ matrix.lib_impl }}_${{ needs._preset.outputs.pkgver }}_${{ matrix.pkg_type }}'
echo "CCACHE_GHA_KEY=${CCACHE_GHA_KEY}" >> "$GITHUB_ENV"
echo "CCACHE_GHA_KEY_RESTORE=${CCACHE_GHA_KEY_RESTORE}" >> "$GITHUB_ENV"
Expand Down Expand Up @@ -189,6 +193,9 @@ jobs:
SCRIPT_NAME='crossbuild_${{ matrix.platform }}_${{ matrix.lib_impl }}_${{ matrix.arch }}.sh'
fi
./${SCRIPT_NAME} ${{ github.workflow }} ${{ matrix.pkg_type }}
# keep file permissions and case sensitivity
tar -cvf ${{ env.PKG_ZIP_NAME }}.tar ${{ github.workflow }}
- name: gh action ccache save
uses: actions/cache/save@v4
with:
Expand All @@ -198,7 +205,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: ${{ env.PKG_ZIP_NAME }}
path: ${{ env.INST_DIR }}
path: ${{ env.PKG_ZIP_NAME }}.tar
- name: commit to pre-compiled storage
if: ${{ github.event_name == 'push' && (! inputs.disable_upload) }}
run: |
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/llvm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: llvm
on:
workflow_dispatch:
push:
branches:
- main
paths:
- '.github/matrix*.json'
- '.github/workflows/_matrix.yml'
- '.github/workflows/llvm.yml'
- 'deps/llvm'
- 'patches/llvm/**'
- 'scripts/llvm.sh'
- 'build.sh'
- 'env-*.sh'
- 'pkg-conf.sh'
pull_request:
branches:
- main
paths:
- '.github/matrix*.json'
- '.github/workflows/_matrix.yml'
- '.github/workflows/llvm.yml'
- 'deps/llvm'
- 'patches/llvm/**'
- 'scripts/llvm.sh'
- 'build.sh'
- 'env-*.sh'
- 'pkg-conf.sh'

jobs:
build:
secrets: inherit
uses: ./.github/workflows/_matrix.yml
with:
allow_failure: true
disable_upload: true
8 changes: 7 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
url = https://github.com/libsdl-org/SDL.git
[submodule "deps/llvm"]
path = deps/llvm
url = https://github.com/llvm/llvm-project.git
url = http://mirrors.bfsu.edu.cn/git/llvm-project.git
[submodule "deps/zlib-ng"]
path = deps/zlib-ng
url = https://github.com/zlib-ng/zlib-ng.git
[submodule "deps/libedit"]
path = deps/libedit
url = https://salsa.debian.org/debian/libedit.git
[submodule "deps/ncurses"]
path = deps/ncurses
url = https://salsa.debian.org/debian/ncurses.git
7 changes: 7 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ $compile = {
Pop-Location
}
& "${PROJ_ROOT}\scripts\${PKG_NAME}.ps1"


if (${env:CLANGD_CODE_COMPLETION} -ne "1") {
Get-ChildItem "${env:PKG_INST_DIR}"
}
$BUILD_DATE = (Get-Date -UFormat "+%Y-%m-%dT%H:%M:%S %Z")
Write-Host -ForegroundColor Magenta "${env:SUBPROJ_SRC} - Build Done @${BUILD_DATE}"
}

if (($PKG_NAME -eq $null) -or ($PKG_NAME -eq "")) {
Expand Down
1 change: 1 addition & 0 deletions deps/libedit
Submodule libedit added at 5f25a9
2 changes: 1 addition & 1 deletion deps/llvm
Submodule llvm updated from 3b5b5c to e21dc4
1 change: 1 addition & 0 deletions deps/ncurses
Submodule ncurses added at f39aae
10 changes: 6 additions & 4 deletions env-apple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ TARGET_ARCH=${2}
case ${TARGET_PLATFORM} in
"macosx")
TARGET_FLAG="macosx"
export CMAKE_EXTRA="-D CMAKE_SYSTEM_NAME=Darwin ${CMAKE_EXTRA}"
;;
"iphoneos")
TARGET_FLAG="iphoneos"
export CMAKE_EXTRA="-D CMAKE_SYSTEM_NAME=iOS ${CMAKE_EXTRA}"
;;
"iphonesimulator")
TARGET_FLAG="ios-simulator"
export CMAKE_EXTRA="-D CMAKE_SYSTEM_NAME=iOS ${CMAKE_EXTRA}"
;;
*)
printf "\e[1m\e[31m%s\e[0m\n" "Unsupported TARGET PLATFORM: '${TARGET_PLATFORM}'."
Expand All @@ -28,6 +31,7 @@ export SYSROOT="$(xcrun --sdk ${TARGET_PLATFORM} --show-sdk-path)"
export CROSS_FLAGS="-arch ${TARGET_ARCH} -m${TARGET_FLAG}-version-min=${TARGET_DEPLOYMENT}"

export CC="clang"; export CXX="clang++"; export OBJC="clang"; export OBJCXX="clang++";
export HOSTCC="clang"; export HOSTCXX="clang++"
export PARALLEL_JOBS="$(sysctl -n hw.ncpu)"
if command -v ccache >/dev/null 2>&1 ; then
export CCACHE_SRC="$(command -v ccache)"
Expand All @@ -39,13 +43,11 @@ if command -v ccache >/dev/null 2>&1 ; then
fi

export CMAKE_EXTRA=$(cat <<- EOF
-D CMAKE_CROSSCOMPILING:BOOL=TRUE \
-D CMAKE_SYSTEM_PROCESSOR=${TARGET_ARCH} \
-D CMAKE_OSX_ARCHITECTURES=${TARGET_ARCH} \
-D CMAKE_OSX_SYSROOT=${TARGET_PLATFORM} \
-D CMAKE_OSX_DEPLOYMENT_TARGET=${TARGET_DEPLOYMENT} \
-D CMAKE_MACOSX_BUNDLE:BOOL=0 ${CMAKE_EXTRA}
EOF
)
if [ "${TARGET_PLATFORM}" == "iphoneos" ] || \
[ "${TARGET_PLATFORM}" == "iphonesimulator" ]; then
export CMAKE_EXTRA="-D CMAKE_SYSTEM_NAME=iOS ${CMAKE_EXTRA}"
fi
43 changes: 43 additions & 0 deletions patches/llvm/01_fix_cmake_cross_build.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
diff --git a/.gitignore b/.gitignore
index 20c4f52cd378..80bd660499d3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -70,3 +70,6 @@ pythonenv*
/clang/utils/analyzer/projects/*/RefScanBuildResults
# automodapi puts generated documentation files here.
/lldb/docs/python_api/
+
+/.env
+/.cache
diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
index 5d2b4b03fe60..2161fe0eaf23 100644
--- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -66,6 +66,9 @@
#define TRAP_HWBKPT 4
#endif

+#ifndef AT_HWCAP2
+#define AT_HWCAP2 26
+#endif
#ifndef HWCAP2_MTE
#define HWCAP2_MTE (1 << 18)
#endif
diff --git a/llvm/cmake/modules/CrossCompile.cmake b/llvm/cmake/modules/CrossCompile.cmake
index 55bf3be75642..1c838b1f81b7 100644
--- a/llvm/cmake/modules/CrossCompile.cmake
+++ b/llvm/cmake/modules/CrossCompile.cmake
@@ -15,10 +15,10 @@ function(llvm_create_cross_target project_name target_name toolchain buildtype)
if (EXISTS ${LLVM_MAIN_SRC_DIR}/cmake/platforms/${toolchain}.cmake)
set(CROSS_TOOLCHAIN_FLAGS_INIT
-DCMAKE_TOOLCHAIN_FILE=\"${LLVM_MAIN_SRC_DIR}/cmake/platforms/${toolchain}.cmake\")
- elseif (NOT CMAKE_CROSSCOMPILING)
+ elseif (CMAKE_CROSSCOMPILING)
set(CROSS_TOOLCHAIN_FLAGS_INIT
- -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
- -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
+ -DCMAKE_C_COMPILER=${CMAKE_C_HOST_COMPILER}
+ -DCMAKE_CXX_COMPILER=${CMAKE_CXX_HOST_COMPILER}
)
endif()
set(CROSS_TOOLCHAIN_FLAGS_${target_name} ${CROSS_TOOLCHAIN_FLAGS_INIT}
49 changes: 21 additions & 28 deletions scripts/llvm.ps1
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
# ----------------------------
# prepare env
# ----------------------------
# if (-not (Test-Path -PathType Container -Path "${env:SUBPROJ_SRC}\.env")) {
# Push-Location "${env:SUBPROJ_SRC}"
# python -m venv .env

# .\.env\Scripts\python -m pip install ${env:PYPI_MIRROR} --upgrade pip
# .\.env\Scripts\python -m pip install ${env:PYPI_MIRROR} ninja
# Pop-Location
# if (-not (Test-Path -PathType Container -Path "${env:PROJ_ROOT}\.env")) {
# Push-Location "${env:PROJ_ROOT}"; python -m venv .env; Pop-Location
# }
# & ${env:SUBPROJ_SRC}\.env\Scripts\activate.ps1
# & ${env:PROJ_ROOT}\.env\Scripts\activate.ps1
# python -m pip install ${env:PYPI_MIRROR} --upgrade pip
# python -m pip install ${env:PYPI_MIRROR} --upgrade ninja
# ----------------------------
# static or shared
# ----------------------------
Expand Down Expand Up @@ -44,6 +39,7 @@ if ($LIB_RELEASE -ieq "1") {
"@
$PKG_INST_STRIP = "--strip"
} else {
<#
$PKG_BULD_TYPE = @"
``
-D CMAKE_BUILD_TYPE=Debug ``
Expand All @@ -53,6 +49,9 @@ if ($LIB_RELEASE -ieq "1") {
-D CMAKE_MODULE_LINKER_FLAGS_DEBUG="/debug /INCREMENTAL:NO"
"@
$PKG_INST_STRIP = ""
#>
Write-Host -ForegroundColor Red "Unsupported LIB_RELEASE: '${LIB_RELEASE}'."
exit 1
}
# ----------------------------
# compile :p
Expand All @@ -63,17 +62,6 @@ New-Item -ItemType Directory -Path "${env:PKG_INST_DIR}" *> $null
Remove-Item "${env:PKG_BULD_DIR}" -Recurse -Force -ErrorAction SilentlyContinue
New-Item -ItemType Directory -Path "${env:PKG_BULD_DIR}" *> $null

switch ($env:PKG_ARCH) {
'amd64' {
$LLVM_TARGET = "X86"
break
}
default {
Write-Host -ForegroundColor Red "Invalid PKG_ARCH: '${PKG_ARCH}'."
exit 1
}
}

${env:CFLAGS} = "/utf-8"
${env:CXXFLAGS} = "/utf-8"

Expand All @@ -95,16 +83,21 @@ cmake -G Ninja ``
-D LLVM_INCLUDE_TESTS:BOOL=0 ``
-D LLVM_INCLUDE_DOCS:BOOL=0 ``
-D LLVM_INCLUDE_UTILS:BOOL=0 ``
-D LLVM_TARGETS_TO_BUILD="${LLVM_TARGET}" ``
-D LLVM_TARGETS_TO_BUILD="AArch64;ARM;RISCV;WebAssembly;X86" ``
-D LLDB_USE_SYSTEM_DEBUGSERVER:BOOL=1
"@
Write-Host -ForegroundColor Cyan "${CMAKE_COMMAND}"
Invoke-Expression -Command "${CMAKE_COMMAND}"

# build & install
cmake --build "${env:PKG_BULD_DIR}"
cmake --install "${env:PKG_BULD_DIR}" ${PKG_INST_STRIP}

Get-ChildItem "${env:PKG_INST_DIR}"
$BUILD_DATE = (Get-Date -UFormat "+%Y-%m-%dT%H:%M:%S %Z")
Write-Host -ForegroundColor Magenta "${env:SUBPROJ_SRC} - Build Done @${BUILD_DATE}"
cmake --build "${env:PKG_BULD_DIR}" -j ${env:PARALLEL_JOBS} `
--target 'clangd;lldb;lldb-dap;lldb-server;lldb-instr;llvm-symbolizer'
cmake --install "${env:PKG_BULD_DIR}\tools" ${PKG_INST_STRIP} --component llvm-symbolizer
cmake --install "${env:PKG_BULD_DIR}\tools\lldb\tools" ${PKG_INST_STRIP} --component lldb
cmake --install "${env:PKG_BULD_DIR}\tools\lldb\tools" ${PKG_INST_STRIP} --component lldb-argdumper
cmake --install "${env:PKG_BULD_DIR}\tools\lldb\tools" ${PKG_INST_STRIP} --component lldb-dap
cmake --install "${env:PKG_BULD_DIR}\tools\lldb\tools" ${PKG_INST_STRIP} --component lldb-instr
cmake --install "${env:PKG_BULD_DIR}\tools\lldb\tools" ${PKG_INST_STRIP} --component lldb-server
cmake --install "${env:PKG_BULD_DIR}\tools\lldb" ${PKG_INST_STRIP} --component liblldb
cmake --install "${env:PKG_BULD_DIR}\tools\clang" ${PKG_INST_STRIP} --component clangd
cmake --install "${env:PKG_BULD_DIR}\tools\clang" ${PKG_INST_STRIP} --component clang-resource-headers
Loading

0 comments on commit f28c40b

Please sign in to comment.