mirror of
https://github.com/boostorg/build.git
synced 2026-01-19 04:02:14 +00:00
Add initial support for {CPP}-26 Contracts for GCC based toolsets (like clang).
This commit is contained in:
@@ -1,6 +1,12 @@
|
|||||||
[[b2.history]]
|
[[b2.history]]
|
||||||
= History
|
= History
|
||||||
|
|
||||||
|
== Version 5.4.0
|
||||||
|
|
||||||
|
* *New*: Add initial support for {CPP}-26 Contracts for GCC based toolsets
|
||||||
|
(like clang).
|
||||||
|
-- _René Ferdinand Rivera Morell_
|
||||||
|
|
||||||
== Version 5.3.3
|
== Version 5.3.3
|
||||||
|
|
||||||
* Fix `stdlib=libc++` feature being applied to compiles other than {CPP}.
|
* Fix `stdlib=libc++` feature being applied to compiles other than {CPP}.
|
||||||
|
|||||||
@@ -286,6 +286,7 @@ include::../../src/tools/features/warnings-feature.jam[tag=doc]
|
|||||||
include::../../src/tools/features/translate-path-feature.jam[tag=doc]
|
include::../../src/tools/features/translate-path-feature.jam[tag=doc]
|
||||||
include::../../src/tools/features/lto-feature.jam[tag=doc]
|
include::../../src/tools/features/lto-feature.jam[tag=doc]
|
||||||
include::../../src/tools/features/response-file-feature.jam[tag=doc]
|
include::../../src/tools/features/response-file-feature.jam[tag=doc]
|
||||||
|
include::../../src/tools/features/contracts-feature.jam[tag=doc]
|
||||||
|
|
||||||
[[b2.reference.tools]]
|
[[b2.reference.tools]]
|
||||||
== Builtin tools
|
== Builtin tools
|
||||||
|
|||||||
21
example/contracts/hello.cpp
Normal file
21
example/contracts/hello.cpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
// Copyright 2025 René Ferdinand Rivera Morel
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// (See accompanying file LICENSE.txt or copy at
|
||||||
|
// https://www.bfgroup.xyz/b2/LICENSE.txt)
|
||||||
|
|
||||||
|
// tag::source[]
|
||||||
|
#include <contracts>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int f(const int x) pre(x != 0) post(r : r != x)
|
||||||
|
{
|
||||||
|
return x + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::cout << "Hello!\n";
|
||||||
|
f(1);
|
||||||
|
f(0);
|
||||||
|
}
|
||||||
|
// end::source[]
|
||||||
14
example/contracts/jamroot.jam
Normal file
14
example/contracts/jamroot.jam
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# Copyright 2008 Jurko Gospodnetic
|
||||||
|
# Copyright 2025 René Ferdinand Rivera Morell
|
||||||
|
# Distributed under the Boost Software License, Version 1.0.
|
||||||
|
# (See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt)
|
||||||
|
|
||||||
|
project
|
||||||
|
: requirements
|
||||||
|
<contracts>on
|
||||||
|
<contracts-semantic>enforce
|
||||||
|
<toolset>clang:<stdlib>libc++
|
||||||
|
<cxxstd>23
|
||||||
|
;
|
||||||
|
|
||||||
|
exe hello : hello.cpp ;
|
||||||
47
example/contracts/readme.adoc
Normal file
47
example/contracts/readme.adoc
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
////
|
||||||
|
Copyright 2008 Jurko Gospodnetic
|
||||||
|
Copyright 2025 René Ferdinand Rivera Morell
|
||||||
|
Distributed under the Boost Software License, Version 1.0.
|
||||||
|
(See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt)
|
||||||
|
////
|
||||||
|
|
||||||
|
= Hello
|
||||||
|
|
||||||
|
This example shows a very basic Boost Build project set up so it compiles a
|
||||||
|
single executable which makes use of contracts from a single source file:
|
||||||
|
|
||||||
|
.`hello.cpp`
|
||||||
|
[source,cpp]
|
||||||
|
----
|
||||||
|
include::../../example/contracts/hello.cpp[tag=source]
|
||||||
|
----
|
||||||
|
|
||||||
|
Our `jamroot.jam` is minimal and only specifies one `exe` target for the
|
||||||
|
program:
|
||||||
|
|
||||||
|
.`jamroot.jam`
|
||||||
|
[source,jam]
|
||||||
|
----
|
||||||
|
include::jamroot.jam[]
|
||||||
|
----
|
||||||
|
|
||||||
|
Building the example yields:
|
||||||
|
|
||||||
|
[source,bash]
|
||||||
|
----
|
||||||
|
> cd /example/hello
|
||||||
|
> b2
|
||||||
|
...found 12 targets...
|
||||||
|
...updating 8 targets...
|
||||||
|
clang-linux.compile.c++ bin/clang-linux-22.0~contracts/debug/contracts-on-enforce/cxxstd-23-iso/stdlib-libc++/hello.o
|
||||||
|
clang-linux.link bin/clang-linux-22.0~contracts/debug/contracts-on-enforce/cxxstd-23-iso/stdlib-libc++/hello
|
||||||
|
|
||||||
|
...updated 8 targets...
|
||||||
|
> LD_LIBRARY_PATH=/opt/clang-ericwf-contracts-trunk/lib/x86_64-unknown-linux-gnu/ bin/clang-linux-22.0~contracts/debug/contracts-on-enforce/cxxstd-23-iso/stdlib-libc++/hello
|
||||||
|
Hello!
|
||||||
|
hello.cpp:11: pre(x != 0) failed
|
||||||
|
libc++abi: terminating
|
||||||
|
Aborted (core dumped) LD_LIBRARY_PATH=/opt/clang-ericwf-contracts-trunk/lib/x86_64-unknown-linux-gnu/ bin/clang-linux-22.0~contracts/debug/contracts-on-enforce/cxxstd-23-iso/stdlib-libc++/hello
|
||||||
|
----
|
||||||
|
|
||||||
|
NOTE: The actual paths will depend on your configuration.
|
||||||
@@ -9,8 +9,8 @@ import numbers ;
|
|||||||
|
|
||||||
# Mirror engine JAM_VERSION
|
# Mirror engine JAM_VERSION
|
||||||
.major = 5 ;
|
.major = 5 ;
|
||||||
.minor = 3 ;
|
.minor = 4 ;
|
||||||
.patch = 3 ;
|
.patch = 0 ;
|
||||||
|
|
||||||
|
|
||||||
rule build ( )
|
rule build ( )
|
||||||
|
|||||||
@@ -13,5 +13,5 @@ https://www.bfgroup.xyz/b2/LICENSE.txt)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#define VERSION_MAJOR 5
|
#define VERSION_MAJOR 5
|
||||||
#define VERSION_MINOR 3
|
#define VERSION_MINOR 4
|
||||||
#define VERSION_PATCH 3
|
#define VERSION_PATCH 0
|
||||||
|
|||||||
48
src/tools/features/contracts-feature.jam
Normal file
48
src/tools/features/contracts-feature.jam
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
# Copyright 2025 René Ferdinand Rivera Morel
|
||||||
|
# Distributed under the Boost Software License, Version 1.0.
|
||||||
|
# (See accompanying file LICENSE.txt or copy at
|
||||||
|
# https://www.bfgroup.xyz/b2/LICENSE.txt)
|
||||||
|
|
||||||
|
import feature ;
|
||||||
|
|
||||||
|
#| tag::doc[]
|
||||||
|
|
||||||
|
[[b2.builtin.features.contracts]]`contracts`::
|
||||||
|
*Allowed values:* `on`.
|
||||||
|
+
|
||||||
|
Enables use of experimental use of {CPP}-26 Contracts (P2900). Enabling
|
||||||
|
contracts has additional requirements when using them with at least clang. See
|
||||||
|
https://contracts.efcs.ca/ for details. For B2 the requirements amount to
|
||||||
|
needing to use `<toolset>clang:<stdlib>libc++` and `<cxxstd>23`.
|
||||||
|
|
||||||
|
|# # end::doc[]
|
||||||
|
|
||||||
|
feature.feature contracts
|
||||||
|
: on
|
||||||
|
: optional propagated link-incompatible ;
|
||||||
|
|
||||||
|
#| tag::doc[]
|
||||||
|
|
||||||
|
[[b2.builtin.features.contracts-sematic]]`contracts-semantic`::
|
||||||
|
*Subfeature of* `contracts`
|
||||||
|
+
|
||||||
|
*Allowed values:* `enforce', 'quick_enforce', 'observe', 'ignore`.
|
||||||
|
+
|
||||||
|
Specifies the contract checking semantic for the translation unit. The default
|
||||||
|
is `enforce` for which contract checks are evaluated with violations resulting
|
||||||
|
in error termination.
|
||||||
|
+
|
||||||
|
`enforce`::: Contract assertions are not evaluated (contracts are disabled).
|
||||||
|
`quick_enforce`::: Contract assertions are evaluated but violations do not
|
||||||
|
terminate the program.
|
||||||
|
`observe`::: Contract assertions are evaluated and violations terminate the
|
||||||
|
program.
|
||||||
|
`ignore`::: Like enforce, but uses optimized evaluation that may skip some
|
||||||
|
checks.
|
||||||
|
|
||||||
|
|# # end::doc[]
|
||||||
|
|
||||||
|
feature.subfeature contracts
|
||||||
|
: semantic
|
||||||
|
: enforce quick_enforce observe ignore
|
||||||
|
: ;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# Copyright 2021 Nikita Kniazev
|
# Copyright 2021 Nikita Kniazev
|
||||||
# Copyright 2001 David Abrahams
|
# Copyright 2001 David Abrahams
|
||||||
# Copyright 2002-2017 Rene Rivera
|
# Copyright 2002-2025 René Ferdinand Rivera Morell
|
||||||
# Copyright 2002-2003 Vladimir Prus
|
# Copyright 2002-2003 Vladimir Prus
|
||||||
# Copyright 2005 Reece H. Dunn
|
# Copyright 2005 Reece H. Dunn
|
||||||
# Copyright 2006 Ilya Sokolov
|
# Copyright 2006 Ilya Sokolov
|
||||||
@@ -716,6 +716,13 @@ toolset.flags gcc.link OPTIONS <lto>on/<lto-mode>fat : -flto ;
|
|||||||
toolset.flags gcc.compile.c++ DEFINES <stdlib>gnu : _GLIBCXX_USE_CXX11_ABI=0 ;
|
toolset.flags gcc.compile.c++ DEFINES <stdlib>gnu : _GLIBCXX_USE_CXX11_ABI=0 ;
|
||||||
toolset.flags gcc.compile.c++ DEFINES <stdlib>gnu11 : _GLIBCXX_USE_CXX11_ABI=1 ;
|
toolset.flags gcc.compile.c++ DEFINES <stdlib>gnu11 : _GLIBCXX_USE_CXX11_ABI=1 ;
|
||||||
|
|
||||||
|
# Contracts
|
||||||
|
toolset.flags gcc.compile.c++ OPTIONS <contracts>on : -fcontracts ;
|
||||||
|
toolset.flags gcc.compile.c++ OPTIONS <contracts>on/<contracts-semantic>ignore : -fcontract-evaluation-semantic=ignore ;
|
||||||
|
toolset.flags gcc.compile.c++ OPTIONS <contracts>on/<contracts-semantic>observe : -fcontract-evaluation-semantic=observe ;
|
||||||
|
toolset.flags gcc.compile.c++ OPTIONS <contracts>on/<contracts-semantic>enforce : -fcontract-evaluation-semantic=enforce ;
|
||||||
|
toolset.flags gcc.compile.c++ OPTIONS <contracts>on/<contracts-semantic>quick_enforce : -fcontract-evaluation-semantic=quick_enforce ;
|
||||||
|
|
||||||
###
|
###
|
||||||
### User free feature options.
|
### User free feature options.
|
||||||
###
|
###
|
||||||
|
|||||||
Reference in New Issue
Block a user