crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.48k stars 1.62k forks source link

MIPS cross-compile failed #4529

Closed artem-a closed 2 years ago

artem-a commented 7 years ago

Hi all!

I'm trying to compile a simple web application like "hello, world!" for MIPS architecture

app.cr
require "kemal"

get "/" do
  "hello, world! the time is #{Time.now}"
end

Kemal.run 8080

I use the command crystal build app.cr --cross-compile --target "mips-linux-gnu" also tried the command crystal build app.cr --cross-compile --target "mips-unknown-linux-gnu"

but I get an error Unsupported arch for target triple: mips-linux-gnu or Unsupported arch for target triple: mips-unknown-linux-gnu

Crystal compiler version Crystal 0.22.0 [3c71228] (2017-04-20) LLVM 3.5.0

OS version Linux xbnt-vm 4.8.0-36-generic #36~16.04.1-Ubuntu SMP Sun Feb 5 09:39:57 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Thanks.

akzhan commented 7 years ago

MIPS is not supported yet (take a look at https://github.com/crystal-lang/crystal/blob/master/src/compiler/crystal/codegen/target_machine.cr#L22).

We need to add MIPS ABI class to get it compiled.

akzhan commented 7 years ago

Crystal ABIs built using https://github.com/rust-lang/rust/tree/master/src/librustc_trans as source of implementation, but I have no any MIPS to test :)

https://github.com/crystal-lang/crystal/blob/master/src/llvm/abi/arm.cr

RX14 commented 7 years ago

You can test new architectures without hardware using QEMU. Obviously they should be validated on real hardware by the community at least once before merging.

artem-a commented 7 years ago

@akzhan Do you plan to add MIPS architecture in future?

akzhan commented 7 years ago

Have not seen it https://github.com/crystal-lang/crystal/wiki/Roadmap

But it should be easy to add.

ysbaddaden commented 7 years ago

Porting Crystal is a multi stage process. It's rarely easy, and sometimes very hard, especially when introducing a new architecture (e.g. the ARM EABI port was hard).

  1. add an ABI class for each new arch (e.g. MIPS, MIPS64, ...);
  2. add lib C bindings for each arch+sys+libc combination (e.g. mips-linux-gnu);
  3. write arch-specific ASM for fiber context switches;
  4. sometimes fix issues personalities to unwind the stack and raise exceptions;
  5. fix failures, errors (sometimes segfaults) in specs;

Supporting MIPS wasn't on my personnal radar for different reasons, the most important being that MIPS seems mostly used in embedded systems with (very) limited memory, which Crystal ain't really aiming at —the language could, but the core/stdlib won't.

But maybe my assumption is wrong?

artem-a commented 7 years ago

@ysbaddaden

Thank you! Got your point, though the crystal language provides the following very suitable for the MIPS architecture:

And this makes crystal a very good match for embedded systems.

RX14 commented 7 years ago

@artem-a when you say "embedded" what kind of ram/os do you mean? I suspect @ysbaddaden is thinking of microcontrollers with RAM measured in the single megabytes or kilobytes which are incapable of running linux. Obviously that's not true for all embedded systems.

artem-a commented 7 years ago

@RX14 OS OpenWRT, RAM 32/64/128 Mb mostly routers.

drhuffman12 commented 7 years ago

I would imagine that Crystal on OpenWRT would be a nice [and faster but probably not smaller] alternative to using mruby.

ysbaddaden commented 7 years ago

With careful memory usage, it sounds possible to run a crystal app on MIPS, as long as GC can run.

I don't think I'll work on this anytime soon. If someone is motivated enough, steps are above :)

Cyan101 commented 7 years ago

I have a MIPS system with 200MB, would be great to run crystal on it since at 200mbs ram (and then the OS and other programs leave little remaining) running Ruby isn't really an option

IridescentRose commented 4 years ago

Alright @ysbaddaden my question is that does it need to be for every single MIPS architecture? I.E., if I wish to port one of them, do I need to write an ABI for all of them, even if my specific use case is one MIPS architecture? Currently I'm looking at mipsel-unknown-none as my target on MIPS2.

IridescentRose commented 4 years ago

Never mind my previous post, I've figured it out for myself. Thank you, and sorry for bothering.

straight-shoota commented 2 years ago

Closing. There is nothing actionable here.

This is not discounting MIPS support - we would like to get that eventually. But it makes no sense to keep issues open for every unsupported target.

If you're interested in working on support for a new target, please start with an informal discussion at https://forum.crystal-lang.org/