Commit Graph

28 Commits

Author SHA1 Message Date
jheaff1 33bce66655
Absolutise path to cmake crosstool file (#870) 2022-02-09 23:15:54 +00:00
jheaff1 7205619704
Ensure Windows paths used by CMake contain forward slashes only (#807) 2021-11-22 19:53:28 +00:00
James Sharpe bad4ab0c3d
Fix quoting for cmake (#703) 2021-07-28 18:12:53 +01:00
Attila Oláh fccd4ddaeb
Fix tool_prefix for CMake (#686)
* Fix tool_prefix for CMake.

Set the prefix before the first CMake invocation (where all the extra
flags are passed), and don't set the prefix for the `--build` and
`--install` invocations of CMake.

Fixes #685.

* Update test/cmake_text_tests.bzl

Co-authored-by: UebelAndre <github@uebelandre.com>
2021-06-16 21:55:02 +00:00
UebelAndre 923cd88ed4
Added new foreign_cc framework commands: (#628)
- enable_tracing
- disable_tracing
- script_extension
- shebang
2021-04-30 13:26:23 -07:00
UebelAndre c734ca8446
Replaced uses of `export ` with `##export_var##` (#614) 2021-04-19 15:37:56 +01:00
Danny Wolf b6135adb24
Fix string escaping for cmake and configure/make (#567)
* Fix string escaping for cmake and configure/make

Use raw strings where possible to make readability slightly less maddening.

* Example usage of __TIME__

* Allow expansion of environment variables in HEREDOC for cmake crosstool

* Add compile check that __TIME__ is correctly redacted

* Ran buildifier

* Remove comment that is now invalid

Co-authored-by: James Sharpe <james.sharpe@zenotech.com>
2021-04-15 16:44:41 -07:00
James Sharpe ede2c80a51
Keep lines of scripts as a list of commands until script creation (#572)
This reduced the large amount of `"\n".join()` calls
2021-03-17 14:50:25 -07:00
UebelAndre e4399415b8
Added "targets" API (#556)
* Added `targets` API to all existing build rules

* Updated examples

* Restore making the make toolchain always available.

* Add support for generator cmake parsing and setting CMAKE_MAKE_PROGRAM

* Cleaned up duplicate generator arguments

* Fixed cmake tests

* Updated docs

* Addressed PR feedback

* Fixed missing and incorrect generators

* Fixed `generate_args` name
2021-03-17 13:42:44 +00:00
UebelAndre edbfa3bfa9
Restructured rules to match architecture (#555)
* Restructured rules to match architecture

* Added exports of all symbols in the deprecated location for legacy support

* Updated examples
2021-03-12 16:54:14 +00:00
James Sharpe 4520018bc2
Make generate_crosstool=True the default for cmake. (#523)
This was previously setting `CMAKE_SYSTEM_NAME` in the generated
toolchain file but setting this explicitly enables `CMAKE_CROSSCOMPILING`
(see https://cmake.org/cmake/help/v3.19/variable/CMAKE_CROSSCOMPILING.html#variable:CMAKE_CROSSCOMPILING)
which breaks projects that use `TRY_RUN`
2021-02-24 14:45:36 -08:00
UebelAndre 14520d220f
Made buildifier checks more aggressive (#485)
* Made buildifier checks more aggressive

* Ran buildifier to fix all warnings

* Added sorting to cmake script generation and updated tests
2021-02-02 20:09:33 +00:00
Laurent Le Brun c292369597
Fix Buildifier warnings (#395)
* Run buildifier formatter

* Fix buildifier warnings

Ran: `buildifier --lint=fix -r .`
2020-05-04 19:50:45 +02:00
irengrig 30f398dc40
Fix a way of wiping CMake cache entry values defined by toolchain fro… (#293)
* Fix a way of wiping CMake cache entry values defined by toolchain from a command line, in case user specified empty values for these cache entries explicitly in cmake_external target

- it was a problem that we did not check that there was some value in the "toolchain" dict before we pop() - reported in comment in #292
- make code which does wiping empty values more explicit

* Additionally, if non-empty value for CMAKE_RANLIB was not specified by user or Bazel toolchain, put empty value for it to forbid CMake to auto detect it

context: https://github.com/bazelbuild/rules_foreign_cc/issues/252

* Add test for user's redefined value for CMAKE_BUILD_TYPE
2019-07-17 13:51:21 +02:00
Justin Buchanan d084070466 fix(cmake): Use "Debug" and "Release" instead of "DEBUG" and "RELEASE" (#277)
* fix(cmake): Use "Debug" and "Release" instead of "DEBUG" and "RELEASE"

These values are case-sensitive in cmake and give this error currently:

```
CMake Error at CMakeLists.txt:23 (message):
  CMAKE_BUILD_TYPE must be one of: Debug, Release (current value: 'RELEASE')
```

* update test data
2019-06-21 10:40:01 +02:00
László Csomor 5f9879c7ec Windows, tests: fix for native test wrapper (#246)
* Windows, tests: fix for native test wrapper

In this PR:

- Update `@bazel_skylib` to 0.8.0, which has a
  Windows-compatible unittest.bzl

- Fix unittest-using tests. Correct usage of
  `unittest.end(env)` is to return its value.

Result: //test:all now passes with Bazel 0.25.0rc3
and --incompatible_windows_native_test_wrapper

* Register Skylib toolchains

* rules_foreign_cc_dep registers unittest toolchains

* Address review comments

* Add bazel_skylib_workspace to WORKSPACE files

* Remove stale toolchain init code
2019-04-30 16:50:26 +03:00
irengrig d8e78e4cf0
cmake_external: allow user to suppress computed cache entries (#224)
If the user passes empty string for some cache entry, for instance,
CMAKE_BUILD_TYPE, then the corresponding computed value
(computed from the Bazel's build type or Bazel C/C++ toolchain)
should not be used.
I.e., user passes "CMAKE_BUILD_TYPE": "", and there will be no
-DCMAKE_BUILD_TYPE in the cmake call.
2019-02-07 17:11:23 +01:00
irengrig c51480261c
Extract shell fragments into a toolchain (#196)
* Extract shell fragments into a toolchain

Construct script in framework.bzl using special notation for calling
shell fragments, defining and referencing environment variables;
have the script converted from this special notation into a real script
(see README.md notes.)
The special notation is used to keep script construction in code still readable.

Tools scripts (cmake, ninja) were also converted.

* Fix reference to environment variables in examples

.. and reference it correctly $$var_name$$ so it is replaced further

* Review comments: documentation, explicitly mark functions from toolchain

- mark functions from shell toolchain as ##funname##, so that they
can not be mixed with usual shell functions

* Fix operating system name for windows in toolchain file

* Additional env vars for windows

* Correct cmake tool build

* Do not build ninja on Windows

* When run on Windows under msys, find utility from Window could "leak"...

into the script. Use heuristics to use /usr/bin/find if it exists.
Also, use pwd -W to get Windows-styled paths (for cmake)
2019-01-18 18:06:10 +01:00
irengrig 99ea1b09fc
Extract cmake and ninja into a toolchain; provide defaults. (#192)
* Extract cmake and ninja into a toolchain; provide defaults.

In the workspace-level rule registration function, default toolchain
implementations are registered for all platforms, which are calling
the cmake and ninja just by name, assuming they are preinstalled.

Also, the user can pass the custom toolchains in the initialization
function, they will be registered before the defaults.

* Do not run ninja build test for now without nested workspaces support

* Corrections after merge

* Always build ninja from sources for tests, correct initialization order

* Add example of using prebuilt artefact in the native tools toolchain.

* Review comments, have native_tool_toolchain#target, not label

+ improve documentation

* Correct ninja toolchain label

* Correct documentation in native_tools_toolchain.bzl
2019-01-08 12:25:16 +01:00
irengrig 9a261f7993
Crosstool example + fixes (#174)
* Add crosstool example; does not work with cmake rule yet

the code is taken from Bazel test data (bazel_toolchain_test_data)

* Make crosstool compilation of cmake_external + cc_binary work

To build example, cd examples/cmake_crosstool bazel build //:libhello_test

Changes:
1) Initially suggested in #124: put $EXT_BUILD_ROOT on path, so that relative paths can be resolved by CMake
2) Toolchain tools are references as relative paths, and they themselves refer to external repository with external/ prefix.
This will not work with CMake, as CMake also perform compiler tests and the build is performed in some temp directory.
We need to convert to absolute paths.
I did a trick with checking of $EXT_BUILD_ROOT is defined and then using it as a prefix.
3) I had to change the visibility of the cc-compiler-k8 toolchain to public
4) For CMake crosstool file, CMAKE_C_COMPILER, CMAKE_CXX_COMPILER, CMAKE_AR need to be absolute, so in cases when they are relative and not under external directory, force paths conversion
2018-12-06 18:14:00 +01:00
irengrig f31530ab3d
Fix test (replace cmkae command to actually used in expected) on Mac (#170) 2018-12-05 14:37:44 +01:00
irengrig 348628d18b
Add test for #163 (do not strip quotes when merging flag values) (#167) 2018-12-04 16:08:30 +01:00
irengrig 8dca26ac29
Pass the value of --compilation_mode dbg to the rule and to CMake (#96)
CMAKE_BUILD_TYPE=DEBUG (otherwise RELEASE)
Can be overriden by user passing CMAKE_BUILD_TYPE in cache_entries
2018-09-14 10:18:38 +02:00
irengrig 86ea154cd9
More windows tests corrections (#87)
* Use rlocation for artifact paths in the test shell scripts

* CMake text tests: split into lines to be good with line separators
2018-09-11 13:55:25 +02:00
irengrig bbb4bb8059
Merge CMAKE_PREFIX_PATH, passed by user, with $EXT_BUILD_DEPS (#76)
This allows using locally installed libraries to be found by CMake
+ test
2018-08-31 10:50:38 +02:00
irengrig 8ef43c6f3c
make cmake and ninja build rules be available from util repository (#72) 2018-08-30 17:31:02 +02:00
irengrig 595c9b6d4b
correct CMake script test to use cmake path from workspace definition (#71) 2018-08-30 13:50:12 +02:00
irengrig 515c15a392
Add a feature of generating CMake toolchain file and writing tools and flags information there (#70)
* cmake toolchain files support

* extract cmake script consruction code into a separate file

for further testing

* simplify cmake script creation code

* first four tests for CMake script creation functions

* + move_dict_values_test for CMake script creation functions

* + reverse_descriptor_dict_test for CMake script creation functions

* + toolchain_and_user_values_test for CMake script creation functions

* add create_cmake_script_no_toolchain_file_test for CMake script creation

* do not insert executable linker rule option if it uses cxx compiler

since it would be the same as default
add one more test for command line

* add test for cmake script with toolchain file

* add test for cmake script with toolchain file with user values

* propagate information about target into CMake toolchain file
2018-08-30 13:12:51 +02:00