zig icon indicating copy to clipboard operation
zig copied to clipboard

Add option to specify language of CSourceFiles

Open GalaxyShard opened this issue 1 year ago • 4 comments

Closes #20655 (without the proposed breaking changes)

The addCSourceFile functions gain an optional language field which defaults to the current behavior (find the language by the file extension of each input).

This does not add support for any new languages beyond what addCSourceFile already supports: the C languages and assembly.

GalaxyShard avatar Jul 20 '24 04:07 GalaxyShard

I have a similar commit in #17956: https://github.com/ziglang/zig/pull/17956/commits/650a335befc37dd54dda7fc90c0ac5e03169768c

The main difference is that I don't put the -x flag inside the --cflags ... -- section since it is recognized by zig. But I don't know which one is correct/best...

xxxbxxx avatar Jul 22 '24 07:07 xxxbxxx

I have a similar commit in #17956: 650a335

The main difference is that I don't put the -x flag inside the --cflags ... -- section since it is recognized by zig. But I don't know which one is correct/best...

Actually the -x flag is outside of the cflags section in this PR as well, so it gets handled by src/main.zig instead of getting passed as a C flag.

I did notice though, in your PR there is no -x none after the source files were added. If I'm not mistaken, doing addCSourceFile once specifying a language (lets say C), then doing another addCSourceFile not specifying a language, would result in both files being forced to compile as a C file, even if the second file is C++ or something else.

GalaxyShard avatar Jul 22 '24 18:07 GalaxyShard

I have a similar commit in #17956: 650a335 The main difference is that I don't put the -x flag inside the --cflags ... -- section since it is recognized by zig. But I don't know which one is correct/best...

Actually the -x flag is outside of the cflags section in this PR as well, so it gets handled by src/main.zig instead of getting passed as a C flag.

ah my bad, I casually read the diff in the web interface and misread.

I did notice though, in your PR there is no -x none after the source files were added. If I'm not mistaken, doing addCSourceFile once specifying a language (lets say C), then doing another addCSourceFile not specifying a language, would result in both files being forced to compile as a C file, even if the second file is C++ or something else.

You're right! thanks.

xxxbxxx avatar Jul 24 '24 07:07 xxxbxxx

Is there anything that needs to be done before merging? Thanks.

GalaxyShard avatar Jan 28 '25 22:01 GalaxyShard