2
0
Fork 0
mirror of https://github.com/bazel-contrib/rules_foreign_cc synced 2024-11-25 17:31:25 +00:00
Commit graph

107 commits

Author SHA1 Message Date
irengrig e36f3cee8c
Fix using Bazel-built libraries by cmake_external and configure_make (#249)
Fix #232 - enable usage of Bazel-built libraries as dependencies of cmake_external and configure_make.

- fix logic of reading library data described by C/C++ Bazel interface (as CcInfo.linking_context appeared)
- symlink transitive include directories under $EXT_BUILD_DEPS
- gather all possible transitive include directories to pass to CMake, pass transitive include directories to CMAKE_PREFIX_PATH so that the transitive include directories were scanned by CMake
- fix logic of passing transitive libraries into CPPFLAGS (configure_make)
- add test with the chain: Bazel lib -> CMake lib -> Bazel cc_test
- add synthetic configure-make test with the chain: Bazel lib -> configure_make lib -> Bazel cc_test
- also notice, that passed include directories from Bazel C/C++ Sandwich interface are not always existing; for now, make symlinking code resistant to that

see https://www.gnu.org/software/autoconf/manual/autoconf-2.63/html_node/Preset-Output-Variables.html
2019-05-09 10:35:00 +02:00
Dig-Doug e43f5f275a - Fixes a bug where bootstrap options weren't being passed (#245) 2019-05-06 10:30:14 +02:00
irengrig e3f4b5e0bc
remove unneeded -print option from find command (#242) 2019-04-04 13:39:40 +02: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 bcb7a345f7
Remove support for the versions of Bazel before 0.22 (#234)
- as 0.23 is already released
- to have only one variant of framework code
2019-03-11 16:34:56 +01:00
irengrig bb9d86c1f2
Fix generated code to have load statements strictly in the beginning (#231)
make code compatible with --incompatible_bzl_disallow_load_after_statement
2019-03-07 13:35:13 +01:00
irengrig 8648b04460
Correct check for shared library requiring also interface library on win (#226)
originally suggested in #184
2019-02-14 11:18:47 +01:00
bbarnes52 514cb4e0a1 adds bootstrap_options to attribute to allow user to pass command line args to bootstrap.sh (#181) 2019-02-14 11:05:10 +01:00
bbarnes52 02e808a885 removes unused reference (#180) 2019-02-14 10:50:44 +01:00
irengrig 4d73887da8
Improve outputs handling: wrapper script in shell-abstract manner (#223)
* Improve outputs handling: wrapper script in shell-abstract manner

- extract wrapper script creation into a separate function,
- simplify the script and log names, also output the wrapper script text,
- introduce more shell primitives

related to #204

* Correct review comments
2019-02-14 10:00:19 +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 d334e2eec6
For configure_make, allow to run configure in place (#221)
Some configure scripts rely on being called from their parent directory (they call other files as if they are in the same directory). For this case, we should copy/symlink the contents of the directory under our build root, and run configure from there.

New attribute in configure_make rule: "configure_in_place".

Also, add documentation for configure_make.
2019-02-04 20:10:40 +01:00
irengrig 4999ececdb
Fix shell script conversion bug + test (#220) 2019-02-04 19:53:44 +01:00
Dig-Doug fa183dcc1f Hide build output from console (#204)
* Implements redirecting the build command output to a log file and printing it when the build fails.

* - Removed gitignore
2019-02-01 17:39:07 +01:00
irengrig b2ac19e790
Pass through the os_name() from a custom shell toolchain to CMake (#215) 2019-01-31 15:42:37 +01:00
irengrig 91ba4441d2
Register shell toolchain implementations in the correct order and allow customization (#214)
* Register shell toolchain implementations in the correct order

so that the default implementation is the last

* Refactor shell toolchain to allow users register custom shell toolchains.

- define your own shell toolchain file(s) by copying @rules_foreign_cc//tools/build_defs/shell_toolchain/toolchains/impl:linux_commands.bzl,
and modifying the methods.
- create a mapping: a list of ToolchainMapping with the mappings between created file(s) and execution or/and target platform constraints.
- in the BUILD file of some package, call "register_mappings" macro from "@rules_foreign_cc//tools/build_defs/shell_toolchain/toolchains:defs.bzl", passing the mappings and toolchain_type_ = "@rules_foreign_cc//tools/build_defs/shell_toolchain/toolchains:shell_commands"
- in the WORKSPACE file of your main repository, when you initialize rules_foreign_cc, pass the mappings and the package, in which BUILD file you called "register_mappings" macro

* Correct typo
2019-01-31 15:11:28 +01:00
irengrig 4a6fd7fd62
Add default shell toolchain implementation (#213)
assume Linux as a platform name for CMake
2019-01-31 08:27:34 +01:00
irengrig b0feddbcbb
Remove platform specific variables from generic windows toolchain (#211) 2019-01-30 17:49:37 +01:00
irengrig 216ded8acb
Boost rule to use shell toolchain, fixes #202 (#203) 2019-01-19 17:37:57 +01:00
irengrig 5511d9e1fe
Launch at least some Windows tests on CI (#201)
All custom tools (MS Visual Studio) information goes into
windows_commands.bzl
2019-01-18 18:43:37 +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 dff9d0a729
More changes because of incompatible flags (#198) 2019-01-10 13:47:45 +01:00
irengrig 7994b96ff6
Remove incorrect load symbol, this failed in incompatible flags build (#197) 2019-01-09 16:41:56 +01:00
Laurent Le Brun dfd1d815f5 Fixes for Bazel --all_incompatible_changes (#194)
Tested:
  `bazel test //... --nobuild --all_incompatible_changes`
2019-01-08 18:25:04 +01:00
irengrig 4dc369a845
Do not support Bazel before 0.20 (#195) 2019-01-08 18:21:22 +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 ee779e7d9d
Fix create_compilation_context call to match changed Starlark API (#189)
... in Bazel HEAD
2019-01-03 10:21:08 +01:00
irengrig 370a8ff244
Remove unused call of an old Starlark API (#186) 2019-01-02 14:50:20 +01:00
irengrig 82ff0ce803
We need a separate variant for 0.21 and fix for HEAD was in wrong file (#183) 2018-12-20 13:27:52 +01:00
irengrig cec144aef4
Fix a call to cc_common.create_compilation_context for Bazel HEAD (#182) 2018-12-20 13:13:17 +01:00
irengrig b08610b154
Improve the boost rule including user_options attribute. (#177)
* Improve the boost rule including user_options attribute.

Then --with-<library> parameter can be passed to build only that library
Modify examples to demonstrate how to use it.
However, building examples takes too long time, so do not include them into the tests.
2018-12-07 14:30:41 +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 eb5f16592f
Fix compatibility with Bazel HEAD for a cc_common.create_XXX_variables (#172) 2018-12-05 17:34:00 +01:00
irengrig 8e2cc0f83c
Use shell function for copying directory contents to be multi-platform (#171) 2018-12-05 15:13:03 +01:00
irengrig 87f42c4a5b
Support in-the-middle state of C++ API in Bazel 0.20.0 (#168) 2018-12-04 18:39:08 +01:00
bbarnes52 6caaa8a26b removes strip calls from string concatenation to fix bug where compiler invocation failed due to invalid syntax (#163) 2018-12-04 16:02:00 +01:00
irengrig 7fdfc7cade
When cmake_external script fails, do not delete build directory. (#166)
* When cmake_external script fails, do not delete build directory.

Fixes #162.
2018-12-04 14:32:59 +01:00
irengrig 59bd073a22
In the generated repository, refer to the "parent" as @rules_foreign_cc (#161)
Fixes #160
2018-11-29 21:55:27 +01:00
irengrig d6d2f0761a
Adapt to the new Starlark API. (#157)
The rule supports both old and new API;
however, for switching the implementations, I had to use code generation - copying the actual implementations for different API variants into a generated repository.
I did not invent any other mechanics to deal with non existing top level symbols like CcInfo or CcCompilationInfo.

Design document about the new API: https://github.com/bazelbuild/proposals, Partial C++ Starlark API
Introduced in the commit: eb139371c9
2018-11-27 10:06:23 +01:00
irengrig 13419882d6
Put each of binary files into OutputGroupInfo under its name. (#148)
Add CMake test for building a binary and using that binary in a test.
2018-10-25 16:28:43 +02:00
irengrig d9318f13d3
framework: extract environment variable declaration into separate part (#145) 2018-10-25 12:37:15 +02:00
irengrig dee42b1598
Correct the problem with dependent output files/directories (#138)
* Correct the problem with dependent output files/directories

A rule should not return files and their parent directory;
therefore, create a copy directory for the install directory, which we use in the next-step external builds, and reduce other outputs to the lowest level (library files, binary files, include directories).

* Correct review comments: add documentation, revert not related change.

* Do not pass the rule context as argument into shell utilities functions;

only pass the actions factory and other specific parameters.
(review comments)
2018-10-25 11:53:58 +02:00
bbarnes52 8026d6f5ce minor code cleanup (#144) 2018-10-25 11:30:25 +02:00
bbarnes52 2fc3d7b847 removes directories from output declarations to enable remote execution (#133)
* removes directories from output declarations to enable remote execution

* incorporates @irengrigs feedback
2018-10-25 11:24:44 +02:00
irengrig b3552bfef8
Fix dynamic libraries (#141)
* move cmake_hello example with static library into a subdirectory

* Fix #139; correct arguments to create_library_to_link

However, the test (which should link the externally built shared library to the calling .c file) fails with assertion that the .so file is in a "wrong" directory, so I am providing it here for additional work [possibly] on Bazel side; and I do not include it into the tests list

* As cc_common.create_library_to_link is now broken for shared libraries,
use the "old" variant cc_common.create_symlink_library_to_link.

As it will later be removed (and create_library_to_link fixed),
it is safe to check for the existence of create_symlink_library_to_link and call it.

Now the test with shared library built by CMake runs, so add it ot the [non-Windows, for now] suite.

* Adapt building shared library with cmake test for mac

* increment version

* Add comment on CMAKE_MACOSX_RPATH
2018-10-23 16:49:20 +02:00
bbarnes52 5373e59a65 fixes boost (#136)
* fixes boost rule

* fixes boost

* updates to use configureParameters
2018-10-19 18:49:30 +02:00
irengrig 30ecb0d59e
Fix binary outputs declaration (#131) 2018-10-15 11:05:52 -04:00
irengrig ce306646d0
Improve documentation and naming for the configuration callback (#130)
- create provider for the parameters, passed to the callback
- correct documentation
2018-10-15 11:00:52 -04:00
irengrig 944399982f
Fix getting ForeignCcDeps from deps, it is optional provider (#129) 2018-10-15 07:23:03 -04:00
irengrig 4965090335
External C/C++ libraries rules need to pass transitive info (#112)
* External C/C++ libraries rules need to pass transitive info

- to have the same interface as cc_library to hide the "implementation details",
so that the information about the install directory and its contents of non-direct external dependencies of external library was available for external build
- this is particularly needed for configure-make rule, where we do not control the way needed libraries are found, so we want to provide the install directory and the -L, -I flags (include and library directories to be searched) consistently,
pointing to the directories under $EXT_BUILD_DEPS
- as a side effect, *.la files that contained links to absolute paths of dependencies (pointing somewhere under ...sandbox/bazel-out/...) now will point to directories under $EXT_BUILD_DEPS and so will be replaced correctly/will not point to paths under the previous sandbox

* External C/C++ libraries rules need to pass transitive info [improve]
By review comments;

- rename to do not collate with internally reserved list, dir, provider
- rename providers to use the same "foreign_cc" prefix and be shorter
- improve providers description
- return back output groups to do not reduce the flexibility

* External C/C++ libraries rules need to pass transitive info [improve]
By review comments:

- some more renames

* External C/C++ libraries rules need to pass transitive info: version++

* Correct review comments
2018-10-05 22:04:54 +02:00