Skip to content

Commit 8cf06b8

Browse files
committed
Repo Update
- Moved high level LLD support to libLLVM.LLD unit - Updated LLDLink to capture StdOut and StdErr strings
1 parent 92bd5c8 commit 8cf06b8

File tree

9 files changed

+508
-180
lines changed

9 files changed

+508
-180
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Push → Discussion
2+
3+
on:
4+
push:
5+
branches:
6+
- '**' # change to [ main ] if you only want main pushes
7+
8+
permissions:
9+
contents: read
10+
discussions: write # needed to create discussions
11+
12+
env:
13+
# Must match an existing Discussions category in this repo
14+
DISCUSSIONS_CATEGORY: Push Updates
15+
16+
jobs:
17+
post:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Create a discussion for this push
21+
uses: actions/github-script@v7
22+
with:
23+
script: |
24+
const core = require("@actions/core");
25+
const { owner, repo } = context.repo;
26+
const push = context.payload;
27+
28+
// --- 1) Find category by name ---
29+
const desiredName = (process.env.DISCUSSIONS_CATEGORY || "").trim();
30+
const { data: categories } = await github.request(
31+
"GET /repos/{owner}/{repo}/discussions/categories",
32+
{ owner, repo }
33+
);
34+
if (!categories?.length) {
35+
core.setFailed("No Discussions categories found. Enable Discussions and create at least one category.");
36+
return;
37+
}
38+
const category = categories.find(c => c.name.toLowerCase() === desiredName.toLowerCase()) || categories[0];
39+
40+
// --- 2) Build title/body from push payload ---
41+
const branch = (push.ref || "").replace("refs/heads/", "");
42+
const pusher =
43+
push.pusher?.name ||
44+
push.sender?.login ||
45+
"unknown";
46+
47+
const commits = push.commits || [];
48+
const commitCount = commits.length;
49+
50+
// Title like: "Push to main by Jarrod — 3 commits"
51+
const title = `Push to ${branch || "(unknown branch)"} by ${pusher} — ${commitCount} commit${commitCount === 1 ? "" : "s"}`;
52+
53+
// Each commit: short sha, first-line message, author, link
54+
const lines = [];
55+
for (const c of commits) {
56+
const sha7 = (c.id || "").substring(0, 7);
57+
const firstLine = (c.message || "").split("\n")[0];
58+
const author = c.author?.name || "unknown";
59+
const url = c.url || `https://github.com/${owner}/${repo}/commit/${c.id}`;
60+
lines.push(`- [\`${sha7}\`](${url}) ${firstLine} — _${author}_`);
61+
}
62+
63+
// Compare URL (payload usually provides it)
64+
const compareUrl =
65+
push.compare ||
66+
`https://github.com/${owner}/${repo}/compare/${push.before}...${push.after}`;
67+
68+
// Top banner + details + footer
69+
const body = [
70+
`> _This discussion was created automatically by GitHub Actions from a \`push\` event._`,
71+
"",
72+
`**Branch:** \`${branch}\``,
73+
`**Pusher:** ${pusher}`,
74+
`**Compare:** ${compareUrl}`,
75+
"",
76+
"### Commits",
77+
lines.length ? lines.join("\n") : "_No commit details available._",
78+
"",
79+
"<sub>— end of automated log —</sub>"
80+
].join("\n");
81+
82+
// --- 3) Create the Discussion ---
83+
const { data: discussion } = await github.request(
84+
"POST /repos/{owner}/{repo}/discussions",
85+
{
86+
owner,
87+
repo,
88+
title,
89+
body,
90+
category_id: category.id
91+
}
92+
);
93+
94+
core.info(`Created discussion: ${discussion.html_url}`);

checkpoint.zip

20.8 MB
Binary file not shown.

examples/testbed/Testbed.dpr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ uses
3838
libLLVM.Test.Types in '..\..\src\tests\libLLVM.Test.Types.pas',
3939
libLLVM.Test.Values in '..\..\src\tests\libLLVM.Test.Values.pas',
4040
libLLVM.Test.Variable in '..\..\src\tests\libLLVM.Test.Variable.pas',
41-
libLLVM.Test.CodeGen in '..\..\src\tests\libLLVM.Test.CodeGen.pas';
41+
libLLVM.Test.CodeGen in '..\..\src\tests\libLLVM.Test.CodeGen.pas',
42+
libLLVM.LLD in '..\..\src\libLLVM.LLD.pas';
4243

4344
begin
4445
RunTests();

examples/testbed/Testbed.dproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
<DCCReference Include="..\..\src\tests\libLLVM.Test.Values.pas"/>
137137
<DCCReference Include="..\..\src\tests\libLLVM.Test.Variable.pas"/>
138138
<DCCReference Include="..\..\src\tests\libLLVM.Test.CodeGen.pas"/>
139+
<DCCReference Include="..\..\src\libLLVM.LLD.pas"/>
139140
<BuildConfiguration Include="Base">
140141
<Key>Base</Key>
141142
</BuildConfiguration>

src/libLLVM.API.pas

Lines changed: 6 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
{===============================================================================
32
_ _ _ _ _ __ ____ __ ™
43
| (_) |__| | | |\ \ / / \/ |
@@ -39,10 +38,11 @@
3938
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4039
4140
------------------------------------------------------------------------------
42-
41+
4342
This library uses the following open-source libraries:
44-
* LLVM - https://github.com/llvm/llvm-project
45-
43+
* Dlluminator - https://github.com/tinyBigGAMES/Dlluminator
44+
* LLVM - https://github.com/llvm/llvm-project
45+
4646
===============================================================================}
4747

4848
unit libLLVM.API;
@@ -2426,111 +2426,7 @@ LLVMOrcCLookupSetElement = record
24262426
LLVMPassBuilderOptionsSetMergeFunctions: procedure(Options: LLVMPassBuilderOptionsRef; MergeFunctions: LLVMBool); cdecl;
24272427
LLVMPassBuilderOptionsSetInlinerThreshold: procedure(Options: LLVMPassBuilderOptionsRef; Threshold: Integer); cdecl;
24282428
LLVMDisposePassBuilderOptions: procedure(Options: LLVMPassBuilderOptionsRef); cdecl;
2429-
2430-
2431-
/// <summary>
2432-
/// Invokes the LLD linker (via the combined LLVM-C + LLD DLL) with the given command-line
2433-
/// arguments and linker <c>AFlavor</c>, returning LLD’s process-style exit code and whether
2434-
/// the linker may be safely called again within the same process.
2435-
/// </summary>
2436-
///
2437-
/// <param name="AArgs">
2438-
/// Command-line tokens to forward to LLD as <c>argv</c>. This should mirror what you would
2439-
/// pass to the command-line tools (e.g., <c>lld-link</c>, <c>ld.lld</c>, <c>ld64.lld</c>, <c>wasm-ld</c>).
2440-
/// <para>
2441-
/// If the first element is missing or starts with <c>-</c>/<c>/</c>, the wrapper inserts a suitable
2442-
/// tool token for <c>AFlavor</c> as <c>argv[0]</c>. Valid defaults are:
2443-
/// <list type="bullet">
2444-
/// <item><description><c>coff</c> → <c>lld-link</c></description></item>
2445-
/// <item><description><c>elf</c> → <c>ld.lld</c></description></item>
2446-
/// <item><description><c>macho</c>/<c>darwin</c> → <c>ld64.lld</c></description></item>
2447-
/// <item><description><c>wasm</c> → <c>wasm-ld</c></description></item>
2448-
/// <item><description><c>mingw</c> → <c>ld.lld</c></description></item>
2449-
/// </list>
2450-
/// </para>
2451-
/// <para>
2452-
/// All tokens are marshaled as UTF-8 and passed verbatim to LLD. Include your object files,
2453-
/// libraries, and options (e.g., <c>/out:app.exe</c>, <c>/subsystem:console</c>,
2454-
/// <c>/libpath:...</c>, <c>kernel32.lib</c>, <c>ucrt.lib</c>, <c>vcruntime.lib</c>,
2455-
/// <c>legacy_stdio_definitions.lib</c>, etc.).
2456-
/// </para>
2457-
/// </param>
2458-
///
2459-
/// <param name="AFlavor">
2460-
/// Linker “driver” to invoke: <c>coff</c>, <c>elf</c>, <c>macho</c>, <c>wasm</c>, or <c>mingw</c>
2461-
/// (case-insensitive). If empty, LLD auto-detects based on <c>argv[0]</c> and inputs.
2462-
/// </param>
2463-
///
2464-
/// <param name="ACanRunAgain">
2465-
/// <c>True</c> if LLD reports it is safe to call again in the same process; <c>False</c> if a
2466-
/// fatal/unsafe condition was detected (e.g., crash-recovery scenario). If <c>False</c>,
2467-
/// do not invoke LLD again in this process—restart a helper process instead.
2468-
/// </param>
2469-
///
2470-
/// <returns>
2471-
/// LLD’s exit code (0 = success; non-zero = failure). Typical link errors return 1 with
2472-
/// diagnostics emitted by LLD (enable <c>/verbose</c> to increase detail).
2473-
/// </returns>
2474-
///
2475-
/// <remarks>
2476-
/// <para><b>Requirements:</b> The combined DLL must export <c>LLD_Link</c> and the relevant LLD drivers
2477-
/// must be linked in (e.g., <c>lldCOFF</c>, <c>lldELF</c>, <c>lldMachO</c>, <c>lldWasm</c>, <c>lldMinGW</c>, plus <c>lldCommon</c>).</para>
2478-
/// <para><b>CRT/SDK:</b> For COFF, ensure the correct CRT set is provided:
2479-
/// <list type="bullet">
2480-
/// <item><description><b>Dynamic (/MD)</b>: <c>ucrt.lib</c>, <c>vcruntime.lib</c>, <c>legacy_stdio_definitions.lib</c>, <c>kernel32.lib</c></description></item>
2481-
/// <item><description><b>Static (/MT)</b>: <c>libucrt.lib</c>, <c>libvcruntime.lib</c>, <c>libcmt.lib</c>, <c>legacy_stdio_definitions.lib</c>, <c>kernel32.lib</c></description></item>
2482-
/// </list>
2483-
/// Add appropriate <c>/libpath:</c> entries (VC Tools, UCRT, WinSDK) if the libs aren’t in the working directory.
2484-
/// </para>
2485-
/// <para><b>argv[0] and flavor:</b> LLD uses either <c>AFlavor</c> or the tool name in <c>argv[0]</c> to select a driver. This
2486-
/// wrapper guarantees a valid <c>argv[0]</c> when missing.</para>
2487-
/// <para><b>Thread-safety:</b> Treat calls as serialized with respect to LLD. If you need concurrency,
2488-
/// isolate each link in a separate process.</para>
2489-
/// <para><b>Diagnostics:</b> This wrapper does not intercept stdout/stderr. LLD prints errors/warnings
2490-
/// to the process streams. Use <c>/verbose</c> (COFF) or the equivalent flags for other drivers to
2491-
/// diagnose missing libs/symbols and path issues.</para>
2492-
/// </remarks>
2493-
///
2494-
/// <example>
2495-
/// <code lang="delphi">
2496-
/// // COFF (dynamic CRT)
2497-
/// var Can: Boolean; RC: Integer;
2498-
/// RC := LLDLink([
2499-
/// 'lld-link',
2500-
/// '/nologo',
2501-
/// '/subsystem:console',
2502-
/// '/entry:mainCRTStartup',
2503-
/// '/out:C:\temp\hello.exe',
2504-
/// '/libpath:C:\VS\VC\Tools\MSVC\14.3x\lib\x64',
2505-
/// '/libpath:C:\Windows Kits\10\Lib\10.0.x\um\x64',
2506-
/// '/libpath:C:\Windows Kits\10\Lib\10.0.x\ucrt\x64',
2507-
/// 'C:\temp\hello.obj',
2508-
/// 'kernel32.lib','ucrt.lib','vcruntime.lib','legacy_stdio_definitions.lib',
2509-
/// '/verbose'
2510-
/// ], 'coff', Can);
2511-
/// </code>
2512-
/// </example>
2513-
///
2514-
/// <example>
2515-
/// <code lang="delphi">
2516-
/// // COFF (static CRT, /MT)
2517-
/// var Can: Boolean; RC: Integer;
2518-
/// RC := LLDLink([
2519-
/// 'lld-link','/nologo','/subsystem:console','/entry:mainCRTStartup',
2520-
/// '/out:C:\temp\hello.exe','C:\temp\hello.obj',
2521-
/// 'kernel32.lib','libucrt.lib','libvcruntime.lib','libcmt.lib','legacy_stdio_definitions.lib'
2522-
/// ], 'coff', Can);
2523-
/// </code>
2524-
/// </example>
2525-
///
2526-
/// <example>
2527-
/// <code lang="delphi">
2528-
/// // ELF
2529-
/// var Can: Boolean; RC: Integer;
2530-
/// RC := LLDLink(['ld.lld','-o','/tmp/hello','/tmp/hello.o','--fatal-warnings'], 'elf', Can);
2531-
/// </code>
2532-
/// </example>
2533-
function LLDLink(const AArgs: array of string; const AFlavor: string; out ACanRunAgain: Boolean): Integer;
2429+
LLD_Link: function(argc: Integer; argv: PPUTF8Char; const flavor: PUTF8Char; canRunAgain: PInteger): Integer; cdecl;
25342430

25352431
procedure GetExports(const aDLLHandle: THandle);
25362432

@@ -2539,6 +2435,7 @@ implementation
25392435
procedure GetExports(const aDLLHandle: THandle);
25402436
begin
25412437
if aDllHandle = 0 then Exit;
2438+
LLD_Link := GetProcAddress(aDLLHandle, 'LLD_Link');
25422439
LLVMABIAlignmentOfType := GetProcAddress(aDLLHandle, 'LLVMABIAlignmentOfType');
25432440
LLVMABISizeOfType := GetProcAddress(aDLLHandle, 'LLVMABISizeOfType');
25442441
LLVMAddAlias2 := GetProcAddress(aDLLHandle, 'LLVMAddAlias2');
@@ -3831,66 +3728,6 @@ procedure GetExports(const aDLLHandle: THandle);
38313728

38323729
var
38333730
DepsDLLHandle: THandle = 0;
3834-
LLD_Link: function(argc: Integer; argv: PPUTF8Char; const flavor: PUTF8Char; canRunAgain: PInteger): Integer; cdecl;
3835-
3836-
function LLDLink(const AArgs: array of string; const AFlavor: string; out ACanRunAgain: Boolean): Integer;
3837-
var
3838-
LUTF8Args: TArray<UTF8String>;
3839-
LArgv: TArray<PUTF8Char>;
3840-
LFlavorUTF8: UTF8String;
3841-
LCan: Integer;
3842-
LIdx: Integer;
3843-
LArg0: UTF8String;
3844-
begin
3845-
ACanRunAgain := False;
3846-
3847-
if Length(AArgs) > 0 then
3848-
begin
3849-
// Allocate arrays: UTF8 strings for storage, pointers for argv
3850-
SetLength(LUTF8Args, Length(AArgs));
3851-
SetLength(LArgv, Length(AArgs) + 1); // +1 for null terminator
3852-
3853-
// Convert each argument and store both string and pointer
3854-
for LIdx := 0 to High(AArgs) do
3855-
begin
3856-
LUTF8Args[LIdx] := UTF8String(AArgs[LIdx]);
3857-
LArgv[LIdx] := PUTF8Char(LUTF8Args[LIdx]);
3858-
end;
3859-
3860-
// Null-terminate the argv array
3861-
LArgv[High(LArgv)] := nil;
3862-
end
3863-
else
3864-
begin
3865-
// Handle empty args case with default tool names
3866-
if SameText(AFlavor, 'elf') then
3867-
LArg0 := UTF8String('ld.lld')
3868-
else if SameText(AFlavor, 'macho') or SameText(AFlavor, 'darwin') then
3869-
LArg0 := UTF8String('ld64.lld')
3870-
else if SameText(AFlavor, 'wasm') then
3871-
LArg0 := UTF8String('wasm-ld')
3872-
else
3873-
LArg0 := UTF8String('lld-link');
3874-
3875-
SetLength(LUTF8Args, 1);
3876-
SetLength(LArgv, 2); // 1 arg + null terminator
3877-
LUTF8Args[0] := LArg0;
3878-
LArgv[0] := PUTF8Char(LUTF8Args[0]);
3879-
LArgv[1] := nil; // Null terminator
3880-
end;
3881-
3882-
// Convert flavor string
3883-
if AFlavor <> '' then
3884-
LFlavorUTF8 := UTF8String(AFlavor)
3885-
else
3886-
LFlavorUTF8 := UTF8String('');
3887-
3888-
LCan := 0;
3889-
3890-
// Call with proper argc count (excludes null terminator)
3891-
Result := LLD_Link(Length(LUTF8Args), @LArgv[0], PUTF8Char(LFlavorUTF8), @LCan);
3892-
ACanRunAgain := LCan <> 0;
3893-
end;
38943731

38953732
procedure LoadDLL();
38963733
var
@@ -3922,7 +3759,6 @@ procedure LoadDLL();
39223759
LResStream.Free();
39233760
end;
39243761
GetExports(DepsDLLHandle);
3925-
LLD_Link := GetProcAddress(DepsDLLHandle, 'LLD_Link');
39263762
end;
39273763

39283764
procedure UnloadDLL();

0 commit comments

Comments
 (0)