Skip to content

Commit a52f3d5

Browse files
authored
Merge pull request #971 from swiftlang/t/actions
[llbuild3] Groundwork for Actions
2 parents ae496d1 + ee02f07 commit a52f3d5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+19276
-3630
lines changed

llbuild.xcodeproj/project.pbxproj

Lines changed: 122 additions & 42 deletions
Large diffs are not rendered by default.

products/llbuild3/Errors.hpp

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#ifndef LLBUILD3_CORE_ERRORS_H
14-
#define LLBUILD3_CORE_ERRORS_H
13+
#ifndef LLBUILD3_ERRORS_H
14+
#define LLBUILD3_ERRORS_H
1515

1616
#include <cstdint>
17+
#include <type_traits>
1718

1819
namespace llbuild3 {
19-
namespace core {
2020

21-
enum EngineError: uint64_t {
21+
enum class EngineError: uint64_t {
2222
// 100 - Graph Errors
2323
NoArtifactProducer = 100,
2424
NoProviderForRule = 101,
@@ -46,14 +46,43 @@ enum EngineError: uint64_t {
4646
Unknown = 0
4747
};
4848

49-
enum CASError: uint64_t {
49+
enum class CASError: uint64_t {
5050
ObjectNotFound = 100,
5151

5252
// Unknown
53-
UnknownCASError = 0
53+
Unknown = 0
5454
};
5555

56+
enum class ExecutorError: uint64_t {
57+
58+
// 200 - Client Implementation Errors
59+
BadRequest = 200,
60+
61+
// 1000 - Executor Internal Errors
62+
Unimplemented = 1000,
63+
InternalInconsistency = 1001,
64+
65+
Unknown = 0
66+
};
67+
68+
69+
namespace internal
70+
{
71+
template <typename E>
72+
using UnderlyingType = typename std::underlying_type<E>::type;
73+
74+
template <typename E>
75+
using EnumTypesOnly = typename std::enable_if<std::is_enum<E>::value, E>::type;
76+
77+
} // namespace internal
78+
79+
80+
template <typename E, typename = internal::EnumTypesOnly<E>>
81+
constexpr internal::UnderlyingType<E> rawCode(E e) {
82+
return static_cast<internal::UnderlyingType<E>>(e);
5683
}
84+
85+
5786
}
5887

5988
#endif /* Header_h */

products/llbuild3/SwiftAdaptors.hpp

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,28 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#ifndef LLBUILD3_CORE_SWIFTADAPTORS_H
14-
#define LLBUILD3_CORE_SWIFTADAPTORS_H
13+
#ifndef LLBUILD3_SWIFTADAPTORS_H
14+
#define LLBUILD3_SWIFTADAPTORS_H
1515

16+
#include <functional>
1617
#include <memory>
1718
#include <optional>
1819
#include <string>
20+
#include <unordered_map>
1921
#include <vector>
2022

2123
#include <llbuild3/Visibility.hpp>
2224
#include <llbuild3/Result.hpp>
2325

2426

2527
namespace llbuild3 {
26-
namespace core {
2728

2829
class Build;
2930
class Engine;
3031
struct EngineConfig;
3132

3233
// Serialized Protobuf Objects
34+
typedef std::string ActionPB;
3335
typedef std::string ArtifactPB;
3436
typedef std::string CacheKeyPB;
3537
typedef std::string CacheValuePB;
@@ -45,9 +47,33 @@ typedef std::string TaskNextStatePB;
4547

4648
// Swift helper typedefs
4749
typedef std::vector<LabelPB> LabelVector;
50+
typedef std::vector<std::pair<uint64_t, result<void*, ErrorPB>>> SubtaskResultMap;
4851

4952
// External Adaptor Objects
5053

54+
class CASDatabase;
55+
typedef std::shared_ptr<CASDatabase> CASDatabaseRef;
56+
57+
struct ExtCASDatabase {
58+
void* ctx;
59+
60+
// FIXME: cleanup context
61+
62+
void (*containsFn)(void* ctx, CASIDBytes id, std::function<void (bool, ErrorPB)>);
63+
void (*getFn)(void* ctx, CASIDBytes id, std::function<void (CASObjectPB, ErrorPB)>);
64+
void (*putFn)(void* ctx, CASObjectPB obj, std::function<void (CASIDBytes, ErrorPB)>);
65+
CASIDBytes (*identifyFn)(void* ctx, CASObjectPB obj);
66+
};
67+
68+
LLBUILD3_EXPORT CASDatabaseRef makeExtCASDatabase(ExtCASDatabase extCASDB);
69+
LLBUILD3_EXPORT CASDatabaseRef makeInMemoryCASDatabase();
70+
71+
LLBUILD3_EXPORT void* getRawCASDatabaseContext(CASDatabaseRef casDB);
72+
LLBUILD3_EXPORT void adaptedCASDatabaseContains(CASDatabaseRef casDB, CASIDBytes, void* ctx, void (*handler)(void*, result<bool, ErrorPB>*));
73+
LLBUILD3_EXPORT void adaptedCASDatabaseGet(CASDatabaseRef casDB, CASIDBytes, void* ctx, void (*handler)(void*, result<CASObjectPB, ErrorPB>*));
74+
LLBUILD3_EXPORT void adaptedCASDatabasePut(CASDatabaseRef casDB, CASObjectPB, void* ctx, void (*handler)(void*, result<CASIDBytes, ErrorPB>*));
75+
LLBUILD3_EXPORT CASIDBytes adaptedCASDatabaseIdentify(CASDatabaseRef casDB, CASObjectPB);
76+
5177
struct ExtRule;
5278

5379
struct ExtRuleProvider {
@@ -62,6 +88,23 @@ struct ExtRuleProvider {
6288
bool (*ruleForArtifactFn)(void*, const LabelPB*, ExtRule*);
6389
};
6490

91+
class ExtSubtaskInterface {
92+
private:
93+
void* impl;
94+
uint64_t ctx;
95+
96+
public:
97+
ExtSubtaskInterface(void* impl, uint64_t ctx) : impl(impl), ctx(ctx) { }
98+
99+
LLBUILD3_EXPORT CASDatabaseRef cas();
100+
};
101+
102+
struct ExtSubtask {
103+
void* ctx;
104+
105+
void (*perform)(void*, ExtSubtaskInterface, std::function<void (void*, ErrorPB)>);
106+
};
107+
65108
class ExtTaskInterface {
66109
private:
67110
void* impl;
@@ -74,7 +117,8 @@ class ExtTaskInterface {
74117

75118
LLBUILD3_EXPORT result<uint64_t, ErrorPB> requestArtifact(const LabelPB label);
76119
LLBUILD3_EXPORT result<uint64_t, ErrorPB> requestRule(const LabelPB label);
77-
LLBUILD3_EXPORT result<uint64_t, ErrorPB> requestAction();
120+
LLBUILD3_EXPORT result<uint64_t, ErrorPB> requestAction(const ActionPB action);
121+
LLBUILD3_EXPORT result<uint64_t, ErrorPB> spawnSubtask(const ExtSubtask subtask);
78122
};
79123

80124
struct ExtTask {
@@ -88,7 +132,7 @@ struct ExtTask {
88132
// FIXME: some method for cleaning up context
89133

90134
void (*producesFn)(void*, std::vector<LabelPB>*);
91-
bool (*computeFn)(void*, ExtTaskInterface, const TaskContextPB*, const TaskInputsPB*, TaskNextStatePB*);
135+
bool (*computeFn)(void*, ExtTaskInterface, const TaskContextPB*, const TaskInputsPB*, SubtaskResultMap*, TaskNextStatePB*);
92136
};
93137

94138
struct ExtRule {
@@ -115,22 +159,6 @@ class BuildRef {
115159
LLBUILD3_EXPORT void addCompletionHandler(void* ctx, void (*handler)(void*, result<ArtifactPB, ErrorPB>*));
116160
};
117161

118-
struct ExtCASDatabase {
119-
void* ctx;
120-
121-
// FIXME: cleanup context
122-
123-
void (*containsFn)(void* ctx, CASIDBytes id, std::function<void (bool, ErrorPB)>);
124-
void (*getFn)(void* ctx, CASIDBytes id, std::function<void (CASObjectPB, ErrorPB)>);
125-
void (*putFn)(void* ctx, CASObjectPB obj, std::function<void (CASIDBytes, ErrorPB)>);
126-
CASIDBytes (*identifyFn)(void* ctx, CASObjectPB obj);
127-
};
128-
129-
class CASDatabase;
130-
typedef std::shared_ptr<CASDatabase> CASDatabaseRef;
131-
LLBUILD3_EXPORT CASDatabaseRef makeExtCASDatabase(ExtCASDatabase extCASDB);
132-
LLBUILD3_EXPORT CASDatabaseRef makeInMemoryCASDatabase();
133-
134162
struct ExtActionCache {
135163
void* ctx;
136164

@@ -145,6 +173,9 @@ typedef std::shared_ptr<ActionCache> ActionCacheRef;
145173
LLBUILD3_EXPORT ActionCacheRef makeExtActionCache(ExtActionCache extCache);
146174
LLBUILD3_EXPORT ActionCacheRef makeInMemoryActionCache();
147175

176+
class ActionExecutor;
177+
typedef std::shared_ptr<ActionExecutor> ActionExecutorRef;
178+
LLBUILD3_EXPORT ActionExecutorRef makeActionExecutor();
148179

149180
struct ExtEngineConfig {
150181
std::optional<LabelPB> initRule;
@@ -160,9 +191,12 @@ class EngineRef {
160191
LLBUILD3_EXPORT BuildRef build(const LabelPB artifact);
161192
};
162193

163-
LLBUILD3_EXPORT EngineRef makeEngine(ExtEngineConfig config, CASDatabaseRef casdb, ActionCacheRef cache, const ExtRuleProvider provider);
194+
LLBUILD3_EXPORT EngineRef makeEngine(ExtEngineConfig config,
195+
CASDatabaseRef casdb,
196+
ActionCacheRef cache,
197+
ActionExecutorRef executor,
198+
const ExtRuleProvider provider);
164199

165-
}
166200
}
167201

168202
#endif /* Header_h */

0 commit comments

Comments
 (0)