Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to build on Windows? #1442

Closed
inxksp opened this issue Mar 29, 2024 · 17 comments
Closed

How to build on Windows? #1442

inxksp opened this issue Mar 29, 2024 · 17 comments

Comments

@inxksp
Copy link

inxksp commented Mar 29, 2024

How can I compile a riscv-tolchain on Windows for nuclei N300 (arch=rv32imafcp)?

@kito-cheng
Copy link
Collaborator

WSL and then use mingw cross compiler (by something like --with-host=x86_64-w64-mingw32)...that's the best way I know.

@TommyMurphyTM1234
Copy link
Collaborator

For what it's worth, two other options that I have found useful for building RISC-V toolchains - particularly cross compiling the toolchain to run on Windows:

  1. crosstool-NG: https://crosstool-ng.github.io/
  2. @ilg-ul's xPack npm/xpm/Docker based build scripts: https://xpack.github.io/dev-tools/riscv-none-elf-gcc/#build-details

@TommyMurphyTM1234
Copy link
Collaborator

TommyMurphyTM1234 commented Mar 30, 2024

How can I compile a riscv-tolchain on Windows for nuclei N300 (arch=rv32imafcp)?

Is that even possible at the moment?
As far as I can see the P extension (which presumably encompasses some or all of Zbpbo, Zpn, Zpsfoperand) is not yet ratified so I'm not sure if/where any toolchain support has been prototyped?

Presumably not in the upstream GCC and related projects where only support for ratified extensions is implemented?

Edit: oh - maybe this helps? (I'd completely forgotten about it!)...

@TommyMurphyTM1234
Copy link
Collaborator

TommyMurphyTM1234 commented Mar 30, 2024

WSL and then use mingw cross compiler (by something like --with-host=x86_64-w64-mingw32)...that's the best way I know.

I tried a few different tacks to get this working but failed.
This was my last atttempt which got furthest but still failed:

sudo apt install gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64
git clone https://github.com/riscv-collab/riscv-gnu-toolchain issues-1442
cd issues-1442
git clone https://github.com/plctlab/riscv-gcc -b riscv-gcc-p-ext riscv-gcc-p-ext
git clone https://github.com/plctlab/riscv-binutils-gdb -b riscv-binutils-p-ext riscv-binutils-p-ext
cd riscv-gcc-p-ext
./contrib/download_prerequisites
cd ..
./configure  --prefix=`pwd`/installed-tools --with-arch=rv32imafcp --with-abi=ilp32f --with-gcc-src=`pwd`/riscv-gcc-p-ext --with-binutils-src=`pwd`/riscv-binutils-p-ext --disable-gdb --with-host=x86_64-w64-mingw32 --without-system-zlib
make 2>&1 | tee build.log
...
cc -Wl,--stack,12582912 -o xgcc.exe gcc.o gcc-main.o ggc-none.o \
  c/gccspec.o driver-mingw32.o  libcommon-target.a \
   libcommon.a ../libcpp/libcpp.a   ../libbacktrace/.libs/libbacktrace.a ../libiberty/libiberty.a ../libdecnumber/libdecnumber.a
cp xgcc.exe gcc-cross.exe
x86_64-w64-mingw32-g++ -fno-PIE -c   -g -O2 -DIN_GCC  -DCROSS_DIRECTORY_STRUCTURE   -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wno-error=format-diag -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings   -DHAVE_CONFIG_H -I. -Ic-family -I/home/user/Downloads/riscv-gnu-toolchain/riscv-gcc-p-ext/gcc -I/home/user/Downloads/riscv-gnu-toolchain/riscv-gcc-p-ext/gcc/c-family -I/home/user/Downloads/riscv-gnu-toolchain/riscv-gcc-p-ext/gcc/../include -I/home/user/Downloads/riscv-gnu-toolchain/riscv-gcc-p-ext/gcc/../libcpp/include -I/home/user/Downloads/riscv-gnu-toolchain/build-gcc-newlib-stage1/./gmp -I/home/user/Downloads/riscv-gnu-toolchain/riscv-gcc-p-ext/gmp -I/home/user/Downloads/riscv-gnu-toolchain/build-gcc-newlib-stage1/./mpfr/src -I/home/user/Downloads/riscv-gnu-toolchain/riscv-gcc-p-ext/mpfr/src -I/home/user/Downloads/riscv-gnu-toolchain/riscv-gcc-p-ext/mpc/src  -I/home/user/Downloads/riscv-gnu-toolchain/riscv-gcc-p-ext/gcc/../libdecnumber -I/home/user/Downloads/riscv-gnu-toolchain/riscv-gcc-p-ext/gcc/../libdecnumber/dpd -I../libdecnumber -I/home/user/Downloads/riscv-gnu-toolchain/riscv-gcc-p-ext/gcc/../libbacktrace -I/home/user/Downloads/riscv-gnu-toolchain/build-gcc-newlib-stage1/./isl/include -I/home/user/Downloads/riscv-gnu-toolchain/riscv-gcc-p-ext/isl/include  -o c-family/cppspec.o -MT c-family/cppspec.o -MMD -MP -MF c-family/.deps/cppspec.TPo /home/user/Downloads/riscv-gnu-toolchain/riscv-gcc-p-ext/gcc/c-family/cppspec.c
x86_64-w64-mingw32-g++ -no-pie   -g -O2 -DIN_GCC  -DCROSS_DIRECTORY_STRUCTURE   -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wno-error=format-diag -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings   -DHAVE_CONFIG_H -static-libstdc++ -static-libgcc -Wl,--stack,12582912 -o cpp.exe gcc.o gcc-main.o ggc-none.o \
  c-family/cppspec.o driver-mingw32.o  libcommon-target.a \
   libcommon.a ../libcpp/libcpp.a   ../libbacktrace/.libs/libbacktrace.a ../libiberty/libiberty.a ../libdecnumber/libdecnumber.a
riscv32-unknown-elf-gcc -dumpspecs > tmp-specs
/bin/bash: line 1: riscv32-unknown-elf-gcc: command not found
make[2]: *** [Makefile:2090: specs] Error 127
make[2]: Leaving directory '/home/user/Downloads/riscv-gnu-toolchain/build-gcc-newlib-stage1/gcc'
make[1]: *** [Makefile:4414: all-gcc] Error 2
make[1]: Leaving directory '/home/user/Downloads/riscv-gnu-toolchain/build-gcc-newlib-stage1'
make: *** [Makefile:627: stamps/build-gcc-newlib-stage1] Error 2

I gave up and had better success with crosstool-NG.

I followed the usual instructions for installing CT-NG:

cd ~/Downloads
git clone https://github.com/crosstool-ng/crosstool-ng
cd crosstool-ng
./bootstrap
# Install any prerequisites and repeat until bootstrap succeeds
./configure --enable-local
# Install any prerequisites and repeat until configure succeeds
make

As above I installed the Windows cross compilers and cloned the P extension sources:

sudo apt install gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64
cd ~/Downloads/crosstool-ng
git clone https://github.com/plctlab/riscv-gcc -b riscv-gcc-p-ext riscv-gcc-p-ext
git clone https://github.com/plctlab/riscv-binutils-gdb -b riscv-binutils-p-ext riscv-binutils-p-ext

I then ran ct-ng menuconfig to create this .config (renamed to allow uploading here) to build the Canadian Cross toolchain (build host = Linux, run host = Windows, target = RISC-V) using the P enabled GCC and Binutils sources and with a toolchain default arch/abi of rv32imafcp/ilp32f:

I then ran ct-ng build and the toolchain built successfully.
I'm not sure about the non-fatal errors in this log which don't seem to impact the functionality of the final toolchain but I will check into them with the CT-NG community:

Edit: see the link above for an explanation of these "errors". In summary they are false positives and can be ignored. They occur because CT-NG presents any output string containing "error" as an [ERROR].

./ct-ng build
[INFO ]  Performing some trivial sanity checks
[WARN ]  Number of open files 1024 may not be sufficient to build the toolchain; increasing to 2048
[INFO ]  Build started 20240331.103021
[INFO ]  Building environment variables
[EXTRA]  Preparing working directories
[EXTRA]  Installing user-supplied crosstool-NG configuration
[EXTRA]  =================================================================
[EXTRA]  Dumping internal crosstool-NG configuration
[EXTRA]    Building a toolchain for:
[EXTRA]      build  = x86_64-pc-linux-gnu
[EXTRA]      host   = x86_64-w64-mingw32
[EXTRA]      target = riscv32-unknown-elf
[EXTRA]  Dumping internal crosstool-NG configuration: done in 0.12s (at 00:33)
[INFO ]  =================================================================
[INFO ]  Retrieving needed toolchain components' tarballs
[INFO ]  Retrieving needed toolchain components' tarballs: done in 2.22s (at 00:36)
[INFO ]  =================================================================
[INFO ]  Extracting and patching toolchain components
[WARN ]    binutils: using custom location, no patches applied
[WARN ]    gcc: using custom location, no patches applied
[INFO ]  Extracting and patching toolchain components: done in 406.38s (at 07:22)
[INFO ]  =================================================================
[INFO ]  Installing zlib for build
[EXTRA]    Configuring zlib
[EXTRA]    Building zlib
[EXTRA]    Installing zlib
[INFO ]  Installing zlib for build: done in 3.61s (at 07:26)
[INFO ]  =================================================================
[INFO ]  Installing zstd for build
[EXTRA]    Building zstd
[EXTRA]    Installing zstd
[INFO ]  Installing zstd for build: done in 16.49s (at 07:42)
[INFO ]  =================================================================
[INFO ]  Installing GMP for build
[EXTRA]    Configuring GMP
[EXTRA]    Building GMP
[EXTRA]    Installing GMP
[INFO ]  Installing GMP for build: done in 92.36s (at 09:15)
[INFO ]  =================================================================
[INFO ]  Installing MPFR for build
[EXTRA]    Configuring MPFR
[EXTRA]    Building MPFR
[EXTRA]    Installing MPFR
[INFO ]  Installing MPFR for build: done in 54.08s (at 10:09)
[INFO ]  =================================================================
[INFO ]  Installing ISL for build
[EXTRA]    Configuring ISL
[EXTRA]    Building ISL
[EXTRA]    Installing ISL
[INFO ]  Installing ISL for build: done in 54.55s (at 11:04)
[INFO ]  =================================================================
[INFO ]  Installing MPC for build
[EXTRA]    Configuring MPC
[EXTRA]    Building MPC
[EXTRA]    Installing MPC
[INFO ]  Installing MPC for build: done in 21.40s (at 11:25)
[INFO ]  =================================================================
[INFO ]  Installing ncurses for build
[EXTRA]    Configuring ncurses
[EXTRA]    Building ncurses
[EXTRA]    Installing ncurses
[INFO ]  Installing ncurses for build: done in 46.89s (at 12:12)
[INFO ]  =================================================================
[INFO ]  Installing libiconv for build
[EXTRA]    Skipping (included in GNU C library)
[INFO ]  Installing libiconv for build: done in 0.05s (at 12:12)
[INFO ]  =================================================================
[INFO ]  Installing gettext for build
[EXTRA]    Skipping (included in GNU C library)
[INFO ]  Installing gettext for build: done in 0.04s (at 12:12)
[INFO ]  =================================================================
[INFO ]  Installing binutils for build
[EXTRA]    Configuring binutils
[EXTRA]    Building binutils
[EXTRA]    Installing binutils
[INFO ]  Installing binutils for build: done in 138.06s (at 14:30)
[INFO ]  =================================================================
[INFO ]  Installing zlib for host
[EXTRA]    Building zlib
[EXTRA]    Installing zlib
[INFO ]  Installing zlib for host: done in 2.34s (at 14:33)
[INFO ]  =================================================================
[INFO ]  Installing zstd for host
[EXTRA]    Building zstd
[EXTRA]    Installing zstd
[INFO ]  Installing zstd for host: done in 18.61s (at 14:51)
[INFO ]  =================================================================
[INFO ]  Installing GMP for host
[EXTRA]    Configuring GMP
[EXTRA]    Building GMP
[EXTRA]    Installing GMP
[INFO ]  Installing GMP for host: done in 92.62s (at 16:24)
[INFO ]  =================================================================
[INFO ]  Installing MPFR for host
[EXTRA]    Configuring MPFR
[EXTRA]    Building MPFR
[EXTRA]    Installing MPFR
[INFO ]  Installing MPFR for host: done in 51.87s (at 17:16)
[INFO ]  =================================================================
[INFO ]  Installing ISL for host
[EXTRA]    Configuring ISL
[EXTRA]    Building ISL
[EXTRA]    Installing ISL
[INFO ]  Installing ISL for host: done in 56.67s (at 18:13)
[INFO ]  =================================================================
[INFO ]  Installing MPC for host
[EXTRA]    Configuring MPC
[EXTRA]    Building MPC
[EXTRA]    Installing MPC
[INFO ]  Installing MPC for host: done in 21.52s (at 18:34)
[INFO ]  =================================================================
[INFO ]  Installing expat for host
[EXTRA]    Configuring expat
[EXTRA]    Building expat
[EXTRA]    Installing expat
[INFO ]  Installing expat for host: done in 23.48s (at 18:58)
[INFO ]  =================================================================
[INFO ]  Installing ncurses for host
[EXTRA]    Configuring ncurses
[EXTRA]    Building ncurses
[EXTRA]    Installing ncurses
[INFO ]  Installing ncurses for host: done in 69.42s (at 20:07)
[INFO ]  =================================================================
[INFO ]  Installing libiconv for host
[EXTRA]    Configuring libiconv
[EXTRA]    Building libiconv
[EXTRA]    Installing libiconv
[INFO ]  Installing libiconv for host: done in 34.59s (at 20:42)
[INFO ]  =================================================================
[INFO ]  Installing gettext for host
[EXTRA]    Configuring gettext
[EXTRA]    Building gettext
[EXTRA]    Installing gettext
[INFO ]  Installing gettext for host: done in 579.10s (at 30:21)
[INFO ]  =================================================================
[INFO ]  Installing binutils for host
[EXTRA]    Configuring binutils
[EXTRA]    Prepare binutils for static build
[ERROR]      449 |       _bfd_error_handler (_("%pB: error: attribute section '%pA' too big: %#llx"),
[ERROR]      449 |       _bfd_error_handler (_("%pB: error: attribute section '%pA' too big: %#llx"),
[ERROR]      490 |   (_("%pB: error: attribute section length too small: %" PRId64),
[ERROR]      490 |   (_("%pB: error: attribute section length too small: %" PRId64),
[ERROR]      599 |       _bfd_error_handler (_("DWARF error: offset (%" PRIu64 ")"
[ERROR]      599 |       _bfd_error_handler (_("DWARF error: offset (%" PRIu64 ")"
[ERROR]      599 |       _bfd_error_handler (_("DWARF error: offset (%" PRIu64 ")"
[ERROR]      599 |       _bfd_error_handler (_("DWARF error: offset (%" PRIu64 ")"
[ERROR]     2036 |  (_("DWARF error: data count (%" PRIx64 ") larger than buffer size"),
[ERROR]     2036 |  (_("DWARF error: data count (%" PRIx64 ") larger than buffer size"),
[ERROR]     2077 |   (_("DWARF error: unknown format content type %" PRIu64),
[ERROR]     2077 |   (_("DWARF error: unknown format content type %" PRIu64),
[ERROR]     2150 |  (_("DWARF error: line info section is too small (%" PRId64 ")"),
[ERROR]     2150 |  (_("DWARF error: line info section is too small (%" PRId64 ")"),
[ERROR]     2180 |  (_("DWARF error: line info data is bigger (%#" PRIx64 ")"
[ERROR]     2180 |  (_("DWARF error: line info data is bigger (%#" PRIx64 ")"
[ERROR]     2180 |  (_("DWARF error: line info data is bigger (%#" PRIx64 ")"
[ERROR]     3006 |      (_("DWARF error: unable to read alt ref %" PRIu64),
[ERROR]     3006 |      (_("DWARF error: unable to read alt ref %" PRIu64),
[ERROR]     3062 |   (_("DWARF error: unable to locate abstract instance DIE ref %"
[ERROR]     3062 |   (_("DWARF error: unable to locate abstract instance DIE ref %"
[EXTRA]    Building binutils
[EXTRA]    Installing binutils
[INFO ]  Installing binutils for host: done in 139.13s (at 32:40)
[INFO ]  =================================================================
[INFO ]  Installing C library headers
[INFO ]  Installing C library headers: done in 0.22s (at 32:40)
[INFO ]  =================================================================
[INFO ]  Installing core C gcc compiler
[EXTRA]    Configuring core C gcc compiler
[EXTRA]    Building gcc
[EXTRA]    Installing gcc
[EXTRA]    Housekeeping for core gcc compiler
[EXTRA]       '' --> lib (gcc)   lib (os)
[INFO ]  Installing core C gcc compiler: done in 496.34s (at 40:57)
[INFO ]  =================================================================
[INFO ]  Installing C library
[EXTRA]    Configuring C library
[EXTRA]    Building C library
[EXTRA]    Installing C library
[INFO ]  Installing C library: done in 61.56s (at 41:58)
[INFO ]  =================================================================
[INFO ]  Installing final gcc compiler for build
[EXTRA]    Configuring final gcc compiler
[EXTRA]    Building final gcc compiler
[EXTRA]    Installing final gcc compiler
[EXTRA]    Housekeeping for core gcc compiler
[EXTRA]       '' --> lib (gcc)   lib (os)
[INFO ]  Installing final gcc compiler for build: done in 583.29s (at 51:42)
[INFO ]  =================================================================
[INFO ]  Installing final gcc compiler
[EXTRA]    Configuring final gcc compiler
[EXTRA]    Building final gcc compiler
[EXTRA]    Installing final gcc compiler
[EXTRA]    Housekeeping for core gcc compiler
[EXTRA]    Canadian Cross/Cross-native unable to confirm multilibs configuration  directly; will use build-compiler for housekeeping.
[EXTRA]       '' --> lib (gcc)   lib (os)
[INFO ]  Installing final gcc compiler: done in 631.95s (at 62:14)
[INFO ]  =================================================================
[INFO ]  Installing cross-gdb
[EXTRA]    Configuring cross gdb
[EXTRA]    Prepare gdb for static build
[ERROR]    14251 |       (_("%pB(%pA): error: reloc table entry %zu is empty"),
[ERROR]    14251 |       (_("%pB(%pA): error: reloc table entry %zu is empty"),
[ERROR]    14276 |        (_("%pB(%pA): error: secondary reloc %zu"
[ERROR]    14276 |        (_("%pB(%pA): error: secondary reloc %zu"
[ERROR]    14294 |    (_("%pB(%pA): error: secondary reloc %zu"
[ERROR]    14294 |    (_("%pB(%pA): error: secondary reloc %zu"
[ERROR]    14308 |       (_("%pB(%pA): error: secondary reloc %zu"
[ERROR]    14308 |       (_("%pB(%pA): error: secondary reloc %zu"
[ERROR]      503 |       _bfd_error_handler (_("%pB: error: attribute section '%pA' too big: %#llx"),
[ERROR]      503 |       _bfd_error_handler (_("%pB: error: attribute section '%pA' too big: %#llx"),
[ERROR]      757 |       _bfd_error_handler (_("DWARF error: offset (%" PRIu64 ")"
[ERROR]      757 |       _bfd_error_handler (_("DWARF error: offset (%" PRIu64 ")"
[ERROR]      757 |       _bfd_error_handler (_("DWARF error: offset (%" PRIu64 ")"
[ERROR]      757 |       _bfd_error_handler (_("DWARF error: offset (%" PRIu64 ")"
[ERROR]     2595 |  (_("DWARF error: data count (%" PRIx64 ") larger than buffer size"),
[ERROR]     2595 |  (_("DWARF error: data count (%" PRIx64 ") larger than buffer size"),
[ERROR]     2634 |   (_("DWARF error: unknown format content type %" PRIu64),
[ERROR]     2634 |   (_("DWARF error: unknown format content type %" PRIu64),
[ERROR]     2707 |  (_("DWARF error: line info section is too small (%" PRId64 ")"),
[ERROR]     2707 |  (_("DWARF error: line info section is too small (%" PRId64 ")"),
[ERROR]     2734 |  (_("DWARF error: line info data is bigger (%#" PRIx64 ")"
[ERROR]     2734 |  (_("DWARF error: line info data is bigger (%#" PRIx64 ")"
[ERROR]     2734 |  (_("DWARF error: line info data is bigger (%#" PRIx64 ")"
[ERROR]     3505 |      (_("DWARF error: unable to read alt ref %" PRIu64),
[ERROR]     3505 |      (_("DWARF error: unable to read alt ref %" PRIu64),
[ERROR]     3557 |   (_("DWARF error: unable to locate abstract instance DIE ref %"
[ERROR]     3557 |   (_("DWARF error: unable to locate abstract instance DIE ref %"
[EXTRA]    Building cross gdb
[EXTRA]    Installing cross gdb
[EXTRA]    Installing '.gdbinit' template
[INFO ]  Installing cross-gdb: done in 454.00s (at 69:48)
[INFO ]  =================================================================
[INFO ]  Finalizing the toolchain's directory
[INFO ]    Stripping all toolchain executables
[EXTRA]    Creating toolchain aliases
[EXTRA]    Removing installed documentation
[EXTRA]    Collect license information from: /home/user/Downloads/crosstool-ng/.build/HOST-x86_64-w64-mingw32/riscv32-unknown-elf/src
[EXTRA]    Put the license information to: /home/user/x-tools/HOST-x86_64-w64-mingw32/riscv32-unknown-elf/share/licenses
[INFO ]  Finalizing the toolchain's directory: done in 23.08s (at 70:11)
[INFO ]  Build completed at 20240331.114025
[INFO ]  (elapsed: 70:04.38)
[INFO ]  Finishing installation (may take a few seconds)...

To avoid problems with symbolic links I did the following:

cd ~/x-tools/HOST-x86_64-w64-mingw32
tar --dereference -czvf riscv32-unknown-elf.tgz riscv32-unknown-elf
# I'm using a Linux guest VM on Windows host so copy the compressed toolchain to Windows
cp riscv32-unknown-elf.tgz /media/sf_C_DRIVE/temp
# Extract the toolchain on Windows

In a Windows command shell:

c:
cd \temp\riscv32-unknown-elf\bin
riscv32-unknown-elf-gcc -v
Using built-in specs.
COLLECT_GCC=riscv32-unknown-elf-gcc
COLLECT_LTO_WRAPPER=c:/temp/riscv32-unknown-elf/bin/../libexec/gcc/riscv32-unknown-elf/10.2.0/lto-wrapper.exe
Target: riscv32-unknown-elf
Configured with: /home/user/Downloads/crosstool-ng/.build/HOST-x86_64-w64-mingw32/riscv32-unknown-elf/src/gcc/configure --build=x86_64-build_pc-linux-gnu --host=x86_64-host_w64-mingw32 --target=riscv32-unknown-elf --prefix=/home/user/x-tools/HOST-x86_64-w64-mingw32/riscv32-unknown-elf --exec_prefix=/home/user/x-tools/HOST-x86_64-w64-mingw32/riscv32-unknown-elf --with-local-prefix=/home/user/x-tools/HOST-x86_64-w64-mingw32/riscv32-unknown-elf/riscv32-unknown-elf --with-headers=/home/user/x-tools/HOST-x86_64-w64-mingw32/riscv32-unknown-elf/riscv32-unknown-elf/include --with-newlib --enable-threads=no --disable-shared --with-arch=rv32imafcp --with-abi=ilp32f --with-pkgversion='crosstool-NG 1.26.0.66_6ad7b96' --enable-__cxa_atexit --disable-libgomp --disable-libmudflap --disable-libmpx --disable-libssp --disable-libquadmath --disable-libquadmath-support --disable-libstdcxx-verbose --with-gmp=/home/user/Downloads/crosstool-ng/.build/HOST-x86_64-w64-mingw32/riscv32-unknown-elf/buildtools/complibs-host --with-mpfr=/home/user/Downloads/crosstool-ng/.build/HOST-x86_64-w64-mingw32/riscv32-unknown-elf/buildtools/complibs-host --with-mpc=/home/user/Downloads/crosstool-ng/.build/HOST-x86_64-w64-mingw32/riscv32-unknown-elf/buildtools/complibs-host --with-isl=/home/user/Downloads/crosstool-ng/.build/HOST-x86_64-w64-mingw32/riscv32-unknown-elf/buildtools/complibs-host --enable-lto --enable-target-optspace --disable-nls --disable-multilib --enable-languages=c,c++
Thread model: single
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.0 (crosstool-NG 1.26.0.66_6ad7b96)

@QBos07
Copy link

QBos07 commented Mar 31, 2024

Hello, ct-ng contributer here. I just wanted to say that MSYS2 is a great wsl alternative using native windows. ct-ng and gcc can but successfully compiled and used in this environment.
The toolchains don't have any dependency on the environment apart from a few DLLs wich you can just copy to the bin folder of the toolchain.

@TommyMurphyTM1234
Copy link
Collaborator

Hello, ct-ng contributer here. I just wanted to say that MSYS2 is a great wsl alternative using native windows. ct-ng and gcc can but successfully compiled and used in this environment. The toolchains don't have any dependency on the environment apart from a few DLLs wich you can just copy to the bin folder of the toolchain.

Thanks @QBos07. Maybe things have changed in recent years but, in the past, I always found MSYS2 difficult to correctly configure and use in order to build a GCC toolchain or other stuff such as OpenOCD. I always found a CT-NG Canadian Cross compilation from Linux more effective. Or the old xPack Docker based approach. I'm only trying the latest xPack approach now to see if/how that can be used to build a custom toolchain such as the one mentioned here. Maybe I should give MSYS2 another go too? :-)

@QBos07
Copy link

QBos07 commented Mar 31, 2024

Definitely, I wouldn't say it works flawlessly 101% of the time but for that is autoconf. I can recommend it.

@TommyMurphyTM1234
Copy link
Collaborator

TommyMurphyTM1234 commented Apr 1, 2024

Definitely, I wouldn't say it works flawlessly 101% of the time but for that is autoconf. I can recommend it.

Thanks @QBos07 - unfortunately I spent several hours yesterday trying to get things to build under MSYS2 but failed miserably.

Edit: ignore that - at least one fundamental mistake that I seem to have made was to use pacman -S gcc instead of pacman -S mingw-w64-ucrt-x86_64-gcc.

I'll continue trying with the correct GCC installed and post back with updates when I have something useful.

@TommyMurphyTM1234
Copy link
Collaborator

TommyMurphyTM1234 commented Apr 6, 2024

I was able to build a bare-metal toolchain (but not including GDB yet) using MSYS2 as follows:

  1. Create an install directory for MSYS2 - e.g. C:\msys64.
  2. Enable NTFS filesystem case sensitivity in order to avoid problems with files with the same name but different case (e.g. Linux headers): https://learn.microsoft.com/en-us/windows/wsl/case-sensitivity. In a PowerShell terminal with administrative privileges run this command: fsutil.exe file setCaseSensitiveInfo C:\msys64\ enable.
  3. Download the MSYS2 installer from https://www.msys2.org/ run it and install into C:\msys64.
  4. Uncomment MSYS=winsymlinks:nativestrict in C:\msys64\ucrt64.ini to avoid problems with ln -s symbolic links that the build process creates.
  5. Run an MSYS2 UCRT64 terminal: Start Menu > MSYS2 > MSYS2 UCRT64.
  6. Install these dependencies: pacman -S mingw-w64-ucrt-x86_64-gcc autoconf automake autotools curl python3 python3-pip gawk bison flex texinfo gperf libtool patchutils bc libexpat expat ninja git cmake. Updated dependencies including the appropriate expat package for building GDB: pacman -S mingw-w64-ucrt-x86_64-gcc autoconf automake autotools curl python3 python3-pip gawk bison flex texinfo gperf libtool patchutils bc libexpat mingw-w64-ucrt-x86_64-expat ninja git cmake.
  7. Run pwd to display the home directory - if it contains a space/spaces ("e.g. mine was /home/Tommy Murphy) then these will cause problems so create and use a directory without spaces - e.g. cd /home && mkdir riscv && cd riscv.
  8. Do a build as normal (disable GDB for now until I figure that out): See point 6 above.
git clone https://github.com/riscv-collab/riscv-gnu-toolchain
cd riscv-gnu-toolchain
./configure --prefix=`pwd`/installed-tools
make 2>&1 | tee build.log

TODO:

  1. Figure out how to build GDB - haven't been able to figure out what expat package meets its dependency requirements: https://packages.msys2.org/search?t=pkg&q=expat. Done. See point 6 above.
  2. Build Linux toolchain. Done
  3. Build other stuff - e.g. Spike/QEMU, LLVM etc.

Notes:

  1. crosstool-NG seems much easier to configure/use and builds a toolchain much quicker.

@TommyMurphyTM1234
Copy link
Collaborator

  1. Figure out how to build GDB - haven't been able to figure out what expat package meets its dependency requirements: https://packages.msys2.org/search?t=pkg&q=expat

For some reason just installing the expat package (pacman -S expat) didn't help and the build failed looking for libexpat. I tried pacman -S mingw-w64-expat that failed:

pacman -S mingw-w64-expat
error: target not found: mingw-w64-expat

In the end I just downloaded the expat sources and built them myself and then the build worked:

cd /home/temp
# https://github.com/libexpat/libexpat/releases
wget https://github.com/libexpat/libexpat/releases/download/R_2_6_2/expat-2.6.2.tar.gz
tar xzvf expat-2.6.2.tar.gz
cd expat-2.6.2
./configure 
make install

cd /home/temp
git clone https://github.com/riscv-collab/riscv-gnu-toolchain
cd riscv-gnu-toolchain
./configure --prefix=`pwd`/installed-tools
make

ls installed-tools/bin/
riscv64-unknown-elf-addr2line.exe  riscv64-unknown-elf-cpp.exe         riscv64-unknown-elf-gcc-nm.exe      riscv64-unknown-elf-gcov.exe       riscv64-unknown-elf-ld.exe        riscv64-unknown-elf-ranlib.exe   riscv64-unknown-elf-strip.exe
riscv64-unknown-elf-ar.exe         riscv64-unknown-elf-elfedit.exe     riscv64-unknown-elf-gcc-ranlib.exe  riscv64-unknown-elf-gdb-add-index  riscv64-unknown-elf-lto-dump.exe  riscv64-unknown-elf-readelf.exe
riscv64-unknown-elf-as.exe         riscv64-unknown-elf-g++.exe         riscv64-unknown-elf-gcc.exe         riscv64-unknown-elf-gdb.exe        riscv64-unknown-elf-nm.exe        riscv64-unknown-elf-run.exe
riscv64-unknown-elf-c++.exe        riscv64-unknown-elf-gcc-13.2.0.exe  riscv64-unknown-elf-gcov-dump.exe   riscv64-unknown-elf-gprof.exe      riscv64-unknown-elf-objcopy.exe   riscv64-unknown-elf-size.exe
riscv64-unknown-elf-c++filt.exe    riscv64-unknown-elf-gcc-ar.exe      riscv64-unknown-elf-gcov-tool.exe   riscv64-unknown-elf-ld.bfd.exe     riscv64-unknown-elf-objdump.exe   riscv64-unknown-elf-strings.exe

I did also had to manually copy the following DLLs in order for GDB to launch correctly:

cp /ucrt64/bin/libgmp-10.dll /home/temp/riscv-gnu-toolchain/installed-tools/bin
cp /ucrt64/bin/libmpfr-6.dll /home/temp/riscv-gnu-toolchain/installed-tools/bin
cp /ucrt64/bin/libzstd.dll /home/temp/riscv-gnu-toolchain/installed-tools/bin
cp /ucrt64/bin/libgcc_s_seh-1.dll /home/temp/riscv-gnu-toolchain/installed-tools/bin
cp /ucrt64/bin/libiconv-2.dll /home/temp/riscv-gnu-toolchain/installed-tools/bin
cp /ucrt64/bin/libwinpthread-1.dll /home/temp/riscv-gnu-toolchain/installed-tools/bin
cp /ucrt64/bin/libstdc++-6.dll /home/temp/riscv-gnu-toolchain/installed-tools/bin
cp /ucrt64/bin/libexpat-1.dll /home/temp/riscv-gnu-toolchain/installed-tools/bin

I haven't tried all of the toolchain executables so it's possible that there are other dependent DLLs but I think that the principle of compiling the Windows native bare-metal toolchain using MSYS2 has been illustrated adequately.

@QBos07
Copy link

QBos07 commented Apr 7, 2024

The binary version of expat is distrubuted as mingw-w64-ucrt-x86_64-expat for this platform.

@TommyMurphyTM1234
Copy link
Collaborator

The binary version of expat is distrubuted as mingw-w64-ucrt-x86_64-expat for this platform.

Thanks @QBos07 - I didn't realise that I was searching only base packages and not all packages earlier!

@TommyMurphyTM1234
Copy link
Collaborator

I haven't tried all of the toolchain executables so it's possible that there are other dependent DLLs but I think that the principle of compiling the Windows native bare-metal toolchain using MSYS2 has been illustrated adequately.

I guess that these DLLs probably need to be copied to the toolchain bin directory...

 ldd installed-tools/bin/*.exe | grep ucrt64 | rev | cut -c17- | rev | sort | uniq
        libexpat-1.dll => /ucrt64/bin/libexpat-1.dll
        libgcc_s_seh-1.dll => /ucrt64/bin/libgcc_s_seh-1.dll
        libgmp-10.dll => /ucrt64/bin/libgmp-10.dll
        libiconv-2.dll => /ucrt64/bin/libiconv-2.dll
        libisl-23.dll => /ucrt64/bin/libisl-23.dll
        libmpc-3.dll => /ucrt64/bin/libmpc-3.dll
        libmpfr-6.dll => /ucrt64/bin/libmpfr-6.dll
        libstdc++-6.dll => /ucrt64/bin/libstdc++-6.dll
        libwinpthread-1.dll => /ucrt64/bin/libwinpthread-1.dll
        libzstd.dll => /ucrt64/bin/libzstd.dll
        zlib1.dll => /ucrt64/bin/zlib1.dll

@QBos07
Copy link

QBos07 commented Apr 9, 2024

If you don't want to copy the dlls. It's possible to just add C:\msys64\ucrt\bin to the PATH. This has the added benefit of convienently having many coreutils in your windows terminal.

@TommyMurphyTM1234
Copy link
Collaborator

Yes, but I'm thinking of the situation where one builds a native Windows toolchain for use by somebody who doesn't have/want to install MSYS2.

@ilg-ul
Copy link

ilg-ul commented Apr 9, 2024

It's possible to just add C:\msys64\ucrt\bin to the PATH

Depending on the position in the PATH, this might break other programs using different versions of these libraries.

I'm no Windows specialist, so I might be wrong, but I think that the safest location is the same folder as the executable that uses the library.

@TommyMurphyTM1234
Copy link
Collaborator

Two methods for building a Windows toolchain have been shown to work:

  1. Canadian Cross toolchain buid using crosstool-NG on Linux to build a toolchain to run on Windows that generates code for RISC-V
  2. Building natively on Windows using MSYS2

I haven't had time to pursue a third way:

  1. xPack

I will try to look into that at some point but for now I will close this issue as the original question has been addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants