Skip to content

Commit

Permalink
feat: github actions for building (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
zaucy authored Aug 10, 2024
1 parent 05325ec commit d838ab7
Show file tree
Hide file tree
Showing 8 changed files with 295 additions and 156 deletions.
3 changes: 3 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
UseTab: Always
IndentWidth: 4
TabWidth: 4
22 changes: 15 additions & 7 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
indent_style = tab
indent_size = 4
root = true

[*]
end_of_line = lf
insert_final_newline = true
indent_style = tab
indent_size = 4

[*.{sh,cmd}]
indent_size = 4
indent_style = space

[*.{yml,yaml}]
indent_size = 2
indent_style = space
87 changes: 87 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: main

on:
pull_request:

env:
# libcxx version to match whats already installed
# https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md
LLVM_VERSION: '18.1.3'

jobs:
typos-check:
name: Typos Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: crate-ci/typos@cfe759ac8dd421e203cc293a373396fbc6fe0d4b # v1.22.7

build-script-windows:
name: 'build.cmd'
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- run: .\build.cmd
- uses: actions/upload-artifact@v4
with:
name: cpp2b.exe
path: dist/debug/cpp2b.exe
if-no-files-found: error
retention-days: 0

build-self-windows:
name: 'build self (windows)'
needs: build-script-windows
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: 'cpp2b.exe'
- run: .\cpp2b.exe build
- run: Copy-Item .\.cache\cpp2\bin\cpp2b.exe -Destination .\cpp2b-self.exe
- run: .\cpp2b-self.exe build

build-script-linux:
name: 'build.sh'
runs-on: ubuntu-24.04
steps:
- run: sudo apt-get install libclang-dev ninja-build -y
- uses: actions/cache@v4
id: libcxx_with_modules
with:
path: /tmp/llvm-project/build
key: 'libcxx-${{ env.LLVM_VERSION }}'
- name: compiling libcxx ${{ env.LLVM_VERSION }} with modules
if: steps.libcxx_with_modules.outputs.cache-hit != 'true'
run: |
git clone --depth 1 --branch llvmorg-${{ env.LLVM_VERSION }} https://github.com/llvm/llvm-project.git /tmp/llvm-project
cd /tmp/llvm-project
mkdir build
CC=clang-18 CXX=clang++-18 cmake -G Ninja -S runtimes -B build -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind"
ninja -C build
- uses: actions/checkout@v4
- run: CPP2B_LIBCXX_BUILD_ROOT=/tmp/llvm-project/build CC=clang-18 ./build.sh
- uses: actions/upload-artifact@v4
with:
name: cpp2b
path: dist/debug/cpp2b
if-no-files-found: error
retention-days: 0

build-self-linux:
name: 'build self (linux)'
needs: build-script-linux
runs-on: ubuntu-24.04
steps:
- uses: actions/cache/restore@v4
with:
path: /tmp/llvm-project/build
key: 'libcxx-${{ env.LLVM_VERSION }}'
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: cpp2b
- run: chmod +x cpp2b
- run: CPP2B_LIBCXX_BUILD_ROOT=/tmp/llvm-project/build ./cpp2b build
- run: CPP2B_LIBCXX_BUILD_ROOT=/tmp/llvm-project/build ./.cache/cpp2/bin/cpp2b build
82 changes: 41 additions & 41 deletions build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,40 @@ if not exist dist\debug ( mkdir dist\debug )
set vswhere="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"

for /f "usebackq tokens=*" %%i in (`%vswhere% -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do (
set vs_install_dir=%%i
set vs_install_dir=%%i
)

if exist "%vs_install_dir%\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt" (
set /p vs_tools_version=<"%vs_install_dir%\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt"
set /p vs_tools_version=<"%vs_install_dir%\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt"
)

if "%vs_tools_version%"=="" (
echo ERROR: cannot find VC tools installed on your system
exit 1
echo ERROR: cannot find VC tools installed on your system
exit 1
)

set vs_tools_dir=%vs_install_dir%\VC\Tools\MSVC\%vs_tools_version%

if exist .cache\repos\cppfront\ (
@rem TODO - report which cppfront version is being used
@rem TODO - report which cppfront version is being used
) else (
git clone https://github.com/hsutter/cppfront.git .cache/repos/cppfront --quiet
git clone https://github.com/hsutter/cppfront.git .cache/repos/cppfront --quiet
)

call "%vs_install_dir%\Common7\Tools\vsdevcmd.bat" /no_logo

if not exist "%modules_dir%\std.ifc" (
echo Compiling std module...
pushd %modules_dir%
cl /D"_CRT_SECURE_NO_WARNINGS=1" /std:c++latest /EHsc /nologo /W4 /MDd /c "%vs_tools_dir%\modules\std.ixx"
popd
echo Compiling std module...
pushd %modules_dir%
cl /D"_CRT_SECURE_NO_WARNINGS=1" /std:c++latest /EHsc /nologo /W4 /MDd /c "%vs_tools_dir%\modules\std.ixx"
popd
)

if not exist "%modules_dir%\std.compat.ifc" (
echo Compiling std.compat module...
pushd %modules_dir%
cl /std:c++latest /EHsc /nologo /W4 /MDd /c "%vs_tools_dir%\modules\std.compat.ixx"
popd
echo Compiling std.compat module...
pushd %modules_dir%
cl /std:c++latest /EHsc /nologo /W4 /MDd /c "%vs_tools_dir%\modules\std.compat.ixx"
popd
)

if not exist "%root_dir%.cache\cpp2\source\_build" ( mkdir "%root_dir%.cache\cpp2\source\_build" )
Expand All @@ -72,37 +72,37 @@ endlocal

pushd %modules_dir%
cl /nologo ^
/std:c++latest /W4 /MDd /EHsc ^
/reference "%modules_dir%\std.ifc" ^
/reference "%modules_dir%\std.compat.ifc" ^
/c "%root_dir%.cache\cpp2\source\_build\cpp2b.ixx" > NUL
/std:c++latest /W4 /MDd /EHsc ^
/reference "%modules_dir%\std.ifc" ^
/reference "%modules_dir%\std.compat.ifc" ^
/c "%root_dir%.cache\cpp2\source\_build\cpp2b.ixx" > NUL
popd

if %ERRORLEVEL% neq 0 (
echo ERROR: failed to compile cpp2b module
exit %ERRORLEVEL%
echo ERROR: failed to compile cpp2b module
exit %ERRORLEVEL%
)

echo INFO: compiling dylib module...
pushd %modules_dir%
cl /nologo ^
/std:c++latest /W4 /MDd /EHsc ^
/reference "%modules_dir%\std.ifc" ^
/reference "%modules_dir%\std.compat.ifc" ^
/c /interface /TP "%root_dir%src\dylib.cppm" > NUL
/std:c++latest /W4 /MDd /EHsc ^
/reference "%modules_dir%\std.ifc" ^
/reference "%modules_dir%\std.compat.ifc" ^
/c /interface /TP "%root_dir%src\dylib.cppm" > NUL
popd

if %ERRORLEVEL% neq 0 (
echo ERROR: failed to compile dylib module
exit %ERRORLEVEL%
echo ERROR: failed to compile dylib module
exit %ERRORLEVEL%
)

if not exist %cppfront% (
pushd .cache\repos\cppfront\source
echo INFO: compiling cppfront...
cl /nologo /std:c++latest /EHsc cppfront.cpp
xcopy cppfront.exe %tools_dir% /Y /Q
popd
pushd .cache\repos\cppfront\source
echo INFO: compiling cppfront...
cl /nologo /std:c++latest /EHsc cppfront.cpp
xcopy cppfront.exe %tools_dir% /Y /Q
popd
)

if not exist "%root_dir%.cache/cpp2/source/src" ( mkdir "%root_dir%.cache/cpp2/source/src" )
Expand All @@ -113,16 +113,16 @@ if %ERRORLEVEL% neq 0 exit %ERRORLEVEL%


cl /nologo "%root_dir%.cache/cpp2/source/src/main.cpp" ^
/diagnostics:column /permissive- ^
/reference "%modules_dir%\std.ifc" "%modules_dir%\std.obj" ^
/reference "%modules_dir%\std.compat.ifc" "%modules_dir%\std.compat.obj" ^
/reference "%modules_dir%\dylib.ifc" "%modules_dir%\dylib.obj" ^
/reference "%modules_dir%\cpp2b.ifc" "%modules_dir%\cpp2b.obj" ^
/std:c++latest /W4 /MDd /EHsc ^
/DEBUG:FULL /Zi /FC ^
-I"%cppfront_include_dir%" ^
/Fe"%cpp2b_dist%" ^
/Fd"%cpp2b_dist%.pdb"
/diagnostics:column /permissive- ^
/reference "%modules_dir%\std.ifc" "%modules_dir%\std.obj" ^
/reference "%modules_dir%\std.compat.ifc" "%modules_dir%\std.compat.obj" ^
/reference "%modules_dir%\dylib.ifc" "%modules_dir%\dylib.obj" ^
/reference "%modules_dir%\cpp2b.ifc" "%modules_dir%\cpp2b.obj" ^
/std:c++latest /W4 /MDd /EHsc ^
/DEBUG:FULL /Zi /FC ^
-I"%cppfront_include_dir%" ^
/Fe"%cpp2b_dist%" ^
/Fd"%cpp2b_dist%.pdb"

if %ERRORLEVEL% neq 0 exit %ERRORLEVEL%

Expand Down
Loading

0 comments on commit d838ab7

Please sign in to comment.