cyclone icon indicating copy to clipboard operation
cyclone copied to clipboard

Allow programs to use (c-linker-options ...)

Open justinethier opened this issue 4 years ago • 11 comments

Arthur asked a good question:

why does (c-linker-options ...) only work with library definitions? Would it be too difficult to allow programs to use it too? I really found it elegant to use scheme code instead of passing flags to the command line and consequently depending other script language to automate compilation.

This is a good idea and should be possible. We would just need to treat c-linker-options as a special top-level form for compiled programs, similar to import.

justinethier avatar Apr 30 '20 13:04 justinethier

I think it would be quite useful to have a (c-compiler-options ...) too, both on libraries and programs. What do you think, @justinethier?

arthurmaciel avatar Jun 18 '20 02:06 arthurmaciel

Boch (c-linker-options ...) and (c-compiler-options ...) would be useful for porting C libs. Maybe also a flag to the compiler would be useful. @justinethier, what do you think?

arthurmaciel avatar Jan 16 '21 22:01 arthurmaciel

@arthurmaciel I agree. We can add c-compiler-options as another library form and both as compiler forms.

I need to look at adding these to the compiler. It seems like both should be trivial to add but I think there is a bit more work involved. Let me add this to the roadmap for upcoming development.

justinethier avatar Jan 17 '21 16:01 justinethier

It would also be helpful to have a -COPT or such option to specify the C compiler options from the command line.

justinethier avatar Jan 18 '21 03:01 justinethier

Added -COPT and the c-compiler-options expression for libraries.

Still need to add support for specifying options from a program.

justinethier avatar Jan 18 '21 15:01 justinethier

Updated to allow both c-linker-options and c-compiler-options to work at the top-level of a program.

justinethier avatar Jan 18 '21 21:01 justinethier

Hi @justinethier!

Could you help me find what I am missing?

In t.scm:

(import (scheme base)
        (scheme write)
        (cyclone foreign))

(c-compiler-options "-I/tmp")

(display "hello")
$ cyclone t.scm  # version 0.34.0
Error: Unbound variable(s): 
(c-compiler-options)

arthurmaciel avatar Jun 26 '22 14:06 arthurmaciel

That's a good question @arthurmaciel - this should work. Let me reopen this issue and look into it.

justinethier avatar Jun 26 '22 15:06 justinethier

@arthurmaciel In the meantime this hack will at least let you keep moving, but this is not the long-term solution:

(c-compiler-options "-I/tmp")                                                     
(define c-compiler-options list)                                                 

justinethier avatar Jun 26 '22 15:06 justinethier

Thanks, Justin. Unfortunately the hack doesn't work here (now using cyclone 0.35.0).

(import (scheme base)
        (scheme write)
        (cyclone foreign))

(c-compiler-options "-I/tmp") 
(define c-compiler-options list)

(display "hello")
$ cyclone t.scm
$ ./t
[1]    88020 segmentation fault (core dumped)  ./t

arthurmaciel avatar Jun 26 '22 15:06 arthurmaciel

@arthurmaciel Alright, this is fixed on the master branch now. This was broken by the changes to have cyclone call itself as a subprocess before invoking the C compiler. Let me see if I can add a test case to ensure this continues to work going forward...

justinethier avatar Jun 26 '22 22:06 justinethier