/
rust-1.0.tcl
828 lines (734 loc) · 40.2 KB
/
rust-1.0.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
# -*- coding: utf-8; mode: tcl; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; truncate-lines: t -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4
#
# This PortGroup supports the Rust language ecosystem
#
# Usage:
#
# PortGroup rust 1.0
#
# cargo.crates \
# foo 1.0.1 abcdef123456... \
# bar 2.5.0 fedcba654321...
#
# The cargo.crates option expects a list with 3-tuples consisting of name,
# version, and sha256 checksum. Only sha256 is supported at this time as
# the checksum will be reused by cargo internally.
#
# The list of crates and their checksums can be found in the Cargo.lock file in
# the upstream source code. The cargo2port generator can be used to automate
# updates of this list for new releases.
#
# To get a list of these, run in worksrcdir:
# cargo update
# egrep -e '^(name|version|checksum) = ' Cargo.lock | perl -pe 's/^(?:name|version|checksum) = "(.+)"/$1/'
#
# https://github.com/macports/macports-contrib/tree/master/cargo2port/cargo2port.tcl
#
# If Cargo.lock references pre-release versions, or in general references
# crates not published on crates.io, but available from GitHub, also use the
# following:
#
# # download additional crates from github, not published on crates.io
# cargo.crates_github \
# baz author/baz branch abcdef12345678...commit...abcdef12345678 fedcba654321...
#
PortGroup muniversal 1.1
PortGroup compiler_wrapper 1.0
# ideally, we would like to add the openssl PG, however
# its use of `option_proc` makes changing the default value of `openssl.branch` difficult, and
# it interferes with our intended use of compiler_wrapper PG
# for now, create an option `openssl.branch` in this PG
# Cargo's interaction with OpenSSL is a bit delicate
# see, e.g., https://trac.macports.org/ticket/65011
#
# similarly for legacysupport PG
options cargo.bin \
cargo.home \
cargo.crates \
cargo.offline_cmd \
cargo.crates_github \
cargo.update
default cargo.bin {${prefix}/bin/cargo}
default cargo.home {${workpath}/.home/.cargo}
default cargo.crates {}
default cargo.crates_github {}
# if a dependency has been patched, `--offline` might be a reasonable choice
default cargo.offline_cmd {--frozen}
# some packags do not provide Cargo.lock,
# so offer the option of running cargo-update
default cargo.update {no}
options rust.upstream_deployment_target \
rust.upstream_archs \
rust.use_cctools \
rust.archiver \
rust.ranlib
# default macosx_deployment_target value of Rust function macos_default_deployment_target
# see https://github.com/rust-lang/rust/blob/master/compiler/rustc_target/src/spec/apple_base.rs
default rust.upstream_deployment_target {[expr {${os.arch} eq "arm" ? 11.0 : 10.7}]}
# architectures for which an upstream bootstrap compiler is available
default rust.upstream_archs {[expr {${os.platform} eq "darwin" && ${os.major} >= 13 ? {arm64 x86_64} : {}}]}
# some tools provided by system are too old, so use MacPorts version instead
default rust.use_cctools {[expr {${os.platform} eq "darwin" && ${os.major} < 11 ? "yes" : "no"}]}
default rust.archiver {[expr {${rust.use_cctools} ? "${prefix}/bin/ar" : "/usr/bin/ar"}]}
default rust.ranlib {[expr {${rust.use_cctools} ? "${prefix}/bin/ranlib" : "/usr/bin/ranlib"}]}
# compiler runtime library
# N.B.: `configure.ldflags-append {*}${rust.rt_static_libs}` might be insufficient
# `rust.rt_static_libs` will not give the correct value until *after* the compiler is active
# the compiler might not be active immediately if added as a dependency
options rust.rt_static_libs
default rust.rt_static_libs {[rust::get_static_rutime_libraries]}
# force compiler runtime library to be included in link flags
options rust.add_compiler_runtime
default rust.add_compiler_runtime {no}
# the distfiles of the main port will also be stored in this directory,
# but this is the only way to allow reusing the same crates across multiple ports.
default dist_subdir {[expr {[llength ${cargo.crates}] > 0 || [llength ${cargo.crates_github}] > 0 ? "cargo-crates" : ${name}}]}
default extract.only {[rust::disttagclean $distfiles]}
# to wrap linker, compiler_wrapper PG required existence of configure.ld
options configure.ld
default configure.ld {${configure.cc}}
# Rust set its own compiler flags, so make empty by default
default configure.cflags {}
default configure.cxxflags {}
default configure.ldflags {[expr {${rust.add_compiler_runtime} ? ${rust.rt_static_libs} : {}} ]}
default compiler.limit_flags {yes}
default configure.pipe {no}
rename portconfigure::should_add_stdlib portconfigure::should_add_stdlib_real
rename portconfigure::should_add_cxx_abi portconfigure::should_add_cxx_abi_real
proc portconfigure::should_add_stdlib {} {return no}
proc portconfigure::should_add_cxx_abi {} {return no}
# enforce same compiler settings as used by rust
default compiler.cxx_standard 2017
default compiler.thread_local_storage yes
# do not include os.major in target triplet
default triplet.os {${os.platform}}
# Rust does not easily pass external flags to compilers, so add them to compiler wrappers
default compwrap.compilers_to_wrap {cc cxx ld}
default compwrap.ccache_supported_compilers {}
# possible OpenSSL versions: empty, 3, 1.1, and 1.0
options openssl.branch
default openssl.branch {}
# utility method to get bootstrap compilers
# should only be needed by Rust/Cargo ports
proc rust.add_bootstrap_components {architectures {components {rust-std rustc cargo}}} {
global extract.suffix os.major subport
set version_current 1.66.0
set version_m1 1.65.0
set version_m2 1.64.0
master_sites-append https://static.rust-lang.org/dist:apple_vendor \
https://github.com/MarcusCalhoun-Lopez/rust/releases/download/${version_current}:macports_vendor \
file://[option prefix]/libexec/rust-bootstrap:transition_vendor
if { [join [lrange [split ${subport} -] 0 1] -] eq "rust-bootstrap" } {
set is_bootstrap yes
} else {
set is_bootstrap no
}
set rustc_version ${version_m1}; # ensure value is always set (see https://trac.macports.org/ticket/65183)
foreach arch ${architectures} {
# rust-bootstrap requires `macosx_deployment_target` instead of `os.major`
if { ${arch} in [option rust.upstream_archs] && [vercmp [option macosx_deployment_target] >= [option rust.upstream_deployment_target]]} {
set build_vendor apple
if { ${is_bootstrap} } {
set rustc_version ${version_m2}
} else {
set rustc_version ${version_m1}
}
set build_major ""
} elseif { ${arch} in [option rust.upstream_archs] && ${is_bootstrap} && ${subport} ne "rust-bootstrap-transition" } {
set build_vendor transition
set build_major ""
set rustc_version ${version_m1}
} else {
set build_vendor macports
if { ${os.major} >= 11 || [option os.platform] ne "darwin" } {
set rustc_version ${version_m1}+0
set build_major ""
} elseif { ${os.major} >= 10 } {
set rustc_version ${version_m1}+0
set build_major 10
} elseif { ${os.major} >= 9 } {
set rustc_version ${version_m1}+0
set build_major 9
} elseif { ${os.major} >= 8 } {
set rustc_version ${version_m1}+0
set build_major 8
}
}
if { ${build_vendor} ne "transition" } {
foreach component ${components} {
set binTag ${rustc_version}-[option triplet.cpu.${arch}]-${build_vendor}-[option triplet.os]${build_major}
distfiles-append ${component}-${binTag}${extract.suffix}:${build_vendor}_vendor
}
} else {
depends_extract-delete port:rust-bootstrap-transition
depends_extract-append port:rust-bootstrap-transition
depends_build-delete port:rust-bootstrap-transition
depends_build-append port:rust-bootstrap-transition
depends_skip_archcheck-delete rust-bootstrap-transition
depends_skip_archcheck-append rust-bootstrap-transition
if {[option muniversal.is_cross.[option configure.build_arch]]} {
# if os.arch is arm and subport is rust-bootstrap-10.6, avoid
# Error: Cannot install rust-bootstrap-10.6 for the arch 'x86_64' because
# Error: its dependency rust-bootstrap-transition does not build for the required arch by default
# Error: and does not have a universal variant.
known_fail yes
pre-fetch {
ui_error "${subport} does not support cross-compilation"
return -code error "incompatible OS configuration"
}
}
foreach component ${components} {
set binTag ${rustc_version}+0-[option triplet.cpu.${arch}]-${build_vendor}-[option triplet.os]${build_major}
set distfile [option prefix]/libexec/rust-bootstrap/${component}-${binTag}${extract.suffix}
post-extract "system -W \${workpath} \"\${extract.cmd} \${extract.pre_args} ${distfile} \${extract.post_args}\""
}
}
}
# upstream binaries
checksums-append rust-std-${version_m1}-x86_64-apple-darwin${extract.suffix} \
rmd160 e7f034c7b84e03a0d094bbebc697eb83a4e3ae59 \
sha256 6b832ef5e94dc9d21c00b5c3cdbf5e4f4223a6215d6fa025ba064b7a24a4963a \
size 45706086 \
rustc-${version_m1}-x86_64-apple-darwin${extract.suffix} \
rmd160 54152387cafdf10d2131aa4d9517ecf7784d5c6f \
sha256 be525d2eb2a55f7f5a9f5b3cffe5c1d7b511b4adf9cf5d5855b861138152f1fa \
size 86823029 \
cargo-${version_m1}-x86_64-apple-darwin${extract.suffix} \
rmd160 de37e51c5133b9789ca20b7b691137427ed1bf2d \
sha256 40cbbd62013130d5208435dc45d6c91703eb6a469b6d8eacf746eedc6974ccc0 \
size 7053486 \
rust-std-${version_m1}-aarch64-apple-darwin${extract.suffix} \
rmd160 57c077850c93777ca64f96eb09673a340477e236 \
sha256 68316299635d2577af3b64a2de4839a107f6c33f92e9427d6127526d12ecf07f \
size 44490798 \
rustc-${version_m1}-aarch64-apple-darwin${extract.suffix} \
rmd160 5d800161927dfaf5c8ac16f118e17abaab50ca4b \
sha256 bbcf34977e41b9f966746a559aa2af6fa7efd7f695338851b37f722f7a1104fb \
size 87892283 \
cargo-${version_m1}-aarch64-apple-darwin${extract.suffix} \
rmd160 57cb126c3804b6d0f95431fe58942e31db5a3f78 \
sha256 40858f3078b277165c191b6478c2aba7bf0010162273e28e9964404993eba188 \
size 6572061
# upstream binaries
checksums-append rust-std-${version_m2}-x86_64-apple-darwin${extract.suffix} \
rmd160 f0eb25fca888e671f099e3e233aa77cb4c38991d \
sha256 eb2f7c51f63973765f01efe509ccd2f26345d4bf0d77695adb4198a0899ae648 \
size 41561388 \
rustc-${version_m2}-x86_64-apple-darwin${extract.suffix} \
rmd160 ecc329b1fcc3b5f206fa30fe20ea690afd630791 \
sha256 1201a655352c1a3ec6cd754e458d12eb0d69afdd1608b2813998d7bda1bb9dff \
size 83563528 \
cargo-${version_m2}-x86_64-apple-darwin${extract.suffix} \
rmd160 bbb7948d147a698df11fcfa02cfd83026f8278d1 \
sha256 e032116e22f6d3a4cb078f21031794e88f2a87f066625b8eb7623777e42d6eca \
size 7060018 \
rust-std-${version_m2}-aarch64-apple-darwin${extract.suffix} \
rmd160 79767785ff058ea7173b234232f9f238b1a7c7b6 \
sha256 e70bd0c56f8f716238a1395c54dd9d993a3168e2764e404dc65553babf7aa127 \
size 38541530 \
rustc-${version_m2}-aarch64-apple-darwin${extract.suffix} \
rmd160 18cb2608f941741b3dabe66a0668b6b3cf366994 \
sha256 caac78491d8f0844bb9a512989a409c35ff681a131495e7ebfacb69ba006bbc1 \
size 82983805 \
cargo-${version_m2}-aarch64-apple-darwin${extract.suffix} \
rmd160 d2a4638a1509d051f0bce03ae043eccc4c612b0c \
sha256 4bdcb77ea084364b551a5cf969e263beb09afa39627f6dead262c8e2a7aed9c1 \
size 5750407
# MacPorts bootstrap binaries for older system
checksums-append rust-std-${version_m1}+0-x86_64-macports-darwin${extract.suffix} \
rmd160 8e0e0f30c080733a748526c1b652973b5122f5e3 \
sha256 338518e1a2640a24d2b1acb7c1e1063038c55a408869b4f91e04d6e049d7ab5f \
size 40392363 \
rustc-${version_m1}+0-x86_64-macports-darwin${extract.suffix} \
rmd160 e76452371481d46de6cd7e2a9df23bad7bbb897d \
sha256 e83942780a75a72d30947e00c39fcef267069bf281d3e3ec5671de1608d1ee9d \
size 47999673 \
cargo-${version_m1}+0-x86_64-macports-darwin${extract.suffix} \
rmd160 42cb2560ee7f4ab94f6a89ec6da3ac473c40dd40 \
sha256 829ca1cc123376eabc28c0425330939239b67f25783a0d924bf7d7f356a3e307 \
size 6488699 \
rust-std-${version_m1}+0-i686-macports-darwin${extract.suffix} \
rmd160 be7815902250ddc371d62250d727b42dec48dc9a \
sha256 783d6a998bcbb74c9d3484c9f50860e031fd9f60e204e7a5dcf5be7f91fe57a6 \
size 39896972 \
rustc-${version_m1}+0-i686-macports-darwin${extract.suffix} \
rmd160 86af787fdfbd232d556bab3171f6375f3c1a50d5 \
sha256 ec43736539e9e93179793b653db44128148bd0910d3d3122a39ff917691e9046 \
size 55743906 \
cargo-${version_m1}+0-i686-macports-darwin${extract.suffix} \
rmd160 5bccbe970e63d4746f96d651adbe4abf5d293a9f \
sha256 46306dac27269a7531061aa115ffc56c9887f9edbe2175755509090c08d984bd \
size 6433654 \
rust-std-${version_m1}+0-x86_64-macports-darwin10${extract.suffix} \
rmd160 ccd3541263b9e6b55650a5b6ea824add37e0f00e \
sha256 9a14d00d48738166ec1805f4adcd1c9254ef2ca0a83d90b2ccd49b59c722e9ce \
size 40429022 \
rustc-${version_m1}+0-x86_64-macports-darwin10${extract.suffix} \
rmd160 2b386ac292d8791fb9c15764aba84f793492141b \
sha256 565b7c50c16502e2bead4b450f1a5da0b1172125bb2713029720fa55dae85e4e \
size 48106670 \
cargo-${version_m1}+0-x86_64-macports-darwin10${extract.suffix} \
rmd160 b2ce7637a6be2e6a0b69dd7963af4dd3e3a3cc0b \
sha256 1c9b0135ea2ccec82e1f010dbd9de88fb886e3d51d221a98d3e177e108ed6bc7 \
size 6491725 \
rust-std-${version_m1}+0-i686-macports-darwin10${extract.suffix} \
rmd160 0b47165e6597a42408732d47d6df8779e51ef954 \
sha256 d18a7368268c90c3b0a7ecc197af328c148468ba64bd4e2aa3ee35853ec48367 \
size 39919133 \
rustc-${version_m1}+0-i686-macports-darwin10${extract.suffix} \
rmd160 e290fb055c1146a55ac0e1ad4d7f38fc8acd0675 \
sha256 71b6bb3e3623326641fbd21080e023c891801899a9682a0e37b5f6e23ed0d8f2 \
size 55839990 \
cargo-${version_m1}+0-i686-macports-darwin10${extract.suffix} \
rmd160 7f7a31d53c759776610b3503aecdec9203bfa1a6 \
sha256 8e70bca343c86aa832f35e9a331cba1bdc9aa19124e53c587f0f4eb34ff64a80 \
size 6443710 \
rust-std-${version_m1}+0-x86_64-macports-darwin9${extract.suffix} \
rmd160 970a5e9c83b0dc5e3c5054ed161c850b1c0e6dce \
sha256 43a7109c1521d0aa0195ac1e193168f46084695b18382307f07061cc2350d5ef \
size 40254089 \
rustc-${version_m1}+0-x86_64-macports-darwin9${extract.suffix} \
rmd160 2af3fe4dd112674ac013dee15d3d390cd828184f \
sha256 42103745b17b4dad3fc9691fd4a7a67435d955bd599999ff51a6507298b930e9 \
size 47869542 \
cargo-${version_m1}+0-x86_64-macports-darwin9${extract.suffix} \
rmd160 db038a289fcdc3940c4e1a69e4e5148536654436 \
sha256 8d5d4426aad99d5e3bb14e7ac434bcc6193d83bec039c9953cf5adc09aea864a \
size 6397425 \
rust-std-${version_m1}+0-i686-macports-darwin9${extract.suffix} \
rmd160 09bbda1ef1cb0953d3e318018860a1e74a1a957a \
sha256 19a935834b50f9c71fe943d16e2a2cf94d5bff921ba0c4f3296d79f20e7dd4aa \
size 39769602 \
rustc-${version_m1}+0-i686-macports-darwin9${extract.suffix} \
rmd160 3dc01b38385085bb44aeba7c1aa5a61e2014e68e \
sha256 8a008a86f1cdcca23b2efc51b93cccdaa429476b6dbc6d8587920606afa6b88a \
size 55634489 \
cargo-${version_m1}+0-i686-macports-darwin9${extract.suffix} \
rmd160 666dad68c6c04994904693a7bda5ac4f64670a70 \
sha256 1489a9c56a7bef891fd670f0eab2a8d553a9195edd4b9b7603214b3672a9268a \
size 6358152
return [lindex [split ${rustc_version} +] 0]
}
####################################################################################################################################
# for building LLVM as part of building the Rust compiler
####################################################################################################################################
options rust.llvm.legacy
default rust.llvm.legacy {[expr {${os.major} < 11}]}
options rust.llvm.cflags
default rust.llvm.cflags {[portconfigure::configure_get_cppflags] ${configure.optflags} [expr {${rust.llvm.legacy} ? "-isystem${prefix}/include/LegacySupport" : ""}]}
options rust.llvm.cxxflags
default rust.llvm.cxxflags {[portconfigure::configure_get_cppflags] ${configure.optflags} [expr {${rust.llvm.legacy} ? "-isystem${prefix}/include/LegacySupport" : ""}]}
options rust.llvm.ldflags
default rust.llvm.ldflags {[portconfigure::configure_get_ldflags] [expr {${rust.llvm.legacy} ? "${prefix}/lib/libMacportsLegacySupport.a" : ""}]}
####################################################################################################################################
# utility procedures
####################################################################################################################################
# MacPorts architecture name --> Rust architecture name
proc rust.rust_arch {arch} {
switch ${arch} {
arm64 {return aarch64}
i386 {return i686}
ppc {return powerpc}
ppc64 {return powerpc64}
default {return ${arch}}
}
}
# Rust architecture name --> MacPorts architecture name
proc rust.marcports_arch {rarch} {
switch ${rarch} {
aarch64 {return arm64}
i686 {return i386}
powerpc {return ppc}
powerpc64 {return ppc64}
default {return ${rarch}}
}
}
####################################################################################################################################
# compatibility procedures
####################################################################################################################################
proc cargo.rust_platform {{arch ""}} {
if {${arch} eq ""} {
set arch [option muniversal.build_arch]
# muniversal.build_arch is empty if we are not doing a universal build
if {${arch} eq ""} {
set arch [option configure.build_arch]
if {${arch} eq ""} {
error "No build arch configured"
}
}
}
return [option triplet.${arch}]
}
####################################################################################################################################
# internal procedures
####################################################################################################################################
namespace eval rust {}
# for symbol ___emutls_get_address (used when thread-local-storage is emulated)
#
# for Clang, provides symbol ___muloti4
# since https://github.com/rust-lang/rust/commit/8a6ff90a3a41e6ace18aeb089ea0a0eb3726dd08
#
proc rust::get_static_rutime_libraries {} {
set libs [list ]
if {[string match *clang* [option configure.compiler]]} {
set libName lib/[option os.platform]/libclang_rt.osx.a
} else {
set libName libgcc_eh.a
}
if {![catch [list exec [option configure.cc] --print-search-dirs] results]} {
foreach ln [split ${results} \n] {
set splt [split ${ln} =]
if {[lindex ${splt} 0] eq "libraries: "} {
foreach dir [split [lindex ${splt} 1] :] {
set fl [string trimright ${dir} "/"]/${libName}
if {[file exists ${fl}]} {
lappend libs ${fl}
}
}
}
}
}
return ${libs}
}
proc rust::configure_ldflags_proc {option action args} {
if {$action ne "read"} return
if {[option rust.add_compiler_runtime]} {
configure.ldflags-delete {*}[option rust.rt_static_libs]
configure.ldflags-append {*}[option rust.rt_static_libs]
}
}
option_proc configure.ldflags rust::configure_ldflags_proc
# based on portextract::disttagclean from portextract.tcl
proc rust::disttagclean {list} {
if {$list eq ""} {
return $list
}
foreach fname $list {
set name [getdistname ${fname}]
set is_crate no
foreach {cname cversion chksum} [option cargo.crates] {
set cratefile ${cname}-${cversion}.crate
if {${name} eq ${cratefile}} {
set is_crate yes
}
}
foreach {cname cgithub cbranch crevision chksum} [option cargo.crates_github] {
set cratefile ${cname}-${crevision}.tar.gz
if {${name} eq ${cratefile}} {
set is_crate yes
}
}
if {!${is_crate}} {
lappend val ${name}
}
}
return $val
}
proc rust::handle_crates {} {
foreach {cname cversion chksum} [option cargo.crates] {
# The same crate name can appear with multiple versions. Use
# a combination of crate name and checksum as unique identifier.
# As the :disttag cannot contain dots, the version number cannot be
# used.
#
# To download the crate file curl-0.4.11.crate, the URL is
# https://crates.io/api/v1/crates/curl/0.4.11/download.
# Use ?dummy= to ignore ${distfile}
# see https://trac.macports.org/wiki/PortfileRecipes#fetchwithgetparams
set cratefile ${cname}-${cversion}.crate
set cratetag crate-${cname}-${chksum}
distfiles-append ${cratefile}:${cratetag}
master_sites-append https://crates.io/api/v1/crates/${cname}/${cversion}/download?dummy=:${cratetag}
checksums-append ${cratefile} sha256 ${chksum}
}
foreach {cname cgithub cbranch crevision chksum} [option cargo.crates_github] {
set cratefile ${cname}-${crevision}.tar.gz
set cratetag crate-${cname}-${chksum}
distfiles-append ${cratefile}:${cratetag}
master_sites-append https://github.com/${cgithub}/archive/${crevision}.tar.gz?dummy=:${cratetag}
checksums-append ${cratefile} sha256 ${chksum}
}
}
port::register_callback rust::handle_crates
proc rust::extract_crate {cratefile} {
set tar [findBinary tar ${portutil::autoconf::tar_path}]
system -W "[option cargo.home]/macports" "$tar -xf [shellescape [option distpath]/${cratefile}]"
}
proc rust::write_cargo_checksum {cdirname chksum} {
# although cargo will never see the .crate, it expects to find the sha256 checksum here
set chkfile [open "[option cargo.home]/macports/${cdirname}/.cargo-checksum.json" "w"]
puts $chkfile "{"
puts $chkfile " \"package\": ${chksum},"
puts $chkfile " \"files\": {}"
puts $chkfile "}"
close $chkfile
}
proc rust::old_macos_compatibility {cname cversion} {
global cargo.home subport
switch ${cname} {
"kqueue" {
if { [vercmp ${cversion} < 1.0.5] && "i386" in [option muniversal.architectures] } {
# see https://gitlab.com/worr/rust-kqueue/-/merge_requests/10
reinplace {s|all(target_os = "freebsd", target_arch = "x86")|all(any(target_os = "freebsd", target_os = "macos"), any(target_arch = "x86", target_arch = "powerpc"))|g} \
${cargo.home}/macports/${cname}-${cversion}/src/time.rs
cargo.offline_cmd-replace --frozen --offline
}
}
"curl-sys" {
if { [vercmp ${cversion} < 0.4.56] } {
# on Mac OS X 10.6, clang exists, but `clang --print-search-dirs` returns an empty library directory
# see https://github.com/alexcrichton/curl-rust/commit/b3a3ce876921f2e82a145d9abd539cd8f9b7ab7b
# see https://trac.macports.org/ticket/64146#comment:16
#
# on other systems, we want the static library of the compiler we are using and not necessarily the system compiler
# see https://github.com/alexcrichton/curl-rust/commit/a6969c03b1e8f66bc4c801914327176ed38f44c5
# see https://github.com/alexcrichton/curl-rust/issues/279
#
# for upstream pull request, see https://github.com/alexcrichton/curl-rust/pull/451
#
reinplace "s|Command::new(\"clang\")|cc::Build::new().get_compiler().to_command()|g" \
${cargo.home}/macports/${cname}-${cversion}/build.rs
}
}
}
# rust-bootstrap requires `macosx_deployment_target` instead of `os.major`
if {[option os.platform] ne "darwin" || [vercmp [option macosx_deployment_target] >= 10.8]} {
return
}
switch ${cname} {
"crypto-hash" {
# switch crypto-hash to use openssl instead of commoncrypto
# See: https://github.com/malept/crypto-hash/issues/23
reinplace "s|target_os = \"macos\"|target_os = \"macos_disabled\"|g" \
${cargo.home}/macports/${cname}-${cversion}/src/lib.rs
reinplace "s|macos|macos_disabled|g" \
${cargo.home}/macports/${cname}-${cversion}/Cargo.toml
}
"curl-sys" {
# curl-sys requires CCDigestGetOutputSizeFromRef which is only available since macOS 10.8
# disable USE_SECTRANSP to avoid calling of CCDigestGetOutputSizeFromRef and use OpenSSL instead
# See: https://github.com/alexcrichton/curl-rust/issues/429
reinplace "s|else if target.contains(\"-apple-\")|else if target.contains(\"-apple_disabled-\")|g" \
${cargo.home}/macports/${cname}-${cversion}/build.rs
reinplace "s|macos|macos_disabled|g" \
${cargo.home}/macports/${cname}-${cversion}/Cargo.toml
}
"libgit2-sys" {
# libgit2-sys requires SSLCreateContext which is only available since macOS 10.8
# disable GIT_SECURE_TRANSPORT to avoid calling of SSLCreateContext and use OpenSSL instead
reinplace "s|else if target.contains(\"apple\")|else if target.contains(\"apple_disabled\")|g" \
${cargo.home}/macports/${cname}-${cversion}/build.rs
}
}
if {[option os.platform] ne "darwin" || [vercmp [option macosx_deployment_target] >= 10.6]} {
return
}
switch ${cname} {
"notify" {
reinplace {s|default = \["macos_fsevent"\]|default = \["macos_kqueue"\]|g} \
${cargo.home}/macports/${cname}-${cversion}/Cargo.toml
}
"cargo-util" {
reinplace {s|#\[cfg(not(target_os = "macos"))\]|#\[cfg(not(target_os = "macos_temp"))\]|g} \
${cargo.home}/macports/${cname}-${cversion}/src/paths.rs
reinplace {s|#\[cfg(target_os = "macos")\]|#\[cfg(not(target_os = "macos"))\]|g} \
${cargo.home}/macports/${cname}-${cversion}/src/paths.rs
reinplace {s|#\[cfg(not(target_os = "macos_temp"))\]|#\[cfg(target_os = "macos")\]|g} \
${cargo.home}/macports/${cname}-${cversion}/src/paths.rs
}
}
}
proc rust::import_crate {cname cversion chksum cratefile} {
global cargo.home
ui_info "Adding ${cratefile} to cargo home"
rust::extract_crate ${cratefile}
rust::write_cargo_checksum "${cname}-${cversion}" "\"${chksum}\""
rust::old_macos_compatibility ${cname} ${cversion}
}
proc rust::import_crate_github {cname cgithub crevision chksum cratefile} {
global cargo.home
set crepo [lindex [split ${cgithub} "/"] 1]
set cdirname "${crepo}-${crevision}"
ui_info "Adding ${cratefile} from github to cargo home"
rust::extract_crate ${cratefile}
rust::write_cargo_checksum ${cdirname} "null"
rust::old_macos_compatibility ${cname} ${crevision}
}
post-extract {
if {[llength ${cargo.crates}] > 0 || [llength ${cargo.crates_github}]>0} {
file mkdir "${cargo.home}/macports"
# avoid downloading files from online repository during build phase
# use a replacement for crates.io
# https://doc.rust-lang.org/cargo/reference/source-replacement.html
set conf [open "${cargo.home}/config.toml" "w"]
puts $conf "\[source\]"
puts $conf "\[source.macports\]"
puts $conf "directory = \"${cargo.home}/macports\""
puts $conf "\[source.crates-io\]"
puts $conf "replace-with = \"macports\""
puts $conf "local-registry = \"/var/empty\""
foreach {cname cgithub cbranch crevision chksum} ${cargo.crates_github} {
puts $conf "\[source.\"https://github.com/${cgithub}\"\]"
puts $conf "git = \"https://github.com/${cgithub}\""
puts $conf "branch = \"${cbranch}\""
puts $conf "replace-with = \"macports\""
}
close $conf
# import all crates
foreach {cname cversion chksum} ${cargo.crates} {
set cratefile ${cname}-${cversion}.crate
rust::import_crate ${cname} ${cversion} ${chksum} ${cratefile}
}
foreach {cname cgithub cbranch crevision chksum} ${cargo.crates_github} {
set cratefile ${cname}-${crevision}.tar.gz
rust::import_crate_github ${cname} ${cgithub} ${crevision} ${chksum} ${cratefile}
}
}
if {${subport} ne "rust" && [join [lrange [split ${subport} -] 0 1] -] ne "rust-bootstrap"} {
# see comment below concerning RUSTC and RUSTFLAGS
file mkdir "${cargo.home}"
set conf [open "${cargo.home}/config.toml" "a"]
puts $conf "\[build\]"
puts $conf "rustc = \"${prefix}/bin/rustc\""
# be sure to include all architectures in case, e.g., a 64-bit Cargo compiles a 32-bit port
foreach arch {arm64 x86_64 i386 ppc ppc64} {
puts $conf "\[target.[option triplet.${arch}]\]"
puts $conf "linker = \"[compwrap::wrap_compiler ld]\""
}
close $conf
}
}
proc rust::append_envs { var {phases {configure build destroot}} } {
foreach phase ${phases} {
${phase}.env-delete ${var}
${phase}.env-append ${var}
}
}
# Is build caching enabled ?
# WIP for now ...
#if {[tbool configure.ccache]} {
# # Enable sccache for rust caching
# depends_build-append port:sccache
# rust::append_envs RUSTC_WRAPPER=${prefix}/bin/sccache
# rust::append_envs SCCACHE_CACHE_SIZE=2G
# rust::append_envs SCCACHE_DIR=${workpath}/.sccache
#}
proc rust::set_environment {} {
global prefix configure.pkg_config_path
global subport configure.build_arch configure.universal_archs
rust::append_envs "RUST_BACKTRACE=1"
rust::append_envs CC=[compwrap::wrap_compiler cc] {build destroot}
rust::append_envs CXX=[compwrap::wrap_compiler cxx] {build destroot}
if { [option openssl.branch] ne "" } {
set openssl_ver [string map {. {}} [option openssl.branch]]
rust::append_envs OPENSSL_DIR=${prefix}/libexec/openssl${openssl_ver}
compiler.cpath-prepend ${prefix}/libexec/openssl${openssl_ver}/include
compiler.library_path-prepend ${prefix}/libexec/openssl${openssl_ver}/lib
configure.pkg_config_path-prepend ${prefix}/libexec/openssl${openssl_ver}/lib/pkgconfig
}
# Propagate pkgconfig path to build and destroot phases as well.
# Needed to work with openssl PG.
if { ${configure.pkg_config_path} ne "" } {
rust::append_envs "PKG_CONFIG_PATH=[join ${configure.pkg_config_path} :]" {build destroot}
}
if {${subport} ne "rust" && [join [lrange [split ${subport} -] 0 1] -] ne "rust-bootstrap"} {
# when CARGO_BUILD_TARGET is set or `--target` is used, RUSTFLAGS and RUSTC are ignored
# rust::append_envs "RUSTFLAGS=-C linker=[compwrap::wrap_compiler ld]"
# rust::append_envs "RUSTC=${prefix}/bin/rustc"
# see https://github.com/rust-lang/cargo/issues/4423
foreach stage {configure build destroot} {
foreach arch [option muniversal.architectures] {
${stage}.env.${arch}-append "CARGO_BUILD_TARGET=[option triplet.${arch}]"
}
}
}
}
port::register_callback rust::set_environment
proc rust::rust_pg_callback {} {
global subport \
prefix
if { ${subport} ne "rust" && [join [lrange [split ${subport} -] 0 1] -] ne "rust-bootstrap" } {
# port is *not* building Rust
depends_build-delete port:rust
depends_build-append port:rust
if { ${subport} ne "cargo" } {
# port is building neither Rust nor Cargo
depends_build-delete port:cargo
depends_build-append port:cargo
depends_skip_archcheck-delete cargo
depends_skip_archcheck-append cargo
}
} else {
# port is building Rust
if { [option rust.llvm.legacy] } {
depends_build-delete path:lib/libMacportsLegacySupport.a:legacy-support
depends_build-append path:lib/libMacportsLegacySupport.a:legacy-support
}
if { [option rust.use_cctools] } {
depends_build-delete port:cctools
depends_build-append port:cctools
depends_skip_archcheck-delete cctools
depends_skip_archcheck-append cctools
}
}
if { [option openssl.branch] ne "" } {
set openssl_ver [string map {. {}} [option openssl.branch]]
depends_lib-delete port:openssl${openssl_ver}
depends_lib-append port:openssl${openssl_ver}
}
if { [string match "macports-clang*" [option configure.compiler]] && [option os.major] < 11 } {
# by default, ld64 uses ld64-127 when 9 <= ${os.major} < 11
# Rust fails to build when architecture is x86_64 and ld64 uses ld64-127
depends_build-delete port:ld64-274
depends_build-append port:ld64-274
depends_skip_archcheck-delete ld64-274
depends_skip_archcheck-append ld64-274
configure.ldflags-delete -fuse-ld=${prefix}/bin/ld-274
configure.ldflags-append -fuse-ld=${prefix}/bin/ld-274
}
# rust-bootstrap requires `macosx_deployment_target` instead of `os.major`
if { [option os.platform] eq "darwin" && [vercmp [option macosx_deployment_target] < 10.6]} {
# __Unwind_RaiseException
depends_lib-delete port:libunwind
depends_lib-append port:libunwind
configure.ldflags-delete -lunwind
configure.ldflags-append -lunwind
if { [join [lrange [split ${subport} -] 0 1] -] eq "rust-bootstrap" } {
# Bootstrap compilers are building on newer machines to be run on older ones.
# Use libMacportsLegacySystem.B.dylib since it is able to use the `__asm("$ld$add$os10.5$...")` trick for symbols that are part of legacy-support *only* on older systems.
set legacyLib libMacportsLegacySystem.B.dylib
set dep_type lib
# code should mimic legacy-support
# see https://github.com/macports/macports-ports/blob/master/devel/legacy-support/Portfile
set max_darwin_reexport 19
if { [option configure.build_arch] eq "arm64" || [option os.major] > ${max_darwin_reexport} } {
# ${prefix}/lib/libMacportsLegacySystem.B.dylib does not exist
# see https://trac.macports.org/ticket/65255
known_fail yes
pre-fetch {
ui_error "${subport} requires libMacportsLegacySystem.B.dylib, which is provided by legacy-support"
return -code error "incompatible system configuration"
}
}
} else {
# Use the static library since the Rust compiler looks up certain symbols at *runtime* (e.g. `openat`).
# Normally, we would want the additional functionality provided by MacPorts.
# However, for reasons yet unknown, the Rust file system (sys/unix/fs.rs) functions fail when they try to use MacPorts system calls.
set legacyLib libMacportsLegacySupport.a
set dep_type build
}
# LLVM: CFPropertyListCreateWithStream, uuid_string_t
# Rust: _posix_memalign, extended _realpath, _pthread_setname_np, _copyfile_state_get
depends_${dep_type}-delete path:lib/${legacyLib}:legacy-support
depends_${dep_type}-append path:lib/${legacyLib}:legacy-support
configure.ldflags-delete -Wl,${prefix}/lib/${legacyLib}
configure.ldflags-append -Wl,${prefix}/lib/${legacyLib}
}
# sometimes Cargo.lock does not exist
post-extract {
if { ${cargo.update} } {
system -W ${worksrcpath} "${cargo.bin} --offline update"
}
}
}
port::register_callback rust::rust_pg_callback