Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

introducing compiler flags as language item #97

Merged
merged 2 commits into from
Jul 20, 2020
Merged

introducing compiler flags as language item #97

merged 2 commits into from
Jul 20, 2020

Conversation

aep
Copy link
Collaborator

@aep aep commented Jul 20, 2020

use like this:

flags {
    linker("-lbla")
}

works with conditionals:

flags if #(os::_WIN32){
    linker("-lW32_bla")
}

eventually macro support will allow generating these from configure tests,
something like:

flags {
  @pkgconfig("gtk")
}

in order to integrate into C conditionals they are emitted as pragma.
but there's really only msvc that supports linker pragmas,
so make also parses them back out of the c file and appends them to the
compiler commandline.

this means export to other build systems becomes slightly inconsistent,
but it would have been that way anyway, because every build system works
differently.

  • make: we can just prepend a -E phase to each compile unit,
  • python and nodejs: same as script.
  • rust: same as buildscript
  • golang: would have never worked anyway. best shot is emit each variant
    as different golang file?
  • cmake: no idea. cmake is complicated

aep added 2 commits July 20, 2020 12:49
use like this:

    flags {
        linker("-lbla")
    }

works with conditionals:

    flags if #(os::_WIN32){
        linker("-lW32_bla")
    }

eventually macro support will allow generating these from configure tests,
something like:

    flags {
      @pkgconfig("gtk")
    }

in order to integrate into C conditionals they are emitted as pragma.
but there's really only msvc that supports linker pragmas,
so make also parses them back out of the c file and appends them to the
compiler commandline.

this means export to other build systems becomes slightly inconsistent,
but it would have been that way anyway, because every build system works
differently.

- make: we can just prepend a -E phase to each compile unit,
- python and nodejs: same as script.
- rust: same as buildscript
- golang: would have never worked anyway. best shot is emit each variant
  as different golang file?
- cmake: no idea. cmake is complicated
using c conditionals is more consistent,
and the variants never really worked anyway across library boundaries
@aep aep mentioned this pull request Jul 20, 2020
@jwerle jwerle added the enhancement New feature or request label Jul 20, 2020
@jwerle jwerle added this to the Build Script milestone Jul 20, 2020
@jwerle
Copy link
Member

jwerle commented Jul 20, 2020

This looks great! Is it possible to add a test?
re: variants/features - I never had a chance to look at it, what was the point of it?

@jwerle jwerle linked an issue Jul 20, 2020 that may be closed by this pull request
@aep
Copy link
Collaborator Author

aep commented Jul 20, 2020

not sure how to add a test, because that would have to link something.
async will use this, so i think its fine.

features where a direct copy of rust features. each module can define something like "with_gtk" and use that as conditional like if (with_gtk) { init_gtk.}
but since those are resolved at parsetime, you would end up emitting non portable c code. what we do now is much better, since it delays the conditional choice to the c compiler. the exported C code now works for all variants.

@aep aep merged commit 014be6f into master Jul 20, 2020
@aep aep deleted the flags branch July 20, 2020 12:01
@jwerle
Copy link
Member

jwerle commented Jul 20, 2020

Good point and amazing!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

macros in Build Scripts
2 participants