@@ -11,18 +11,18 @@ information about the behavior.
11
11
Includes new tests in "build_test.go" and "buildbackend_test.go" to help
12
12
maintain this feature. For more information, see the test files.
13
13
---
14
- src/cmd/go/internal/modindex/build.go | 54 + +++++++++++++
15
- src/cmd/go/internal/modindex/build_test.go | 73 +++++++++++++++++++
16
- src/go/build/build.go | 54 + +++++++++++++
17
- src/go/build/buildbackend_test.go | 66 +++++++++++++++++
14
+ src/cmd/go/internal/modindex/build.go | 57 +++++++++++++
15
+ src/cmd/go/internal/modindex/build_test.go | 73 ++++++++++++++++
16
+ src/go/build/build.go | 57 +++++++++++++
17
+ src/go/build/buildbackend_test.go | 84 ++ +++++++++++++++++
18
18
.../testdata/backendtags_openssl/main.go | 3 +
19
19
.../testdata/backendtags_openssl/openssl.go | 3 +
20
20
.../build/testdata/backendtags_system/main.go | 3 +
21
21
.../backendtags_system/systemcrypto.go | 3 +
22
- .../goexperiment/exp_systemcrypto_off.go | 9 +++
23
- .../goexperiment/exp_systemcrypto_on.go | 9 +++
22
+ .../goexperiment/exp_systemcrypto_off.go | 9 ++
23
+ .../goexperiment/exp_systemcrypto_on.go | 9 ++
24
24
src/internal/goexperiment/flags.go | 15 ++++
25
- 11 files changed, 292 insertions(+)
25
+ 11 files changed, 316 insertions(+)
26
26
create mode 100644 src/cmd/go/internal/modindex/build_test.go
27
27
create mode 100644 src/go/build/buildbackend_test.go
28
28
create mode 100644 src/go/build/testdata/backendtags_openssl/main.go
@@ -33,16 +33,17 @@ maintain this feature. For more information, see the test files.
33
33
create mode 100644 src/internal/goexperiment/exp_systemcrypto_on.go
34
34
35
35
diff --git a/src/cmd/go/internal/modindex/build.go b/src/cmd/go/internal/modindex/build.go
36
- index b57f2f6368f0fe..9ddde1ce9a2286 100644
36
+ index b4dacb0f523a8d..4315c288d10cb3 100644
37
37
--- a/src/cmd/go/internal/modindex/build.go
38
38
+++ b/src/cmd/go/internal/modindex/build.go
39
- @@ -880 ,13 +880,67 @@ func (ctxt *Context) matchTag(name string, allTags map[string]bool) bool {
39
+ @@ -886 ,13 +886,70 @@ func (ctxt *Context) matchTag(name string, allTags map[string]bool) bool {
40
40
name = "goexperiment.boringcrypto" // boringcrypto is an old name for goexperiment.boringcrypto
41
41
}
42
42
43
43
+ const system = "goexperiment.systemcrypto"
44
44
+ const openssl = "goexperiment.opensslcrypto"
45
45
+ const cng = "goexperiment.cngcrypto"
46
+ + const darwin = "goexperiment.darwincrypto"
46
47
+ const boring = "goexperiment.boringcrypto"
47
48
+ // Implement the SystemCrypto GOEXPERIMENT logic. This is done here rather
48
49
+ // than during GOEXPERIMENT parsing so "-tags goexperiment.systemcrypto"
@@ -63,11 +64,12 @@ index b57f2f6368f0fe..9ddde1ce9a2286 100644
63
64
+ satisfiedByAnyBackend := name == system
64
65
+ satisfiedBySystemCrypto :=
65
66
+ (ctxt.GOOS == "linux" && name == openssl) ||
66
- + (ctxt.GOOS == "windows" && name == cng)
67
+ + (ctxt.GOOS == "windows" && name == cng) ||
68
+ + (ctxt.GOOS == "darwin" && name == darwin)
67
69
+ satisfiedBy := func(tag string) bool {
68
70
+ if satisfiedByAnyBackend {
69
71
+ switch tag {
70
- + case openssl, cng, boring:
72
+ + case openssl, cng, darwin, boring:
71
73
+ return true
72
74
+ }
73
75
+ }
@@ -81,6 +83,7 @@ index b57f2f6368f0fe..9ddde1ce9a2286 100644
81
83
+ if satisfiedByAnyBackend {
82
84
+ allTags[openssl] = true
83
85
+ allTags[cng] = true
86
+ + allTags[darwin] = true
84
87
+ allTags[boring] = true
85
88
+ }
86
89
+ if satisfiedBySystemCrypto {
@@ -184,16 +187,17 @@ index 00000000000000..1756c5d027fee0
184
187
+ }
185
188
+ }
186
189
diff --git a/src/go/build/build.go b/src/go/build/build.go
187
- index dd6cdc903a21a8..48adcfed5cf3cb 100644
190
+ index 9ffffda08a99b1..78fd536fa6a6d1 100644
188
191
--- a/src/go/build/build.go
189
192
+++ b/src/go/build/build.go
190
- @@ -1947 ,13 +1947,67 @@ func (ctxt *Context) matchTag(name string, allTags map[string]bool) bool {
193
+ @@ -1984 ,13 +1984,70 @@ func (ctxt *Context) matchTag(name string, allTags map[string]bool) bool {
191
194
name = "goexperiment.boringcrypto" // boringcrypto is an old name for goexperiment.boringcrypto
192
195
}
193
196
194
197
+ const system = "goexperiment.systemcrypto"
195
198
+ const openssl = "goexperiment.opensslcrypto"
196
199
+ const cng = "goexperiment.cngcrypto"
200
+ + const darwin = "goexperiment.darwincrypto"
197
201
+ const boring = "goexperiment.boringcrypto"
198
202
+ // Implement the SystemCrypto GOEXPERIMENT logic. This is done here rather
199
203
+ // than during GOEXPERIMENT parsing so "-tags goexperiment.systemcrypto"
@@ -214,11 +218,12 @@ index dd6cdc903a21a8..48adcfed5cf3cb 100644
214
218
+ satisfiedByAnyBackend := name == system
215
219
+ satisfiedBySystemCrypto :=
216
220
+ (ctxt.GOOS == "linux" && name == openssl) ||
217
- + (ctxt.GOOS == "windows" && name == cng)
221
+ + (ctxt.GOOS == "windows" && name == cng) ||
222
+ + (ctxt.GOOS == "darwin" && name == darwin)
218
223
+ satisfiedBy := func(tag string) bool {
219
224
+ if satisfiedByAnyBackend {
220
225
+ switch tag {
221
- + case openssl, cng, boring:
226
+ + case openssl, cng, darwin, boring:
222
227
+ return true
223
228
+ }
224
229
+ }
@@ -232,6 +237,7 @@ index dd6cdc903a21a8..48adcfed5cf3cb 100644
232
237
+ if satisfiedByAnyBackend {
233
238
+ allTags[openssl] = true
234
239
+ allTags[cng] = true
240
+ + allTags[darwin] = true
235
241
+ allTags[boring] = true
236
242
+ }
237
243
+ if satisfiedBySystemCrypto {
@@ -257,10 +263,10 @@ index dd6cdc903a21a8..48adcfed5cf3cb 100644
257
263
}
258
264
diff --git a/src/go/build/buildbackend_test.go b/src/go/build/buildbackend_test.go
259
265
new file mode 100644
260
- index 00000000000000..a22abbb42e37c0
266
+ index 00000000000000..aa3c5f1007ed79
261
267
--- /dev/null
262
268
+++ b/src/go/build/buildbackend_test.go
263
- @@ -0,0 +1,66 @@
269
+ @@ -0,0 +1,84 @@
264
270
+ // Copyright 2023 The Go Authors. All rights reserved.
265
271
+ // Use of this source code is governed by a BSD-style
266
272
+ // license that can be found in the LICENSE file.
@@ -318,14 +324,32 @@ index 00000000000000..a22abbb42e37c0
318
324
+ if err != nil {
319
325
+ t.Fatal(err)
320
326
+ }
321
- + want = []string{"goexperiment.boringcrypto", "goexperiment.cngcrypto", "goexperiment.opensslcrypto", "goexperiment.systemcrypto"}
327
+ + want = []string{"goexperiment.boringcrypto", "goexperiment.cngcrypto", "goexperiment.darwincrypto", "goexperiment. opensslcrypto", "goexperiment.systemcrypto"}
322
328
+ if !reflect.DeepEqual(p.AllTags, want) {
323
329
+ t.Errorf("AllTags = %v, want %v", p.AllTags, want)
324
330
+ }
325
331
+ wantFiles = []string{"main.go", "systemcrypto.go"}
326
332
+ if !reflect.DeepEqual(p.GoFiles, wantFiles) {
327
333
+ t.Errorf("GoFiles = %v, want %v", p.GoFiles, wantFiles)
328
334
+ }
335
+ +
336
+ + ctxt.GOARCH = "amd64"
337
+ + ctxt.GOOS = "darwin"
338
+ + ctxt.BuildTags = []string{"goexperiment.darwincrypto"}
339
+ + p, err = ctxt.ImportDir("testdata/backendtags_openssl", 0)
340
+ + if err != nil {
341
+ + t.Fatal(err)
342
+ + }
343
+ + // Given the current GOOS (darwin), systemcrypto would not affect the
344
+ + // decision, so we don't want it to be included in AllTags.
345
+ + want = []string{"goexperiment.opensslcrypto"}
346
+ + if !reflect.DeepEqual(p.AllTags, want) {
347
+ + t.Errorf("AllTags = %v, want %v", p.AllTags, want)
348
+ + }
349
+ + wantFiles = []string{"main.go"}
350
+ + if !reflect.DeepEqual(p.GoFiles, wantFiles) {
351
+ + t.Errorf("GoFiles = %v, want %v", p.GoFiles, wantFiles)
352
+ + }
329
353
+ }
330
354
diff --git a/src/go/build/testdata/backendtags_openssl/main.go b/src/go/build/testdata/backendtags_openssl/main.go
331
355
new file mode 100644
@@ -394,14 +418,14 @@ index 00000000000000..9c5b0bbc7b99dc
394
418
+ const SystemCrypto = true
395
419
+ const SystemCryptoInt = 1
396
420
diff --git a/src/internal/goexperiment/flags.go b/src/internal/goexperiment/flags.go
397
- index ae3cbaf89fa5dd..de79140b2d4780 100644
421
+ index 31b3d0315b64f8..de1dfa6e567a71 100644
398
422
--- a/src/internal/goexperiment/flags.go
399
423
+++ b/src/internal/goexperiment/flags.go
400
424
@@ -60,6 +60,21 @@ type Flags struct {
401
425
StaticLockRanking bool
402
426
BoringCrypto bool
403
427
404
- + // SystemCrypto enables the OpenSSL or CNG crypto experiment depending on
428
+ + // SystemCrypto enables the OpenSSL, CNG or Darwin crypto experiment depending on
405
429
+ // which one is appropriate on the target GOOS.
406
430
+ //
407
431
+ // If SystemCrypto is enabled but no crypto experiment is appropriate on the
0 commit comments