@@ -11,22 +11,24 @@ 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
22
.../goexperiment/exp_cngcrypto_off.go | 8 ++
23
23
src/internal/goexperiment/exp_cngcrypto_on.go | 8 ++
24
+ .../goexperiment/exp_darwincrypto_off.go | 8 ++
25
+ .../goexperiment/exp_darwincrypto_on.go | 8 ++
24
26
.../goexperiment/exp_opensslcrypto_off.go | 8 ++
25
27
.../goexperiment/exp_opensslcrypto_on.go | 8 ++
26
28
.../goexperiment/exp_systemcrypto_off.go | 8 ++
27
29
.../goexperiment/exp_systemcrypto_on.go | 8 ++
28
- src/internal/goexperiment/flags.go | 17 + ++++
29
- 15 files changed, 324 insertions(+)
30
+ src/internal/goexperiment/flags.go | 18 ++++
31
+ 17 files changed, 365 insertions(+)
30
32
create mode 100644 src/cmd/go/internal/modindex/build_test.go
31
33
create mode 100644 src/go/build/buildbackend_test.go
32
34
create mode 100644 src/go/build/testdata/backendtags_openssl/main.go
@@ -35,22 +37,25 @@ maintain this feature. For more information, see the test files.
35
37
create mode 100644 src/go/build/testdata/backendtags_system/systemcrypto.go
36
38
create mode 100644 src/internal/goexperiment/exp_cngcrypto_off.go
37
39
create mode 100644 src/internal/goexperiment/exp_cngcrypto_on.go
40
+ create mode 100644 src/internal/goexperiment/exp_darwincrypto_off.go
41
+ create mode 100644 src/internal/goexperiment/exp_darwincrypto_on.go
38
42
create mode 100644 src/internal/goexperiment/exp_opensslcrypto_off.go
39
43
create mode 100644 src/internal/goexperiment/exp_opensslcrypto_on.go
40
44
create mode 100644 src/internal/goexperiment/exp_systemcrypto_off.go
41
45
create mode 100644 src/internal/goexperiment/exp_systemcrypto_on.go
42
46
43
47
diff --git a/src/cmd/go/internal/modindex/build.go b/src/cmd/go/internal/modindex/build.go
44
- index b4dacb0f523a8d..615ae461eb8cdc 100644
48
+ index b4dacb0f523a8d..4315c288d10cb3 100644
45
49
--- a/src/cmd/go/internal/modindex/build.go
46
50
+++ b/src/cmd/go/internal/modindex/build.go
47
- @@ -886,13 +886,67 @@ func (ctxt *Context) matchTag(name string, allTags map[string]bool) bool {
51
+ @@ -886,13 +886,70 @@ func (ctxt *Context) matchTag(name string, allTags map[string]bool) bool {
48
52
name = "goexperiment.boringcrypto" // boringcrypto is an old name for goexperiment.boringcrypto
49
53
}
50
54
51
55
+ const system = "goexperiment.systemcrypto"
52
56
+ const openssl = "goexperiment.opensslcrypto"
53
57
+ const cng = "goexperiment.cngcrypto"
58
+ + const darwin = "goexperiment.darwincrypto"
54
59
+ const boring = "goexperiment.boringcrypto"
55
60
+ // Implement the SystemCrypto GOEXPERIMENT logic. This is done here rather
56
61
+ // than during GOEXPERIMENT parsing so "-tags goexperiment.systemcrypto"
@@ -71,11 +76,12 @@ index b4dacb0f523a8d..615ae461eb8cdc 100644
71
76
+ satisfiedByAnyBackend := name == system
72
77
+ satisfiedBySystemCrypto :=
73
78
+ (ctxt.GOOS == "linux" && name == openssl) ||
74
- + (ctxt.GOOS == "windows" && name == cng)
79
+ + (ctxt.GOOS == "windows" && name == cng) ||
80
+ + (ctxt.GOOS == "darwin" && name == darwin)
75
81
+ satisfiedBy := func(tag string) bool {
76
82
+ if satisfiedByAnyBackend {
77
83
+ switch tag {
78
- + case openssl, cng, boring:
84
+ + case openssl, cng, darwin, boring:
79
85
+ return true
80
86
+ }
81
87
+ }
@@ -89,6 +95,7 @@ index b4dacb0f523a8d..615ae461eb8cdc 100644
89
95
+ if satisfiedByAnyBackend {
90
96
+ allTags[openssl] = true
91
97
+ allTags[cng] = true
98
+ + allTags[darwin] = true
92
99
+ allTags[boring] = true
93
100
+ }
94
101
+ if satisfiedBySystemCrypto {
@@ -192,16 +199,17 @@ index 00000000000000..1756c5d027fee0
192
199
+ }
193
200
+ }
194
201
diff --git a/src/go/build/build.go b/src/go/build/build.go
195
- index 9ffffda08a99b1..570937cba3cb85 100644
202
+ index 9ffffda08a99b1..78fd536fa6a6d1 100644
196
203
--- a/src/go/build/build.go
197
204
+++ b/src/go/build/build.go
198
- @@ -1984,13 +1984,67 @@ func (ctxt *Context) matchTag(name string, allTags map[string]bool) bool {
205
+ @@ -1984,13 +1984,70 @@ func (ctxt *Context) matchTag(name string, allTags map[string]bool) bool {
199
206
name = "goexperiment.boringcrypto" // boringcrypto is an old name for goexperiment.boringcrypto
200
207
}
201
208
202
209
+ const system = "goexperiment.systemcrypto"
203
210
+ const openssl = "goexperiment.opensslcrypto"
204
211
+ const cng = "goexperiment.cngcrypto"
212
+ + const darwin = "goexperiment.darwincrypto"
205
213
+ const boring = "goexperiment.boringcrypto"
206
214
+ // Implement the SystemCrypto GOEXPERIMENT logic. This is done here rather
207
215
+ // than during GOEXPERIMENT parsing so "-tags goexperiment.systemcrypto"
@@ -222,11 +230,12 @@ index 9ffffda08a99b1..570937cba3cb85 100644
222
230
+ satisfiedByAnyBackend := name == system
223
231
+ satisfiedBySystemCrypto :=
224
232
+ (ctxt.GOOS == "linux" && name == openssl) ||
225
- + (ctxt.GOOS == "windows" && name == cng)
233
+ + (ctxt.GOOS == "windows" && name == cng) ||
234
+ + (ctxt.GOOS == "darwin" && name == darwin)
226
235
+ satisfiedBy := func(tag string) bool {
227
236
+ if satisfiedByAnyBackend {
228
237
+ switch tag {
229
- + case openssl, cng, boring:
238
+ + case openssl, cng, darwin, boring:
230
239
+ return true
231
240
+ }
232
241
+ }
@@ -240,6 +249,7 @@ index 9ffffda08a99b1..570937cba3cb85 100644
240
249
+ if satisfiedByAnyBackend {
241
250
+ allTags[openssl] = true
242
251
+ allTags[cng] = true
252
+ + allTags[darwin] = true
243
253
+ allTags[boring] = true
244
254
+ }
245
255
+ if satisfiedBySystemCrypto {
@@ -265,10 +275,10 @@ index 9ffffda08a99b1..570937cba3cb85 100644
265
275
}
266
276
diff --git a/src/go/build/buildbackend_test.go b/src/go/build/buildbackend_test.go
267
277
new file mode 100644
268
- index 00000000000000..a22abbb42e37c0
278
+ index 00000000000000..aa3c5f1007ed79
269
279
--- /dev/null
270
280
+++ b/src/go/build/buildbackend_test.go
271
- @@ -0,0 +1,66 @@
281
+ @@ -0,0 +1,84 @@
272
282
+ // Copyright 2023 The Go Authors. All rights reserved.
273
283
+ // Use of this source code is governed by a BSD-style
274
284
+ // license that can be found in the LICENSE file.
@@ -326,14 +336,32 @@ index 00000000000000..a22abbb42e37c0
326
336
+ if err != nil {
327
337
+ t.Fatal(err)
328
338
+ }
329
- + want = []string{"goexperiment.boringcrypto", "goexperiment.cngcrypto", "goexperiment.opensslcrypto", "goexperiment.systemcrypto"}
339
+ + want = []string{"goexperiment.boringcrypto", "goexperiment.cngcrypto", "goexperiment.darwincrypto", "goexperiment. opensslcrypto", "goexperiment.systemcrypto"}
330
340
+ if !reflect.DeepEqual(p.AllTags, want) {
331
341
+ t.Errorf("AllTags = %v, want %v", p.AllTags, want)
332
342
+ }
333
343
+ wantFiles = []string{"main.go", "systemcrypto.go"}
334
344
+ if !reflect.DeepEqual(p.GoFiles, wantFiles) {
335
345
+ t.Errorf("GoFiles = %v, want %v", p.GoFiles, wantFiles)
336
346
+ }
347
+ +
348
+ + ctxt.GOARCH = "amd64"
349
+ + ctxt.GOOS = "darwin"
350
+ + ctxt.BuildTags = []string{"goexperiment.darwincrypto"}
351
+ + p, err = ctxt.ImportDir("testdata/backendtags_openssl", 0)
352
+ + if err != nil {
353
+ + t.Fatal(err)
354
+ + }
355
+ + // Given the current GOOS (darwin), systemcrypto would not affect the
356
+ + // decision, so we don't want it to be included in AllTags.
357
+ + want = []string{"goexperiment.opensslcrypto"}
358
+ + if !reflect.DeepEqual(p.AllTags, want) {
359
+ + t.Errorf("AllTags = %v, want %v", p.AllTags, want)
360
+ + }
361
+ + wantFiles = []string{"main.go"}
362
+ + if !reflect.DeepEqual(p.GoFiles, wantFiles) {
363
+ + t.Errorf("GoFiles = %v, want %v", p.GoFiles, wantFiles)
364
+ + }
337
365
+ }
338
366
diff --git a/src/go/build/testdata/backendtags_openssl/main.go b/src/go/build/testdata/backendtags_openssl/main.go
339
367
new file mode 100644
@@ -399,6 +427,34 @@ index 00000000000000..5b0a55d6c5772e
399
427
+
400
428
+ const CNGCrypto = true
401
429
+ const CNGCryptoInt = 1
430
+ diff --git a/src/internal/goexperiment/exp_darwincrypto_off.go b/src/internal/goexperiment/exp_darwincrypto_off.go
431
+ new file mode 100644
432
+ index 00000000000000..331111ce4759f7
433
+ --- /dev/null
434
+ +++ b/src/internal/goexperiment/exp_darwincrypto_off.go
435
+ @@ -0,0 +1,8 @@
436
+ + // Code generated by mkconsts.go. DO NOT EDIT.
437
+ +
438
+ + //go:build !goexperiment.darwincrypto
439
+ +
440
+ + package goexperiment
441
+ +
442
+ + const DarwinCrypto = false
443
+ + const DarwinCryptoInt = 0
444
+ diff --git a/src/internal/goexperiment/exp_darwincrypto_on.go b/src/internal/goexperiment/exp_darwincrypto_on.go
445
+ new file mode 100644
446
+ index 00000000000000..4bf785b999ecce
447
+ --- /dev/null
448
+ +++ b/src/internal/goexperiment/exp_darwincrypto_on.go
449
+ @@ -0,0 +1,8 @@
450
+ + // Code generated by mkconsts.go. DO NOT EDIT.
451
+ +
452
+ + //go:build goexperiment.darwincrypto
453
+ +
454
+ + package goexperiment
455
+ +
456
+ + const DarwinCrypto = true
457
+ + const DarwinCryptoInt = 1
402
458
diff --git a/src/internal/goexperiment/exp_opensslcrypto_off.go b/src/internal/goexperiment/exp_opensslcrypto_off.go
403
459
new file mode 100644
404
460
index 00000000000000..b28c0976a94cb0
@@ -456,17 +512,18 @@ index 00000000000000..fcd4cb9da0d162
456
512
+ const SystemCrypto = true
457
513
+ const SystemCryptoInt = 1
458
514
diff --git a/src/internal/goexperiment/flags.go b/src/internal/goexperiment/flags.go
459
- index 31b3d0315b64f8..8c140f0dbed134 100644
515
+ index 31b3d0315b64f8..e6c9b7d5e62dc0 100644
460
516
--- a/src/internal/goexperiment/flags.go
461
517
+++ b/src/internal/goexperiment/flags.go
462
- @@ -59,6 +59,23 @@ type Flags struct {
518
+ @@ -59,6 +59,24 @@ type Flags struct {
463
519
PreemptibleLoops bool
464
520
StaticLockRanking bool
465
521
BoringCrypto bool
466
522
+ OpenSSLCrypto bool
467
523
+ CNGCrypto bool
524
+ + DarwinCrypto bool
468
525
+
469
- + // SystemCrypto enables the OpenSSL or CNG crypto experiment depending on
526
+ + // SystemCrypto enables the OpenSSL, CNG or Darwin crypto experiment depending on
470
527
+ // which one is appropriate on the target GOOS.
471
528
+ //
472
529
+ // If SystemCrypto is enabled but no crypto experiment is appropriate on the
0 commit comments