Skip to content

Commit 56075ed

Browse files
committed
Add CI/CD workflows for releases and playground deployment
- Add build-clang.yml: Builds Linux and macOS binaries on version tags - Update build-playground.yml: Builds WASM with EXIT_RUNTIME=0 and ALLOW_MEMORY_GROWTH flags to enable multiple callMain() invocations (fixes signal handler issue) - Playground deploys automatically on push to null-safe-c-dev - Binaries only released when explicitly tagged (v* for binaries, playground-v* for WASM)
1 parent 16c0ba9 commit 56075ed

File tree

4 files changed

+204
-125
lines changed

4 files changed

+204
-125
lines changed

.github/workflows/build-clang.yml

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
name: Build Null-Safe Clang Binaries
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
workflow_dispatch:
8+
9+
jobs:
10+
build-linux:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Install dependencies
18+
run: |
19+
sudo apt-get update
20+
sudo apt-get install -y ninja-build cmake build-essential
21+
22+
- name: Configure build
23+
run: |
24+
mkdir -p build
25+
cd build
26+
cmake -G Ninja \
27+
-DCMAKE_BUILD_TYPE=Release \
28+
-DLLVM_ENABLE_PROJECTS="clang" \
29+
-DLLVM_TARGETS_TO_BUILD="X86" \
30+
-DLLVM_ENABLE_ASSERTIONS=OFF \
31+
-DCMAKE_INSTALL_PREFIX=../install \
32+
../llvm
33+
34+
- name: Build Clang
35+
run: |
36+
cd build
37+
ninja clang
38+
39+
- name: Install Clang
40+
run: |
41+
cd build
42+
ninja install-clang
43+
ninja install-clang-headers
44+
45+
- name: Package binaries
46+
run: |
47+
cd install
48+
tar -czf clang-nullsafe-linux-x86_64.tar.gz bin/ lib/clang/
49+
50+
- name: Upload artifact
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: clang-nullsafe-linux-x86_64
54+
path: install/clang-nullsafe-linux-x86_64.tar.gz
55+
56+
- name: Create Release
57+
uses: softprops/action-gh-release@v1
58+
with:
59+
files: install/clang-nullsafe-linux-x86_64.tar.gz
60+
body: |
61+
## Null-Safe Clang Binary Release
62+
63+
This release contains the Null-Safe Clang compiler for Linux x86_64.
64+
65+
### Installation:
66+
```bash
67+
tar -xzf clang-nullsafe-linux-x86_64.tar.gz
68+
export PATH=$PWD/bin:$PATH
69+
clang --version
70+
```
71+
72+
### Usage:
73+
```bash
74+
# Compile with null-safety warnings (default)
75+
clang mycode.c
76+
77+
# Promote warnings to errors
78+
clang -Werror=nullability mycode.c
79+
80+
# Disable null-safety checking
81+
clang -fno-strict-nullability mycode.c
82+
```
83+
84+
See the [README](https://github.com/cs01/llvm-project/blob/null-safe-c-dev/README.md) for full documentation.
85+
env:
86+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
87+
88+
build-macos:
89+
runs-on: macos-latest
90+
91+
steps:
92+
- name: Checkout code
93+
uses: actions/checkout@v4
94+
95+
- name: Install dependencies
96+
run: |
97+
brew install ninja cmake
98+
99+
- name: Configure build
100+
run: |
101+
mkdir -p build
102+
cd build
103+
cmake -G Ninja \
104+
-DCMAKE_BUILD_TYPE=Release \
105+
-DLLVM_ENABLE_PROJECTS="clang" \
106+
-DLLVM_TARGETS_TO_BUILD="AArch64;X86" \
107+
-DLLVM_ENABLE_ASSERTIONS=OFF \
108+
-DCMAKE_INSTALL_PREFIX=../install \
109+
../llvm
110+
111+
- name: Build Clang
112+
run: |
113+
cd build
114+
ninja clang
115+
116+
- name: Install Clang
117+
run: |
118+
cd build
119+
ninja install-clang
120+
ninja install-clang-headers
121+
122+
- name: Package binaries
123+
run: |
124+
cd install
125+
tar -czf clang-nullsafe-macos-universal.tar.gz bin/ lib/clang/
126+
127+
- name: Upload artifact
128+
uses: actions/upload-artifact@v4
129+
with:
130+
name: clang-nullsafe-macos-universal
131+
path: install/clang-nullsafe-macos-universal.tar.gz
132+
133+
- name: Create Release
134+
uses: softprops/action-gh-release@v1
135+
with:
136+
files: install/clang-nullsafe-macos-universal.tar.gz
137+
body: |
138+
## Null-Safe Clang Binary Release (macOS)
139+
140+
This release contains the Null-Safe Clang compiler for macOS (Intel and Apple Silicon).
141+
142+
### Installation:
143+
```bash
144+
tar -xzf clang-nullsafe-macos-universal.tar.gz
145+
export PATH=$PWD/bin:$PATH
146+
clang --version
147+
```
148+
149+
See the [README](https://github.com/cs01/llvm-project/blob/null-safe-c-dev/README.md) for usage instructions.
150+
env:
151+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/build-playground.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
-DLLVM_ENABLE_TERMINFO=OFF \
4545
-DLLVM_ENABLE_ZLIB=OFF \
4646
-DLLVM_ENABLE_LIBXML2=OFF \
47-
-DCMAKE_EXE_LINKER_FLAGS="-sEXPORTED_RUNTIME_METHODS=callMain" \
47+
-DCMAKE_EXE_LINKER_FLAGS="-sEXPORTED_RUNTIME_METHODS=callMain -sEXIT_RUNTIME=0 -sALLOW_MEMORY_GROWTH=1" \
4848
../llvm
4949
5050
- name: Build Null-Safe Clang WASM

CONTRIBUTING.md

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,50 @@
1-
# Contributing to LLVM
1+
# Contributing to Null-Safe Clang
22

3-
Thank you for your interest in contributing to LLVM! There are many ways to
4-
contribute, and we appreciate all contributions.
3+
Development branch: `null-safe-c-dev`
54

6-
To get started with contributing, please take a look at the
7-
[Contributing to LLVM](https://llvm.org/docs/Contributing.html) guide. It
8-
describes how to get involved, raise issues and submit patches.
5+
## Building
96

10-
## Getting in touch
7+
### Standard (x86)
8+
```bash
9+
mkdir build && cd build
10+
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang" ../llvm
11+
ninja clang clangd
12+
```
1113

12-
Join the [LLVM Discourse forums](https://discourse.llvm.org/) or [Discord
13-
chat](https://discord.gg/xS7Z362).
14+
### WASM (playground)
15+
```bash
16+
# Clone and setup Emscripten (first time only)
17+
git clone https://github.com/emscripten-core/emsdk.git
18+
cd emsdk
19+
./emsdk install latest
20+
./emsdk activate latest
21+
source ./emsdk_env.sh
22+
cd ..
1423

15-
The LLVM project has adopted a [code of conduct](https://llvm.org/docs/CodeOfConduct.html) for
16-
participants to all modes of communication within the project.
24+
# Build WASM
25+
mkdir build-wasm && cd build-wasm
26+
export PATH="/path/to/emsdk/upstream/emscripten:$PATH"
27+
emcmake cmake -G Ninja -DCMAKE_BUILD_TYPE=Release \
28+
-DLLVM_ENABLE_PROJECTS="clang" -DLLVM_TARGETS_TO_BUILD="WebAssembly" \
29+
-DLLVM_ENABLE_THREADS=OFF \
30+
-DCMAKE_EXE_LINKER_FLAGS="-sEXPORTED_RUNTIME_METHODS=callMain -sEXIT_RUNTIME=0 -sALLOW_MEMORY_GROWTH=1" \
31+
../llvm
32+
ninja clang
33+
34+
# Output: bin/clang.wasm and bin/clang.js
35+
```
36+
37+
## Testing
38+
```bash
39+
build/bin/llvm-lit -v clang/test/Sema/strict-nullability.c
40+
```
41+
42+
## Releases
43+
44+
**Playground:** Push to `null-safe-c-dev` → deploys GitHub Pages automatically.
45+
46+
**WASM files:** `git tag playground-v1.0 && git push origin playground-v1.0`
47+
48+
**Binaries:** `git tag v1.0.0 && git push origin v1.0.0`
49+
50+
Downloads: https://github.com/cs01/llvm-project/releases

README.md

Lines changed: 7 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -147,131 +147,25 @@ Many standard library functions already have these attributes in GNU libc header
147147
148148
## Null-Safe C Standard Library
149149
150-
The `clang/nullsafe-headers/` directory contains nullability-annotated standard library headers. Currently includes:
151-
- `string.h` - String manipulation functions (`strlen`, `strcpy`, `strdup`, etc.)
152-
- `stdlib.h` - Memory allocation and utilities (`malloc`, `free`, `getenv`, etc.)
153-
- `stdio.h` - File and I/O operations (`fopen`, `fclose`, `fprintf`, etc.)
154-
155-
These headers tell the compiler which functions can return NULL and which parameters can be NULL—information missing from system headers.
156-
157-
Functions like `malloc`, `strdup`, `getenv` are annotated to return `_Nullable` pointers (can be NULL), while parameters like `strlen`'s input are marked `_Nonnull` (must not be NULL).
158-
159-
Without null-safe headers (using system headers):
160-
```c
161-
#include <string.h> // System headers - no parameter nullability info
162-
163-
void example(const char* input) {
164-
char* result = strdup(input); // No warning - compiler doesn't know strdup needs nonnull
165-
result[0] = 'x'; // ⚠️ Warning: result might be NULL (all pointers nullable by default)
166-
}
167-
```
168-
You get warnings about dereferencing nullable return values, but not about passing NULL to functions.
169-
170-
With null-safe headers:
171-
```c
172-
#include "string.h" // From clang/nullsafe-headers - strdup parameter is _Nonnull
173-
174-
void example(const char* input) {
175-
char* result = strdup(input); // ⚠️ Warning: passing nullable 'input' to nonnull parameter!
176-
result[0] = 'x'; // ⚠️ Warning: dereferencing nullable pointer!
177-
178-
// Fix both issues:
179-
if (input) {
180-
char* result = strdup(input); // ✓ OK - input is non-null
181-
if (result) {
182-
result[0] = 'x'; // ✓ OK - result is non-null
183-
free(result);
184-
}
185-
}
186-
}
187-
```
188-
Now you get warnings for BOTH nullable returns AND passing NULL to nonnull parameters.
189-
190-
The headers catch both directions:
191-
192-
```c
193-
#include "string.h"
194-
195-
void test_returns(void) {
196-
char* str = malloc(100); // malloc returns _Nullable
197-
str[0] = 'x'; // ⚠️ Warning: str might be NULL!
198-
}
199-
200-
void test_params(char* str) {
201-
strlen(str); // ⚠️ Warning: str is nullable, strlen expects nonnull!
202-
203-
if (str) {
204-
strlen(str); // ✓ OK - str is non-null here
205-
}
206-
}
207-
```
208-
209-
### Using Null-Safe Headers
150+
Nullability-annotated headers for `string.h`, `stdlib.h`, and `stdio.h` are available in `clang/nullsafe-headers/`. These tell the compiler which functions return nullable pointers and which parameters must be non-null.
210151
211152
```bash
212153
# Compile with null-safe headers
213154
clang -Iclang/nullsafe-headers/include mycode.c
214155
```
215156

216-
Example code:
217157
```c
218158
#include "string.h"
219159
#include "stdlib.h"
220160

221-
void safe_code(const char* input) {
222-
if (!input) return; // Early return for null check
223-
224-
// After the check, strict nullability knows input is non-null
225-
size_t len = strlen(input); // OK - strlen expects non-null
226-
char* copy = malloc(len + 1);
227-
228-
if (copy) { // Check malloc result (returns _Nullable)
229-
strcpy(copy, input); // OK - both non-null
161+
void example(const char* input) {
162+
if (!input) return;
163+
char* copy = malloc(strlen(input) + 1); // malloc returns _Nullable
164+
if (copy) {
165+
strcpy(copy, input); // Both parameters narrowed to non-null
230166
free(copy);
231167
}
232168
}
233169
```
234170
235-
See [`clang/nullsafe-headers/README.md`](clang/nullsafe-headers/README.md) for complete documentation.
236-
237-
238-
---
239-
240-
# The LLVM Compiler Infrastructure
241-
242-
This repository contains the source code for LLVM, a toolkit for the
243-
construction of highly optimized compilers, optimizers, and run-time
244-
environments.
245-
246-
The LLVM project has multiple components. The core of the project is
247-
itself called "LLVM". This contains all of the tools, libraries, and header
248-
files needed to process intermediate representations and convert them into
249-
object files. Tools include an assembler, disassembler, bitcode analyzer, and
250-
bitcode optimizer.
251-
252-
C-like languages use the [Clang](https://clang.llvm.org/) frontend. This
253-
component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode
254-
-- and from there into object files, using LLVM.
255-
256-
Other components include:
257-
the [libc++ C++ standard library](https://libcxx.llvm.org),
258-
the [LLD linker](https://lld.llvm.org), and more.
259-
260-
## Getting the Source Code and Building LLVM
261-
262-
Consult the
263-
[Getting Started with LLVM](https://llvm.org/docs/GettingStarted.html#getting-the-source-code-and-building-llvm)
264-
page for information on building and running LLVM.
265-
266-
For information on how to contribute to the LLVM project, please take a look at
267-
the [Contributing to LLVM](https://llvm.org/docs/Contributing.html) guide.
268-
269-
## Getting in touch
270-
271-
Join the [LLVM Discourse forums](https://discourse.llvm.org/), [Discord
272-
chat](https://discord.gg/xS7Z362),
273-
[LLVM Office Hours](https://llvm.org/docs/GettingInvolved.html#office-hours) or
274-
[Regular sync-ups](https://llvm.org/docs/GettingInvolved.html#online-sync-ups).
275-
276-
The LLVM project has adopted a [code of conduct](https://llvm.org/docs/CodeOfConduct.html) for
277-
participants to all modes of communication within the project.
171+
See [`clang/nullsafe-headers/README.md`](clang/nullsafe-headers/README.md) for details.

0 commit comments

Comments
 (0)