vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.78k stars 2.16k forks source link

How to cross compile by cross compiler? #15425

Open likema opened 2 years ago

likema commented 2 years ago

Hi,

I have a cross compiler powerpc64le-rhel7-linux-gnu-gcc.

How to cross-compile V source file by this cross compiler?

Thanks.

JalonSolov commented 2 years ago

V doesn't (currently) support ppc, so you will need to do a 2-step process.

First, compile V to C: v -o name.c name.v

Then, compile the C file as you normally would powerpc64le-rhel7-linux-gnu-gcc -o name name.c

Or whatever your favorite options may be.

I would also recommend updating your OS to something more recent... rhel 9 has been our for several months.

likema commented 2 years ago

But name.c depends on libgc.a .

Does it need to be built manually?

likema commented 2 years ago

Will the V dev team plan to support this kind of cross-build scenario?

larpon commented 2 years ago

In general we'll need support from the community to be able to implement and maintain these kinds of lesser known targets. So if anyone reads this and is capable of fixing it, please chip in.

ylluminate commented 2 years ago

@harens & @barracuda156, would you be interested in collaborating with @likema on this due to your involvement also in PPC hardware?

barracuda156 commented 2 years ago

@ylluminate From what I understand, ppc64le is substantially different from ppc and ppc64 on Darwin, but I am interested in the topic. Thank you for tagging me.

likema commented 2 years ago

@ylluminate From what I understand, ppc64le is substantially different from ppc and ppc64 on Darwin, but I am interested in the topic. Thank you for tagging me.

Yes, ppc64le is an architecture of Power 8/9 on Linux.

likema commented 2 years ago

Not only ppc64le, but also loongarch64 cross-compile need to be supported.

I suggest something is similar with CMake toolchain file:

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR ppc64le)
set(CMAKE_C_COMPILER powerpc64le-rhel7-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER powerpc64le-rhel7-linux-gnu-g++)
barracuda156 commented 2 years ago

@likema By the way, why cross, why not build natively?

likema commented 2 years ago

@likema By the way, why cross, why not build natively?

For saving cost

barracuda156 commented 2 years ago

@likema By the way, why cross, why not build natively?

For saving cost

@likema But does it build natively? For ppc it does. ppc64 not sure.

By the way, I am interested to implement ppc64 support, if it is lacking. Primarily for BE, but LE should be easier in fact.

likema commented 2 years ago

By the way, I am interested to implement ppc64 support, if it is lacking. Primarily for BE, but LE should be easier in fact.

Thanks.

I also have powerpc64-rhel6-linux-gnu-gcc , which is big endian.

All of my cross compilers are built on Linux x86_64 by crosstool-ng

barracuda156 commented 2 years ago

V doesn't (currently) support ppc, so you will need to do a 2-step process.

@JalonSolov It actually builds on PPC systems (ppc32 at least): https://trac.macports.org/ticket/64913

JalonSolov commented 2 years ago

Should have said - it doesn't currently support cross-compiling to ppc. If you can run it natively, it'll be fine... but the question was specifically about cross-compiling.