-
Notifications
You must be signed in to change notification settings - Fork 0
Implement swift functions in Bazel [BUILD-317] #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c4094a6
Implement swift functions in Bazel [BUILD-317]
krisukox ac5d0f9
Add data to swift_cc_test and format
krisukox 3716897
Set default c version to gnu99
krisukox 95e9691
Turn on Werror and remove default c and c++ standards
krisukox e65e4b5
Remove rtti and -Wmissing-include-dirs
krisukox 4ea3228
Remove compile flags from swift_cc_test
krisukox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,233 @@ | ||
| def swift_get_compile_options( | ||
| exceptions = None, | ||
| rtti = None, | ||
| warning = None, | ||
| add_compile_options = None, | ||
| remove_compile_options = None, | ||
| cxx_standard = None, | ||
| c_standard = None): | ||
| if add_compile_options == None: | ||
| add_compile_options = [] | ||
| if remove_compile_options == None: | ||
| remove_compile_options = [] | ||
|
|
||
| for flag in add_compile_options + remove_compile_options: | ||
| if flag == "-fexceptions": | ||
| fail("Do not specify -fexceptions directly, use 'exceptions' argument instead") | ||
| if flag == "-fno-exceptions": | ||
| fail("Do not specify -fno-exceptions directly, avoid 'exceptions' argument instead") | ||
| if flag == "-frtti": | ||
| fail("Do not specify -frtti directly, use 'rtti' argument instead") | ||
| if flag == "-fno-rtti": | ||
| fail("Do not specify -fno-rtti directly, avoid 'rtti' argument instead") | ||
| if flag == "-Wno-error": | ||
| fail("Do not specify -Wno-error directly, use 'warning' to disable -Werror") | ||
|
|
||
| all_flags = [] | ||
|
|
||
| if not warning: | ||
| all_flags += ["-Werror", "-Wno-error=deprecated-declarations"] | ||
|
|
||
| # '-Wall' '-Wunused-but-set-parameter' '-Wno-free-nonheap-object' flags are set by default by bazel | ||
| all_flags += [ | ||
| "-Wcast-align", | ||
| "-Wcast-qual", | ||
| "-Wchar-subscripts", | ||
| "-Wcomment", | ||
| "-Wconversion", | ||
| "-Wdisabled-optimization", | ||
| "-Wextra", | ||
| "-Wfloat-equal", | ||
| "-Wformat", | ||
| "-Wformat-security", | ||
| "-Wformat-y2k", | ||
| "-Wimplicit-fallthrough", | ||
| "-Wimport", | ||
| "-Winit-self", | ||
| "-Winvalid-pch", | ||
| "-Wmissing-braces", | ||
| "-Wmissing-field-initializers", | ||
| # "-Wmissing-include-dirs", | ||
| "-Wparentheses", | ||
| "-Wpointer-arith", | ||
| "-Wredundant-decls", | ||
| "-Wreturn-type", | ||
| "-Wsequence-point", | ||
| "-Wshadow", | ||
| "-Wsign-compare", | ||
| "-Wstack-protector", | ||
| "-Wswitch", | ||
| "-Wswitch-default", | ||
| "-Wswitch-enum", | ||
| "-Wtrigraphs", | ||
| "-Wuninitialized", | ||
| "-Wunknown-pragmas", | ||
| "-Wunreachable-code", | ||
| "-Wunused", | ||
| "-Wunused-function", | ||
| "-Wunused-label", | ||
| "-Wunused-parameter", | ||
| "-Wunused-value", | ||
| "-Wunused-variable", | ||
| "-Wvolatile-register-var", | ||
| "-Wwrite-strings", | ||
| ] | ||
|
|
||
| if remove_compile_options: | ||
| for flag in remove_compile_options: | ||
| if not flag in all_flags: | ||
| fail("Compiler flag '%s' specified for removal is not part of the set of common compiler flags" % flag) | ||
| all_flags.remove(flag) | ||
|
|
||
| all_flags += add_compile_options | ||
|
|
||
| if exceptions: | ||
| all_flags.append("-fexceptions") | ||
| else: | ||
| all_flags.append("-fno-exceptions") | ||
|
|
||
| if cxx_standard: | ||
| all_flags.append("-std=c++" + cxx_standard) | ||
|
|
||
| if c_standard: | ||
| all_flags.append("-std=c" + c_standard) | ||
|
|
||
| return all_flags | ||
|
|
||
| def swift_cc_library( | ||
| name, | ||
| srcs = None, | ||
| hdrs = None, | ||
| includes = None, | ||
| textual_hdrs = None, | ||
| visibility = None, | ||
| deps = None, | ||
| add_compile_options = None, | ||
| remove_compile_options = None, | ||
| cxx_standard = None, | ||
| c_standard = None): | ||
| if add_compile_options == None: | ||
| add_compile_options = [] | ||
| add_compile_options.append("-pedantic") | ||
| copts = swift_get_compile_options( | ||
| add_compile_options = add_compile_options, | ||
| remove_compile_options = remove_compile_options, | ||
| cxx_standard = cxx_standard, | ||
| c_standard = c_standard, | ||
| ) | ||
| native.cc_library( | ||
| name = name, | ||
| srcs = srcs, | ||
| hdrs = hdrs, | ||
| copts = copts, | ||
| deps = deps, | ||
| visibility = visibility, | ||
| includes = includes, | ||
| textual_hdrs = textual_hdrs, | ||
| ) | ||
|
|
||
| def swift_cc_tool_library( | ||
| name, | ||
| srcs = None, | ||
| hdrs = None, | ||
| includes = None, | ||
| textual_hdrs = None, | ||
| visibility = None, | ||
| deps = None, | ||
| add_compile_options = None, | ||
| remove_compile_options = None, | ||
| cxx_standard = None, | ||
| c_standard = None): | ||
| copts = swift_get_compile_options( | ||
| add_compile_options = add_compile_options, | ||
| remove_compile_options = remove_compile_options, | ||
| cxx_standard = cxx_standard, | ||
| c_standard = c_standard, | ||
| ) | ||
| native.cc_library( | ||
| name = name, | ||
| srcs = srcs, | ||
| hdrs = hdrs, | ||
| copts = copts, | ||
| deps = deps, | ||
| visibility = visibility, | ||
| includes = includes, | ||
| textual_hdrs = textual_hdrs, | ||
| ) | ||
|
|
||
| def swift_cc_binary( | ||
| name, | ||
| srcs = None, | ||
| hdrs = None, | ||
| includes = None, | ||
| visibility = None, | ||
| deps = None, | ||
| add_compile_options = None, | ||
| remove_compile_options = None, | ||
| cxx_standard = None, | ||
| c_standard = None): | ||
| if add_compile_options == None: | ||
| add_compile_options = [] | ||
| add_compile_options.append("-pedantic") | ||
| copts = swift_get_compile_options( | ||
| add_compile_options = add_compile_options, | ||
| remove_compile_options = remove_compile_options, | ||
| cxx_standard = cxx_standard, | ||
| c_standard = c_standard, | ||
| ) | ||
| native.cc_binary( | ||
| name = name, | ||
| srcs = srcs, | ||
| hdrs = hdrs, | ||
| copts = copts, | ||
| deps = deps, | ||
| visibility = visibility, | ||
| includes = includes, | ||
| ) | ||
|
|
||
| def swift_cc_tool( | ||
| name, | ||
| srcs = None, | ||
| hdrs = None, | ||
| includes = None, | ||
| visibility = None, | ||
| deps = None, | ||
| add_compile_options = None, | ||
| remove_compile_options = None, | ||
| cxx_standard = None, | ||
| c_standard = None): | ||
| copts = swift_get_compile_options( | ||
| add_compile_options = add_compile_options, | ||
| remove_compile_options = remove_compile_options, | ||
| cxx_standard = cxx_standard, | ||
| c_standard = c_standard, | ||
| ) | ||
| native.cc_binary( | ||
| name = name, | ||
| srcs = srcs, | ||
| hdrs = hdrs, | ||
| copts = copts, | ||
| includes = includes, | ||
| visibility = visibility, | ||
| deps = deps, | ||
| ) | ||
|
|
||
| def swift_cc_test( | ||
| name, | ||
| srcs = None, | ||
| hdrs = None, | ||
| data = None, | ||
| includes = None, | ||
| visibility = None, | ||
| deps = None, | ||
| add_compile_options = None): | ||
| native.cc_test( | ||
| name = name, | ||
| srcs = srcs, | ||
| hdrs = hdrs, | ||
| copts = add_compile_options, | ||
| data = data, | ||
| includes = includes, | ||
| visibility = visibility, | ||
| deps = deps, | ||
| ) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I commented out
-Wmissing-include-dirsbecause gcc-11 (this is not the case with clang-14) complains when e.g.includedirectory "inherited" from theswiftnavlibrary is not valid for theixcomlibrary.I tried to workaround it with the
-Iflag but I couldn't find a solution. We should probably create a ticket about it.