Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions .github/actions/build-softfloat-msvc/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Part of the EDG Compiler Project, under the Apache License v2.0 with LLVM
# Exceptions.
# See https://edgcpp.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# Build SoftFloat (at the commit pinned in
# dev_tools/docker/softfloat/SOFTFLOAT_COMMIT) with MSVC, leaving the headers
# in softfloat/include and the library in softfloat/lib/softfloat.lib under
# the workspace. A cached build is reused when one is available. The MSVC
# developer environment must already be set up (e.g., with
# ilammy/msvc-dev-cmd).

name: Build SoftFloat (MSVC)
description: Build (or restore from the cache) SoftFloat with MSVC.

runs:
using: composite
steps:
- name: Read SoftFloat commit pin
id: softfloat-pin
shell: bash
run: |
echo "commit=$(tr -d '[:space:]' < dev_tools/docker/softfloat/SOFTFLOAT_COMMIT)" \
>> "${GITHUB_OUTPUT}"

- name: Cache SoftFloat
id: cache-softfloat
uses: actions/cache@v6
with:
path: softfloat
key: softfloat-msvc-win-${{ steps.softfloat-pin.outputs.commit }}

- name: Build SoftFloat (MSVC)
if: steps.cache-softfloat.outputs.cache-hit != 'true'
shell: bash
run: |
set -euo pipefail
commit="${{ steps.softfloat-pin.outputs.commit }}"
mkdir softfloat-src
git -C softfloat-src init
git -C softfloat-src remote add origin \
https://github.com/ucb-bar/berkeley-softfloat-3.git
git -C softfloat-src fetch --depth 1 origin "${commit}"
git -C softfloat-src checkout FETCH_HEAD

# EDG Windows SoftFloat build: cl + lib (not MinGW). Emit MSVC
# platform bits inline; derive sources.rsp from upstream's
# Win32-SSE2-MinGW Makefile (8086-SSE / non-FAST_INT64).
build_dir=softfloat-src/build/Win-MSVC
mkdir -p "${build_dir}"

cat > "${build_dir}/platform.h" <<'EOF'
/*============================================================================
MSVC platform header for SoftFloat. Keep free of GCC-only opts
(opts-GCC.h, SOFTFLOAT_BUILTIN_CLZ, SOFTFLOAT_INTRINSIC_INT128).
=============================================================================*/

#define LITTLEENDIAN 1

#ifdef _MSC_VER
#define INLINE static __inline
#else
#define INLINE static inline
#endif
EOF

# Strip the leading spaces YAML left in the heredoc body.
sed -i 's/^ //' "${build_dir}/platform.h"

cat > "${build_dir}/build.bat" <<'EOF'
REM In place of a Makefile, use this batch file to create softfloat.lib
REM Source paths live in sources.rsp to avoid CreateProcess length limits.

set LIB=softfloat.lib
set SOFTFLOAT_OPTS=-DSOFTFLOAT_ROUND_ODD -DINLINE_LEVEL=5 -DSOFTFLOAT_FAST_DIV32TO16 -DSOFTFLOAT_FAST_DIV64TO32
set SPECIALIZE_TYPE=8086-SSE
set SOURCE=..\..\source
set S=%SOURCE%\
set P=%SOURCE%\%SPECIALIZE_TYPE%\

del *.obj %LIB% 2>nul
cl -nologo -c -O2 -I. -I%S% -I%P% -I%S%include %SOFTFLOAT_OPTS% @sources.rsp
if errorlevel 1 exit /b 1
lib -nologo /out:%LIB% *.obj
if errorlevel 1 exit /b 1
EOF
sed -i 's/^ //' "${build_dir}/build.bat"

python - <<'PY'
import re
from pathlib import Path

makefile = Path(
'softfloat-src/build/Win32-SSE2-MinGW/Makefile'
).read_text()

def section(name):
match = re.search(
rf'{name}\s*=\s*((?:.*\\\n)*.*)', makefile
)
return re.findall(r'(\w+)\$\(OBJ\)', match.group(1))

paths = (
[fr'..\..\source\{n}.c' for n in section('OBJS_PRIMITIVES')]
+ [
fr'..\..\source\8086-SSE\{n}.c'
for n in section('OBJS_SPECIALIZE')
]
+ [fr'..\..\source\{n}.c' for n in section('OBJS_OTHERS')]
)
Path('softfloat-src/build/Win-MSVC/sources.rsp').write_text(
'\r\n'.join(paths) + '\r\n'
)
PY

cmd.exe //C "cd softfloat-src\\build\\Win-MSVC && build.bat"

mkdir -p softfloat/include softfloat/lib
cp softfloat-src/source/include/softfloat.h \
softfloat-src/source/include/softfloat_types.h \
softfloat/include/
cp softfloat-src/build/Win-MSVC/softfloat.lib softfloat/lib/
94 changes: 94 additions & 0 deletions .github/workflows/self-compile-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Part of the EDG Compiler Project, under the Apache License v2.0 with LLVM
# Exceptions.
# See https://edgcpp.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# Check that the front end can still be built from the C that its
# C-generating back end produces for the front end's own sources, which is how
# C++ code is built for a system that has only a C compiler. Each job builds
# cpfe with the host C++ compiler, uses it to translate the front end to C,
# builds cpfe-self from that C with the host C compiler, and then checks that
# cpfe-self translates the front end to the same C as cpfe (see
# src/cmake/cpfe-self/CMakeLists.txt).

name: Self-Compile CI

on:
push:
branches:
- main
pull_request:

jobs:
linux:
name: Linux ${{ matrix.name }}
runs-on: ubuntu-latest
timeout-minutes: 120
strategy:
fail-fast: false
matrix:
include:
- name: GCC x64
preset: linux-gcc-debug
build-dir: build/gcc
base: gcc
- name: GCC x32
preset: linux-i686-gcc-debug
build-dir: build/gcc-i686
base: gcc-i686
- name: Clang x64
preset: linux-clang-debug
build-dir: build/clang
base: clang
container:
image: docker.io/edgcpp/ci-runner:latest
defaults:
run:
shell: edg-container-exec "bash -eo pipefail {0}"
env:
EDG_BASE: ${{ github.workspace }}/bases/docker/dev-env/${{ matrix.base }}

steps:
- name: Check out repository
uses: actions/checkout@v7

- name: Configure ${{ matrix.preset }}
run: cmake --preset ${{ matrix.preset }} -DEDG_SELF_COMPILE=ON

- name: Build cpfe-self
run: cmake --build ${{ matrix.build-dir }} --target cpfe-self

- name: Check cpfe-self
run: cmake --build ${{ matrix.build-dir }} --target cpfe-self-check

windows-msvc:
name: Windows MSVC x64
runs-on: windows-latest
timeout-minutes: 120
env:
EDG_SOFTFLOAT_INCLUDE_PATH: ${{ github.workspace }}/softfloat/include
EDG_SOFTFLOAT_LIB_PATH: ${{ github.workspace }}/softfloat/lib/softfloat.lib

steps:
- name: Check out repository
uses: actions/checkout@v7

- name: Install Ninja
run: choco install ninja -y

- name: Set up MSVC developer environment
uses: ilammy/msvc-dev-cmd@v1

- name: Build SoftFloat
uses: ./.github/actions/build-softfloat-msvc

# The debug macro configuration does not use Microsoft bit-field
# allocation, so its layouts do not match the code that MSVC generates.
- name: Configure windows-msvc-release
run: cmake --preset windows-msvc-release -DEDG_SELF_COMPILE=ON

- name: Build cpfe-self
run: cmake --build build/msvc-release --target cpfe-self

- name: Check cpfe-self
run: cmake --build build/msvc-release --target cpfe-self-check
106 changes: 2 additions & 104 deletions .github/workflows/strict-build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,113 +26,11 @@ jobs:
- name: Install Ninja
run: choco install ninja -y

- name: Read SoftFloat commit pin
id: softfloat-pin
shell: bash
run: |
echo "commit=$(tr -d '[:space:]' < dev_tools/docker/softfloat/SOFTFLOAT_COMMIT)" \
>> "${GITHUB_OUTPUT}"

- name: Cache SoftFloat
id: cache-softfloat
uses: actions/cache@v6
with:
path: softfloat
key: softfloat-msvc-win-${{ steps.softfloat-pin.outputs.commit }}

- name: Set up MSVC developer environment
uses: ilammy/msvc-dev-cmd@v1

- name: Build SoftFloat (MSVC)
if: steps.cache-softfloat.outputs.cache-hit != 'true'
shell: bash
run: |
set -euo pipefail
commit="${{ steps.softfloat-pin.outputs.commit }}"
mkdir softfloat-src
git -C softfloat-src init
git -C softfloat-src remote add origin \
https://github.com/ucb-bar/berkeley-softfloat-3.git
git -C softfloat-src fetch --depth 1 origin "${commit}"
git -C softfloat-src checkout FETCH_HEAD

# EDG Windows SoftFloat build: cl + lib (not MinGW). Emit MSVC
# platform bits inline; derive sources.rsp from upstream's
# Win32-SSE2-MinGW Makefile (8086-SSE / non-FAST_INT64).
build_dir=softfloat-src/build/Win-MSVC
mkdir -p "${build_dir}"

cat > "${build_dir}/platform.h" <<'EOF'
/*============================================================================
MSVC platform header for SoftFloat. Keep free of GCC-only opts
(opts-GCC.h, SOFTFLOAT_BUILTIN_CLZ, SOFTFLOAT_INTRINSIC_INT128).
=============================================================================*/

#define LITTLEENDIAN 1

#ifdef _MSC_VER
#define INLINE static __inline
#else
#define INLINE static inline
#endif
EOF

# Strip the leading spaces YAML left in the heredoc body.
sed -i 's/^ //' "${build_dir}/platform.h"

cat > "${build_dir}/build.bat" <<'EOF'
REM In place of a Makefile, use this batch file to create softfloat.lib
REM Source paths live in sources.rsp to avoid CreateProcess length limits.

set LIB=softfloat.lib
set SOFTFLOAT_OPTS=-DSOFTFLOAT_ROUND_ODD -DINLINE_LEVEL=5 -DSOFTFLOAT_FAST_DIV32TO16 -DSOFTFLOAT_FAST_DIV64TO32
set SPECIALIZE_TYPE=8086-SSE
set SOURCE=..\..\source
set S=%SOURCE%\
set P=%SOURCE%\%SPECIALIZE_TYPE%\

del *.obj %LIB% 2>nul
cl -nologo -c -O2 -I. -I%S% -I%P% -I%S%include %SOFTFLOAT_OPTS% @sources.rsp
if errorlevel 1 exit /b 1
lib -nologo /out:%LIB% *.obj
if errorlevel 1 exit /b 1
EOF
sed -i 's/^ //' "${build_dir}/build.bat"

python - <<'PY'
import re
from pathlib import Path

makefile = Path(
'softfloat-src/build/Win32-SSE2-MinGW/Makefile'
).read_text()

def section(name):
match = re.search(
rf'{name}\s*=\s*((?:.*\\\n)*.*)', makefile
)
return re.findall(r'(\w+)\$\(OBJ\)', match.group(1))

paths = (
[fr'..\..\source\{n}.c' for n in section('OBJS_PRIMITIVES')]
+ [
fr'..\..\source\8086-SSE\{n}.c'
for n in section('OBJS_SPECIALIZE')
]
+ [fr'..\..\source\{n}.c' for n in section('OBJS_OTHERS')]
)
Path('softfloat-src/build/Win-MSVC/sources.rsp').write_text(
'\r\n'.join(paths) + '\r\n'
)
PY

cmd.exe //C "cd softfloat-src\\build\\Win-MSVC && build.bat"

mkdir -p softfloat/include softfloat/lib
cp softfloat-src/source/include/softfloat.h \
softfloat-src/source/include/softfloat_types.h \
softfloat/include/
cp softfloat-src/build/Win-MSVC/softfloat.lib softfloat/lib/
- name: Build SoftFloat
uses: ./.github/actions/build-softfloat-msvc

- name: Configure windows-msvc-release
env:
Expand Down
25 changes: 25 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,28 @@ print:
simply enter that directory and run the `ninja` build tool (or your specified
build tool if you chose to use an alternative build generator).

## Building the Front End from Generated C

The C-generating back end allows C++ code to be built for systems that have
only a C compiler, and the front end itself can be built that way. Configuring
with `-DEDG_SELF_COMPILE=ON` adds two targets:

- `cpfe-self`: `cpfe` translates the front end's sources to C, and the C
compiler builds that C into `cpfe-self`.
- `cpfe-self-check`: `cpfe-self` translates the same sources, and the result is
compared with the C generated by `cpfe` (ignoring the differences that are
expected between any two runs; see `dev_tools/bin/edg-compare-gen-c`).

For example:

```
cmake --preset 'linux-gcc-debug' -DEDG_SELF_COMPILE=ON
cmake --build build/gcc --target cpfe-self-check
```

This is supported with GCC, Clang, and MSVC and a single-configuration build
generator such as ninja. With MSVC, use a release preset: the debug
configurations do not use Microsoft bit-field allocation, so the front end
would not lay out structs as MSVC does. The "Self-Compile CI" GitHub workflow
runs these targets with GCC (x64 and x32) and Clang on Linux and with MSVC
(x64) on Windows.
Loading
Loading