Commit Graph

58 Commits

Author SHA1 Message Date
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 76198edc79
Fixed dangling symlinks in builds (#656) 2021-06-01 13:59:16 -07:00
UebelAndre 4010620160
Fix RBE by using updated bazel-toolchains version (#654) 2021-05-21 19:40:34 +01:00
UebelAndre 66cd7dc9d4
Revert "Include `libtool` and `.nice` files when replacing sandbox paths (#644)" (#648)
This reverts commit 0859891060.
2021-05-16 22:53:04 +01:00
UebelAndre 0859891060
Include `libtool` and `.nice` files when replacing sandbox paths (#644) 2021-05-12 14:00:42 -07:00
UebelAndre 62fcc5f143
Fixed silent failures replacing sandbox paths in outputs (#635) 2021-05-09 06:18:25 +01:00
James Sharpe b136e6c52d
Add config for building with spawn_strategy=standalone (#603)
* Add config for building with spawn_strategy=standalone

* Always build RELEASE configuration to avoid having to select for the output due to change in artifact names for debug builds

* Fix for copy_contents_to_dir and symlink_contents_to_dir on macOS as per #512

* Update name of test files
2021-05-05 17:47:25 -07:00
UebelAndre 4eb5c5c0c2
Added a new `platform_info` target to the foreign_cc framework (#629)
* Added a new `platform_info` target to the foreign_cc framework

* Update foreign_cc/private/framework/platform.bzl

Co-authored-by: James Sharpe <james.sharpe@zenotech.com>

Co-authored-by: James Sharpe <james.sharpe@zenotech.com>
2021-05-05 21:35:54 +01: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 1bd2a8c547
Refactored framework to avoid polymorphism complexity (#612)
* Refactored framework to be less complex

* Deleted default commands (aka 'stale linux commands')

* Restored toolchain name
2021-04-30 17:03:32 +01:00
UebelAndre a2ec6c0d26
Fixed provider name which was violating naming conventions (#620) 2021-04-23 17:11:13 +00: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 83e6cf48cf
Moved `workspace_definitions.bzl` to `foreign_cc/repositories.bzl` to solve for bzl-visibility issues. (#557) 2021-03-12 09:08:13 -08: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 c309ec1319
Enable testing on RBE (#525)
* Enable testing on RBE

* Attempting to fix ninja example on RBE

* Disable targets that aren't currently working on RBE
2021-03-09 13:28:28 -08:00
UebelAndre 175b29c6f7
Renamed BUILD files to BUILD.bazel (#540)
* Renamed BUILD files to BUILD.bazel

* Ran Buildifier
2021-03-03 10:08:03 -08:00
UebelAndre e285764b78
Restructed examples and enabled more testing (#515)
* Reorganized examples

* Documentation

* Third party
2021-02-26 20:21:13 +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 87df6b25f6
Fixed unbound variable in commands and recursive symlinks (#514)
* Fixed unbound variables

* Fixed MacOS recursive symlinks
2021-02-22 20:28:41 +00:00
James Sharpe 9a4435ecab
Attempt to catch shell script errors proactively with 'set -euo pipef… (#500)
* Attempt to catch shell script errors proactively with 'set -euo pipefail'

* Fix up uninitialised variable use

* Fix osx shell function

* Fix to unbound variable in windows commands
2021-02-16 11:55:48 -08:00
James Sharpe f77a9e12a3
Propagate defines into CFLAGS and CXXFLAGS passed to the framework (#498)
* Propagate defines into CFLAGS and CXXFLAGS passed to the framework

* Fix flags test

* Add example to test propagation of defines
2021-02-09 12:56:20 -08:00
Attila Oláh 466c32c70f
Build under Bazel sandbox instead of /tmp (#479)
* Build under bazel sandbox instead of /tmp, and remove redundant printf

Build artifacts under /tmp are not cleaned up after a failed build, for
the ease of debugging.  However, this can quickly fill up the /tmp partition
if the build is large.  Build under the sandbox directory instead, and
rely on standard bazel cleanup scheme.

Also remove a print from the cleanup function, which somehow causes empty
newlines to be printed in bazel build output.

* Avoid infinite recursion in symlink_to_dir.

This is a somewhat hackish approach to exclude *.ext_build_deps from
symlinks when creating the symlink forest. This is necessary in cases
where an entire directory is added to the includes, e.g. when setting
includes = ["."] where the directory itself contains a cmake_external()
rule that depends on the very rule containing the includes = ["."].

* Also avoid using a temp directory when bootstrapping make or cmake itself.

* Remove the ##tmpdir## shell toolchain command.

It is no longer necessary now that all its uses are gone.

Co-authored-by: Lauri Peltonen <lape@iki.fi>
2021-02-05 13:29:07 +00:00
UebelAndre 743975a998
Fixed incorrect detection of lib_source root (#488)
* Cleanup

* Fixed incorrect detection of lib_source root

* Updated tests
2021-02-03 20:18:43 +00: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
Fumitoshi Ukai 78dd474994
support filename containing space (#416)
handle filename containg space.
cmake prebuilt archive contains such filename in docs etc.

also fix symlink to a directory. [ -L "$1" ] returns success
for it, but it would fail "cp $1 $2" as
 cp: -r not specified; omitting directory ...

Fixes: #405, #406

Co-authored-by: UebelAndre <andre.brisco@gmail.com>
2021-01-31 07:43:03 -08:00
UebelAndre 898bed4efb
Enable Buildifier in CI (#458)
* Added Buildifier check to CI

* Addressed Buildifier lint defects
2021-01-25 22:01:43 +00:00
UebelAndre 9b6a8f675c
Add tests for checking the minimum supported version to CI (#469) 2021-01-25 19:07:05 +00:00
UebelAndre 76870e532d
Updated uses of `@bazel_tools//src/conditions` to `@platforms//` (#465)
Co-authored-by: James Sharpe <james.sharpe@zenotech.com>
2021-01-25 08:01:46 -08:00
James Sharpe 30912b9982
Buildifier formatting (#459) 2021-01-22 06:17:24 -08:00
irengrig 74b146dc87
Fix shell function symlink_contents_to_dir, add test (#377)
Fix shell function symlink_contents_to_dir, add test

- test for the case when we symlink the contents of two directories with the same inner directories (include)
- the test data of the test for shell script helper also changes, as it uses the real shell toolchain implementation text
- Fixes the issue from #330
2020-05-08 11:43:40 +02: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 3515b20a24
Fix shell_script_helper.bzl to replace function calls inside function… (#375)
Fix shell_script_helper.bzl to replace function calls inside function texts.

Add test for shell_script_helper.bzl.
In particular, this fixes the case when some of the shell toolchain functions calls other shell toolchain functions (symlink_contents_to_dir and symlink_to_dir).
2020-04-30 11:24:25 +02:00
irengrig 2ca2de6752
Test for detect_root function and example of usage (#373) 2020-04-30 11:17:48 +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
irengrig dea1437d92
Fix #123 Improve code readability for collecting input dependencies (#257)
* Fix #123 Improve code readability for collecting input dependencies

* Fix line endings
2019-06-19 15:50:58 +02:00
László Csomor 9cfeff53b5 Windows: tests now work with native test wrapper (#263)
Windows: tests now work with native test wrapper

See https://github.com/bazelbuild/bazel/issues/6622
2019-05-17 11:52:28 +02:00
Marcel Hlopko 50e2679dee Migrate for --incompatible_enable_cc_toolchain_resolution (#262)
https://github.com/bazelbuild/bazel/issues/7260
2019-05-15 14:43:13 +02:00
irengrig bf99a0bf00
Fix #254 (Linker flags passed to ar). (#256)
Fix #254 (Linker flags passed to ar).
2019-05-10 15:49:21 +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 f00cd27f06
Pass --copt, --cxxopt, --conlyopt, --linkopt to cmake_external/configure_make rules (#235)
- explicitly pass the values of these options to corresponding compilation/link flags lists; add them to the end of the lists of they are not already there
- please see the test in test/standard_cxx_flags_test
2019-03-11 16:50:39 +01: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 4999ececdb
Fix shell script conversion bug + test (#220) 2019-02-04 19:53:44 +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