On Saturday, 21 May 2022 at 21:18:15 UTC, Chris Piker wrote:
> Hi GDC
I've been able to build gdc-12.1 on ubuntu20 using
wget http://mirrors.concertpass.com/gcc/releases/gcc-12.1.0/gcc-12.1.0.tar.xz
tar -xvf gcc-12.1.0.tar.xz
cd gcc-12.1.0
mkdir build
cd build
../configure --prefix=/usr/local/gcc12 --enable-languages=d \
--enable-libphobos-checking --disable-multilib --program-suffix=-12
make -j6
make install
Now I'm looking to repeat the process for mingw64. I see that I'll need an older version of gdc first, say 11.3. So that's okay, I'll build it twice, but in general I'm wondering if:
-
Anyone has built gdc-11 in the mingw64 environment since it seems a few patches are required?
-
How we might go about creating a pacman package for gdc-12 since it requires an existing D compiler?
The first one is just an information request since the old PKGBUILD files are on github, but the second one is a bit more daunting. Without a previous version of gdc to build gdc it might be hard to get a mingw64 package accepted.
Thanks
My response to the the numbered questions:
-
I have successfully built gdc version 11.3.0 using gcc 12.2.0 (this is possible due to the others who have done work on porting GDC to Windows) in the mingw64 environment by modifying the MINGW-packages gcc PKGBUILD build script that is used for building all the GCC packages (like the gfortran, gcc, objective-c/c++, libgccjit, and Ada packages). I used the command MAKEFLAGS="-j12" MINGW_ARCH=mingw64 makepkg-mingw -sLf
and this PKGBUILD build script based on the last version (https://github.com/preetpalS/MINGW-packages/commit/fc660082fabe2181cae188cb10a99566d8301768) of the GCC build script that built version 11.3 of the compiler. Note that it is a WIP as I have not added any code to package the built gdc compiler and there are also some other issues (see below).
-
To build a package for gdc-12, you will have to compile gdc (gcc version 11 (11.3 or later)) with the same configuration as the rest of the gcc packages and then use that compiled gdc to bootstrap gdc-12 as a part of the build process of gcc-12.2.0 (or a later version). For gdc, I think you could create a separate package that is based on version 11.3 of the gcc sources, then once that is in the package system, modify the PKGBUILD script for the main gcc package so that it includes the necessary packaging for gdc and in a single commit add that change as well as remove the separate gdc package to get it in the system.
Here is the diff of the PKGBUILD script I used for gdc versus what was used for GCC version 11.3:
$ diff PKGBUILD ../mingw-w64-gcc/PKGBUILD
8,10c8,10
< _enable_ada=no
< _enable_objc=no
< _enable_jit=no
---
> _enable_ada=yes
> _enable_objc=yes
> _enable_jit=yes
185c185
< local _languages="d"
---
> local _languages="c,lto,c++,fortran"
224a225
> --enable-threads=${_threads} \
232d232
< --enable-libphobos \
Here are some issues that I encountered:
- The only relevant changes related to gdc in the PKGBUILD script is the enabling of libphobos (
--enable-libphobos
) in the configure flags and the removal of the flag that changes the default threading of GCC on Windows to posix (--enable-threads=${_threads}
where _threads="posix"
). The main issue related to posix threads has already been reported in the GDC issue tracker and based on my limited testing I believe that it is the only issue on the gdc side that is preventing gdc from being package for mingw64 (in msys2).
- When compiling gcc 11.3.0 without any modifications for gdc, Ada could not be compiled so I disabled it in the PKGBUILD script.
- When compiling gcc 11.3.0 with posix threading not being the default, libgccjit did not compile (I also disabled objc and fortran; c, lto, and c++ are also built even when d is the only language in the
local_languages
variable).
The gdc compiler appears to be working on Windows with no issues (with gcc's default threading on Windows) based on a couple of tests:
preet@DESKTOP MINGW64 /b/D/gdc/MINGW-packages-gdc-11.3.0-build/mingw-w64-gdc/tests_for_d_compiler
$ cat message_passing.d
import std.stdio : writeln;
import std.concurrency : receive, receiveOnly,
send, spawn, thisTid, Tid;
/*
A custom struct that is used as a message
for a little thread army.
*/
struct NumberMessage {
int number;
this(int i) {
this.number = i;
}
}
/*
Message is used as a stop sign for other
threads
*/
struct CancelMessage {
}
/// Acknowledge a CancelMessage
struct CancelAckMessage {
}
/*
The thread worker main
function which gets its parent id
passed as argument.
*/
void worker(Tid parentId)
{
bool canceled = false;
writeln("Starting ", thisTid, "...");
while (!canceled) {
receive(
(NumberMessage m) {
writeln("Received int: ", m.number);
},
(string text) {
writeln("Received string: ", text);
},
(CancelMessage m) {
writeln("Stopping ", thisTid, "...");
send(parentId, CancelAckMessage());
canceled = true;
}
);
}
}
void main()
{
Tid[] threads;
// Spawn 10 little worker threads.
for (size_t i = 0; i < 10; ++i) {
threads ~= spawn(&worker, thisTid);
}
// Odd threads get a number, even threads
// a string!
foreach(int idx, ref tid; threads) {
import std.string : format;
if (idx % 2)
send(tid, NumberMessage(idx));
else
send(tid, format("T=%d", idx));
}
// And all threads get the cancel message!
foreach(ref tid; threads) {
send(tid, CancelMessage());
}
// And we wait until all threads have
// acknowledged their stop request
foreach(ref tid; threads) {
receiveOnly!CancelAckMessage;
writeln("Received CancelAckMessage!");
}
}
preet@DESKTOP MINGW64 /b/D/gdc/MINGW-packages-gdc-11.3.0-build/mingw-w64-gdc/tests_for_d_compiler
$ ../src/mingw64/bin/gdc.exe message_passing.d -o message_passing
message_passing.d:64:5: warning: foreach: loop index implicitly converted from 'size_t' to 'int' [-Wdeprecated]
64 | foreach(int idx, ref tid; threads) {
| ^
preet@DESKTOP MINGW64 /b/D/gdc/MINGW-packages-gdc-11.3.0-build/mingw-w64-gdc/tests_for_d_compiler
$ ./message_passing.exe
Starting Tid(1b97d031100)...
Starting Tid(1b97d031200)...
Starting Tid(1b97d031300)...
Starting Tid(1b97d031400)...
Starting Tid(1b97d031500)...
Starting Tid(1b97d031600)...
Starting Tid(1b97d031700)...
Starting Tid(1b97d031800)...
Starting Tid(1b97d031900)...
Starting Tid(1b97d031a00)...
Received string: T=2
Received string: T=0
Received string: T=4
Received int: 5
Received string: T=8
Received int: 7
Received int: 3
Received int: 1
Received string: T=6
Received int: 9
Stopping Tid(1b97d031200)...
Stopping Tid(1b97d031500)...
Stopping Tid(1b97d031600)...
Stopping Tid(1b97d031800)...
Stopping Tid(1b97d031700)...
Stopping Tid(1b97d031900)...
Stopping Tid(1b97d031100)...
Stopping Tid(1b97d031a00)...
Received CancelAckMessage!
Received CancelAckMessage!
Stopping Tid(1b97d031400)...
Received CancelAckMessage!
Received CancelAckMessage!
Received CancelAckMessage!
Received CancelAckMessage!
Received CancelAckMessage!
Received CancelAckMessage!
Stopping Tid(1b97d031300)...
Received CancelAckMessage!
Received CancelAckMessage!
preet@DESKTOP MINGW64 /b/D/gdc/MINGW-packages-gdc-11.3.0-build/mingw-w64-gdc/tests_for_d_compiler
$ cat parallelism.d
import std.parallelism : task,
taskPool, TaskPool;
import std.array : array;
import std.stdio : writeln;
import std.range : iota;
string theTask()
{
import core.thread : dur, Thread;
Thread.sleep( dur!("seconds")(1) );
return "Hello World";
}
void main()
{
// taskpool with two threads
auto myTaskPool = new TaskPool(2);
// Stopping the task pool is important!
scope(exit) myTaskPool.stop();
// Start long running task
// and do some other stuff in the mean
// time..
auto task = task!theTask;
myTaskPool.put(task);
auto arr = iota(1, 10).array;
foreach(ref i; myTaskPool.parallel(arr)) {
i = i*i;
}
writeln(arr);
import std.algorithm.iteration : map;
// Use reduce to calculate the sum
// of all squares in parallel.
auto result = taskPool.reduce!"a+b"(
0.0, iota(100).map!"a*a");
writeln("Sum of squares: ", result);
// Get our result we sent to background
// earlier.
writeln(task.yieldForce);
}
preet@DESKTOP MINGW64 /b/D/gdc/MINGW-packages-gdc-11.3.0-build/mingw-w64-gdc/tests_for_d_compiler
$ ../src/mingw64/bin/gdc.exe parallelism.d -o parallelism
preet@DESKTOP MINGW64 /b/D/gdc/MINGW-packages-gdc-11.3.0-build/mingw-w64-gdc/tests_for_d_compiler
$ ./parallelism.exe
[1, 4, 9, 16, 25, 36, 49, 64, 81]
Sum of squares: 328350
Hello World
preet@DESKTOP MINGW64 /b/D/gdc/MINGW-packages-gdc-11.3.0-build/mingw-w64-gdc/tests_for_d_compiler
$ ../src/mingw64/bin/gdc.exe --version
gdc.exe (Rev2, Built by MSYS2 project) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
preet@DESKTOP MINGW64 /b/D/gdc/MINGW-packages-gdc-11.3.0-build/mingw-w64-gdc/tests_for_d_compiler
$ git log -n 1
commit ce1d6c3ada291332c782516ad81626162d39f2d6 (HEAD -> gcc-11.3.0, origin/gcc-11.3.0)
Author: Preetpal Sohal <preetpal.sohal@gmail.com>
Date: Sun Sep 4 20:23:11 2022 -0700
WIP only build D (other packages need pthreads like jit)