forked from oven-sh/bun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
1433 lines (1237 loc) · 47.7 KB
/
CMakeLists.txt
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
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
cmake_minimum_required(VERSION 3.22)
cmake_policy(SET CMP0091 NEW)
cmake_policy(SET CMP0067 NEW)
set(Bun_VERSION "1.1.6")
set(WEBKIT_TAG 5fe78270f2efca3c0ee3013259776923053d5011)
set(BUN_WORKDIR "${CMAKE_CURRENT_BINARY_DIR}")
message(STATUS "Configuring Bun ${Bun_VERSION} in ${BUN_WORKDIR}")
set(CMAKE_COLOR_DIAGNOSTICS ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_C_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD_REQUIRED ON)
# WebKit uses -std=gnu++20 on non-macOS non-Windows
# If we do not set this, it will crash at startup on the first memory allocation.
if(NOT WIN32 AND NOT APPLE)
set(CMAKE_CXX_EXTENSIONS ON)
endif()
# --- Build Type ---
if(NOT CMAKE_BUILD_TYPE)
message(WARNING "No CMAKE_BUILD_TYPE value specified, defaulting to Debug.\nSet a build type with -DCMAKE_BUILD_TYPE=<Debug|Release>")
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build (Debug, Release)" FORCE)
else()
if(NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|Release)$")
message(FATAL_ERROR
"Invalid CMAKE_BUILD_TYPE value specified: ${CMAKE_BUILD_TYPE}\n"
"CMAKE_BUILD_TYPE must be Debug or Release.")
endif()
message(STATUS "The CMake build type is: ${CMAKE_BUILD_TYPE}")
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(DEBUG ON)
set(DEFAULT_ZIG_OPTIMIZE "Debug")
set(bun "bun-debug")
# COMPILE_COMMANDS
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
set(DEBUG OFF)
set(DEFAULT_ZIG_OPTIMIZE "ReleaseFast")
if(WIN32)
# lld-link will strip it for you, so we can build directly to bun.exe
set(bun "bun")
# TODO(@paperdave): Remove this
# it is enabled for the time being to make sure to catch more bugs in the experimental windows builds
set(DEFAULT_ZIG_OPTIMIZE "ReleaseSafe")
else()
if(ZIG_OPTIMIZE STREQUAL "Debug")
set(bun "bun-debug")
else()
set(bun "bun-profile")
endif()
endif()
endif()
# --- MacOS SDK ---
if(APPLE AND DEFINED ENV{CI})
set(CMAKE_OSX_DEPLOYMENT_TARGET "12.0")
endif()
if(APPLE AND NOT CMAKE_OSX_DEPLOYMENT_TARGET)
execute_process(COMMAND xcrun --show-sdk-path OUTPUT_VARIABLE SDKROOT)
string(STRIP ${SDKROOT} SDKROOT)
message(STATUS "MacOS SDK path: ${SDKROOT}")
SET(CMAKE_OSX_SYSROOT ${SDKROOT})
execute_process(COMMAND xcrun --sdk macosx --show-sdk-version OUTPUT_VARIABLE MACOSX_DEPLOYMENT_TARGET)
string(STRIP ${MACOSX_DEPLOYMENT_TARGET} MACOSX_DEPLOYMENT_TARGET)
set(CMAKE_OSX_DEPLOYMENT_TARGET ${MACOSX_DEPLOYMENT_TARGET})
# Check if current version of macOS is less than the deployment target and if so, raise an error
execute_process(COMMAND sw_vers -productVersion OUTPUT_VARIABLE MACOS_VERSION)
string(STRIP ${MACOS_VERSION} MACOS_VERSION)
if(MACOS_VERSION VERSION_LESS ${MACOSX_DEPLOYMENT_TARGET})
message(WARNING
"The current version of macOS (${MACOS_VERSION}) is less than the deployment target (${MACOSX_DEPLOYMENT_TARGET}).\n"
"The build will be incompatible with your current device due to mismatches in `icucore` versions.\n"
"To fix this, please either:\n"
" - Upgrade to at least macOS ${MACOSX_DEPLOYMENT_TARGET}\n"
" - Use `xcode-select` to switch to an SDK version <= ${MACOS_VERSION}\n"
" - Set CMAKE_OSX_DEPLOYMENT_TARGET=${MACOS_VERSION} (make sure to build all dependencies with this variable set too)"
)
endif()
endif()
if(APPLE)
message(STATUS "Building for macOS v${CMAKE_OSX_DEPLOYMENT_TARGET}")
endif()
# --- LLVM ---
# This detection is a little overkill, but it ensures that the set LLVM_VERSION matches under
# any case possible. Sorry for the complexity...
#
# Bun and WebKit must be compiled with the same compiler, so we do as much as we can to ensure that
# the compiler used for the prebuilt WebKit is the same as we install as a dependency.
#
# It has to be done before project() is called, so that CMake doesnt pick a compiler for us, but even then
# we do some extra work afterwards to double-check, and we will rerun BUN_FIND_LLVM if the compiler did not match.
#
# If the user passes -DLLVM_PREFIX, most of this logic is skipped, but we still warn if invalid.
set(LLVM_VERSION 16)
macro(BUN_FIND_LLVM)
find_program(
_LLVM_CXX_PATH
NAMES clang++-${LLVM_VERSION} clang++
PATHS ENV PATH ${PLATFORM_LLVM_SEARCH_PATHS}
DOC "Path to LLVM ${LLVM_VERSION}'s clang++ binary. Please pass -DLLVM_PREFIX with the path to LLVM"
)
if(NOT _LLVM_CXX_PATH)
message(FATAL_ERROR "Could not find LLVM ${LLVM_VERSION}, search paths: ${PLATFORM_LLVM_SEARCH_PATHS}")
endif()
set(CMAKE_CXX_COMPILER "${_LLVM_CXX_PATH}")
find_program(
_LLVM_C_PATH
NAMES clang-${LLVM_VERSION} clang
PATHS ENV PATH ${PLATFORM_LLVM_SEARCH_PATHS}
DOC "Path to LLVM ${LLVM_VERSION}'s clang binary. Please pass -DLLVM_PREFIX with the path to LLVM"
)
if(NOT _LLVM_C_PATH)
message(FATAL_ERROR "Could not find LLVM ${LLVM_VERSION}, search paths: ${PLATFORM_LLVM_SEARCH_PATHS}")
endif()
set(CMAKE_C_COMPILER "${_LLVM_C_PATH}")
find_program(
STRIP
NAMES llvm-strip
PATHS ENV PATH ${PLATFORM_LLVM_SEARCH_PATHS}
DOC "Path to LLVM ${LLVM_VERSION}'s llvm-strip binary"
)
find_program(
STRIP
NAMES strip
PATHS ENV PATH ${PLATFORM_LLVM_SEARCH_PATHS}
DOC "Path to LLVM ${LLVM_VERSION}'s llvm-strip binary"
)
find_program(
DSYMUTIL
NAMES dsymutil
PATHS ENV PATH ${PLATFORM_LLVM_SEARCH_PATHS}
DOC "Path to LLVM ${LLVM_VERSION}'s dsymutil binary"
)
find_program(
AR
NAMES llvm-ar
PATHS ENV PATH ${PLATFORM_LLVM_SEARCH_PATHS}
DOC "Path to LLVM ${LLVM_VERSION}'s llvm-ar binary"
)
find_program(
AR
NAMES ar
PATHS ENV PATH ${PLATFORM_LLVM_SEARCH_PATHS}
DOC "Path to LLVM ${LLVM_VERSION}'s llvm-ar binary"
)
find_program(
RANLIB
NAMES llvm-ranlib
PATHS ENV PATH ${PLATFORM_LLVM_SEARCH_PATHS}
DOC "Path to LLVM ${LLVM_VERSION}'s llvm-ar binary"
)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version OUTPUT_VARIABLE _tmp)
string(REGEX MATCH "version ([0-9]+)\\.([0-9]+)\\.([0-9]+)" CMAKE_CXX_COMPILER_VERSION "${_tmp}")
set(CMAKE_CXX_COMPILER_VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}")
endmacro()
if(UNIX)
if(LLVM_PREFIX)
set(PLATFORM_LLVM_SEARCH_PATHS ${LLVM_PREFIX}/bin)
else()
set(PLATFORM_LLVM_SEARCH_PATHS /usr/lib/llvm-${LLVM_VERSION}/bin /usr/lib/llvm${LLVM_VERSION}/bin /usr/bin /usr/local/bin)
if(APPLE)
set(PLATFORM_LLVM_SEARCH_PATHS /opt/homebrew/opt/llvm@${LLVM_VERSION}/bin /opt/homebrew/bin ${PLATFORM_LLVM_SEARCH_PATHS})
endif()
endif()
if(CMAKE_CXX_COMPILER)
set(_LLVM_CXX_PATH "${CMAKE_CXX_COMPILER}")
endif()
if(CMAKE_C_COMPILER)
set(_LLVM_C_PATH "${CMAKE_C_COMPILER}")
endif()
BUN_FIND_LLVM()
else()
# Windows uses Clang-CL
# TODO: good configuration in this regard. -G Ninja will pick clang-cl if possible, which should be fine for most users.
if(NOT CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER "clang-cl")
endif()
if(NOT CMAKE_CXX_COMPILER)
set(CMAKE_CXX_COMPILER "clang-cl")
endif()
find_program(
STRIP
NAMES llvm-strip
PATHS ENV PATH ${PLATFORM_LLVM_SEARCH_PATHS}
DOC "Path to LLVM ${LLVM_VERSION}'s llvm-strip binary"
)
find_program(
AR
NAMES llvm-ar
PATHS ENV PATH ${PLATFORM_LLVM_SEARCH_PATHS}
DOC "Path to LLVM ${LLVM_VERSION}'s llvm-ar binary"
)
endif()
project(Bun VERSION "${Bun_VERSION}")
# if(MSVC)
# message(FATAL_ERROR "Bun does not support building with MSVC. Please use `cmake -G Ninja` with LLVM ${LLVM_VERSION} and Ninja.")
# endif()
# More effort to prevent using the wrong C++ compiler
if(UNIX)
if((NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR(NOT CMAKE_CXX_COMPILER_VERSION MATCHES "^${LLVM_VERSION}\."))
# Attempt to auto-correct the compiler
message(STATUS "Compiler mismatch, attempting to auto-correct")
unset(_LLVM_CXX_PATH)
BUN_FIND_LLVM()
if((NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR(NOT CMAKE_CXX_COMPILER_VERSION MATCHES "^${LLVM_VERSION}\."))
message(WARNING "Expected LLVM ${LLVM_VERSION} as the C++ compiler, build may fail or break at runtime.")
endif()
endif()
endif()
message(STATUS "C++ Compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} at ${CMAKE_CXX_COMPILER}")
# --- End LLVM ---
if(NOT WIN32)
set(SHELL "bash")
set(SCRIPT_EXTENSION "sh")
else()
set(SCRIPT_EXTENSION "ps1")
# pwsh is the new powershell, powershell is the old one.
find_program(SHELL NAMES pwsh powershell)
endif()
set(DEFAULT_ON_UNLESS_APPLE ON)
if(APPLE)
set(DEFAULT_ON_UNLESS_APPLE OFF)
endif()
set(CI OFF)
if(DEFINED ENV{CI} OR DEFINED ENV{GITHUB_ACTIONS})
set(CI ON)
endif()
set(DEFAULT_USE_STATIC_LIBATOMIC ON)
set(DEFAULT_USE_DEBUG_JSC, OFF)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(DEFAULT_USE_DEBUG_JSC ON)
set(DEFAULT_LTO OFF)
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
if(CI)
set(DEFAULT_LTO ON)
else()
set(DEFAULT_LTO OFF)
endif()
endif()
if(WIN32)
set(DEFAULT_USE_DEBUG_JSC OFF)
endif()
if(UNIX AND NOT APPLE)
execute_process(COMMAND grep -w "NAME" /etc/os-release OUTPUT_VARIABLE LINUX_DISTRO)
if(${LINUX_DISTRO} MATCHES "NAME=\"(Arch|Manjaro|Artix) Linux\"|NAME=\"openSUSE Tumbleweed\"\n")
set(DEFAULT_USE_STATIC_LIBATOMIC OFF)
endif()
endif()
# -- Build Flags --
option(USE_STATIC_SQLITE "Statically link SQLite?" ${DEFAULT_ON_UNLESS_APPLE})
option(USE_CUSTOM_ZLIB "Use Bun's recommended version of zlib" ON)
option(USE_CUSTOM_BORINGSSL "Use Bun's recommended version of BoringSSL" ON)
option(USE_CUSTOM_LIBARCHIVE "Use Bun's recommended version of libarchive" ON)
option(USE_CUSTOM_MIMALLOC "Use Bun's recommended version of Mimalloc" ON)
option(USE_CUSTOM_ZSTD "Use Bun's recommended version of zstd" ON)
option(USE_CUSTOM_CARES "Use Bun's recommended version of c-ares" ON)
option(USE_CUSTOM_BASE64 "Use Bun's recommended version of libbase64" ON)
option(USE_CUSTOM_LOLHTML "Use Bun's recommended version of lolhtml" ON)
option(USE_CUSTOM_TINYCC "Use Bun's recommended version of tinycc" ON)
option(USE_CUSTOM_LIBUV "Use Bun's recommended version of libuv (Windows only)" ON)
option(USE_CUSTOM_LSHPACK "Use Bun's recommended version of ls-hpack" ON)
option(USE_BASELINE_BUILD "Build Bun for baseline (older) CPUs" OFF)
option(USE_VALGRIND "Build Bun with Valgrind support (Linux only)" OFF)
option(ZIG_OPTIMIZE "Optimization level for Zig" ${DEFAULT_ZIG_OPTIMIZE})
option(USE_DEBUG_JSC "Enable assertions and use a debug build of JavaScriptCore" ${DEFAULT_USE_DEBUG_JSC})
option(USE_UNIFIED_SOURCES "Use unified sources to speed up the build" OFF)
option(USE_STATIC_LIBATOMIC "Statically link libatomic, requires the presence of libatomic.a" ${DEFAULT_USE_STATIC_LIBATOMIC})
option(USE_LTO "Enable Link-Time Optimization" ${DEFAULT_LTO})
if(NOT ZIG_LIB_DIR)
cmake_path(SET ZIG_LIB_DIR NORMALIZE "${CMAKE_CURRENT_SOURCE_DIR}/src/deps/zig/lib")
endif()
if(USE_VALGRIND)
# Disable SIMD
set(USE_BASELINE_BUILD ON)
if(ARCH STREQUAL "x86_64")
# This is for picohttpparser
# Valgrind cannot handle SSE4.2 instructions
add_compile_definitions("__SSE4_2__=0")
endif()
endif()
if(NOT CANARY)
set(CANARY 0)
endif()
if(NOT ZIG_OPTIMIZE)
set(ZIG_OPTIMIZE ${DEFAULT_ZIG_OPTIMIZE})
endif()
set(ERROR_LIMIT 100 CACHE STRING "Maximum number of errors to show when compiling C++ code")
set(ARCH x86_64)
set(HOMEBREW_PREFIX "/usr/local")
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|arm")
set(ARCH aarch64)
set(HOMEBREW_PREFIX "/opt/homebrew")
endif()
if(NOT CPU_TARGET)
if(DEFINED ENV{CPU_TARGET})
set(CPU_TARGET $ENV{CPU_TARGET})
else()
set(CPU_TARGET "native" CACHE STRING "CPU target for the compiler" FORCE)
if(ARCH STREQUAL "x86_64")
if(USE_BASELINE_BUILD)
set(CPU_TARGET "nehalem")
else()
set(CPU_TARGET "haswell")
endif()
endif()
endif()
endif()
message(STATUS "Building for CPU Target: ${CPU_TARGET}")
if(NOT ZIG_TARGET)
set(ZIG_TARGET "native")
if(WIN32)
set(ZIG_TARGET "${ARCH}-windows-msvc")
endif()
endif()
set(CONFIGURE_DEPENDS "CONFIGURE_DEPENDS")
if(NO_CONFIGURE_DEPENDS)
set(CONFIGURE_DEPENDS "")
endif()
# --- CLI Paths ---
set(REQUIRED_IF_NOT_ONLY_CPP_OR_LINK "")
if(NOT BUN_CPP_ONLY AND NOT BUN_LINK_ONLY)
set(REQUIRED_IF_NOT_ONLY_CPP_OR_LINK "REQUIRED")
endif()
# Zig Compiler
function(validate_zig validator_result_var item)
set(${validator_result_var} FALSE PARENT_SCOPE)
# We will allow any valid zig compiler, as long as it contains some text from `zig zen`
# Ideally we would do a version or feature check, but that would be quite slow
execute_process(COMMAND ${item} zen OUTPUT_VARIABLE ZIG_ZEN_OUTPUT)
if(ZIG_ZEN_OUTPUT MATCHES "Together we serve the users")
set(${validator_result_var} TRUE PARENT_SCOPE)
else()
set(${validator_result_var} FALSE PARENT_SCOPE)
endif()
endfunction()
if(ZIG_COMPILER)
if(ZIG_COMPILER STREQUAL "system")
message(STATUS "Using system Zig compiler")
unset(ZIG_COMPILER_)
endif()
find_program(ZIG_COMPILER_ zig ${REQUIRED_IF_NOT_ONLY_CPP_OR_LINK} DOC "Path to the Zig compiler" VALIDATOR validate_zig)
set(ZIG_COMPILER "${ZIG_COMPILER_}")
message(STATUS "Found Zig Compiler: ${ZIG_COMPILER}")
elseif(NOT BUN_CPP_ONLY AND NOT BUN_LINK_ONLY)
execute_process(
COMMAND "${SHELL}"
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/download-zig.${SCRIPT_EXTENSION}"
)
set(ZIG_COMPILER "${CMAKE_CURRENT_SOURCE_DIR}/.cache/zig/zig")
if(WIN32)
set(ZIG_COMPILER "${ZIG_COMPILER}.exe")
endif()
if(NOT EXISTS "${ZIG_COMPILER}")
unset(ZIG_COMPILER)
message(FATAL_ERROR "Auto-installation of Zig failed. Please pass -DZIG_COMPILER=system or a path to the Zig")
endif()
message(STATUS "Installed Zig Compiler: ${ZIG_COMPILER}")
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "build.zig")
endif()
# Bun
find_program(BUN_EXECUTABLE bun ${REQUIRED_IF_NOT_ONLY_CPP_OR_LINK} DOC "Path to an already built release of Bun")
message(STATUS "Found Bun: ${BUN_EXECUTABLE}")
if(WIN32 AND NO_CODEGEN)
# TODO(@paperdave): remove this, see bun-windows.yml's comment.
set(BUN_EXECUTABLE "echo")
endif()
# Prettier
find_program(PRETTIER prettier DOC "Path to prettier" PATHS ./node_modules/.bin ENV PATH)
# Esbuild (TODO: switch these to "bun build")
find_program(ESBUILD esbuild DOC "Path to esbuild" PATHS ./node_modules/.bin ENV PATH)
# Ruby (only needed for unified sources)
if(USE_UNIFIED_SOURCES)
# ruby 'WebKit/Source/WTF/Scripts/generate-unified-source-bundles.rb' source_list.txt --source-tree-path . --derived-sources-path build/unified-sources
find_program(RUBY ruby DOC "Path to ruby")
endif()
# CCache
find_program(CCACHE_PROGRAM sccache)
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
message(STATUS "Using ccache: ${CCACHE_PROGRAM}")
endif()
# --- WebKit ---
# WebKit is either prebuilt and distributed via NPM, or you can pass WEBKIT_DIR to use a local build.
# We cannot include their CMake build files (TODO: explain why, for now ask @paperdave why)
#
# On Unix, this will pull from NPM the single package that is needed and use that
if(WIN32)
set(STATIC_LIB_EXT "lib")
set(libJavaScriptCore "JavaScriptCore")
set(libWTF "WTF")
else()
set(STATIC_LIB_EXT "a")
set(libJavaScriptCore "libJavaScriptCore")
set(libWTF "libWTF")
endif()
if(NOT WEBKIT_DIR)
set(BUN_WEBKIT_PACKAGE_NAME_SUFFIX "")
set(ASSERT_ENABLED "0")
if(USE_DEBUG_JSC)
add_compile_definitions("BUN_DEBUG=1")
set(BUN_WEBKIT_PACKAGE_NAME_SUFFIX "-debug")
set(ASSERT_ENABLED "1")
elseif(NOT DEBUG AND NOT WIN32)
# Avoid waiting for LTO in local release builds outside of CI
if(USE_LTO)
set(BUN_WEBKIT_PACKAGE_NAME_SUFFIX "-lto")
else()
set(BUN_WEBKIT_PACKAGE_NAME_SUFFIX "")
endif()
set(ASSERT_ENABLED "0")
endif()
if(WIN32)
set(BUN_WEBKIT_PACKAGE_PLATFORM "windows")
elseif(APPLE)
set(BUN_WEBKIT_PACKAGE_PLATFORM "macos")
else()
set(BUN_WEBKIT_PACKAGE_PLATFORM "linux")
endif()
if(ARCH STREQUAL "x86_64")
set(BUN_WEBKIT_PACKAGE_ARCH "amd64")
elseif(ARCH MATCHES "aarch64|arm64|arm")
set(BUN_WEBKIT_PACKAGE_ARCH "arm64")
endif()
set(BUN_WEBKIT_PACKAGE_NAME "bun-webkit-${BUN_WEBKIT_PACKAGE_PLATFORM}-${BUN_WEBKIT_PACKAGE_ARCH}${BUN_WEBKIT_PACKAGE_NAME_SUFFIX}")
message(STATUS "Using Pre-built WebKit: ${BUN_WEBKIT_PACKAGE_NAME}")
execute_process(
COMMAND "${SHELL}"
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/download-webkit.${SCRIPT_EXTENSION}"
"${BUN_WORKDIR}/bun-webkit"
"${WEBKIT_TAG}"
"${BUN_WEBKIT_PACKAGE_NAME}"
WORKING_DIRECTORY ${BUN_WORKDIR}
)
if(NOT EXISTS "${BUN_WORKDIR}/bun-webkit")
message(FATAL_ERROR "Prebuilt WebKit package ${BUN_WEBKIT_PACKAGE_NAME} failed to install")
endif()
set(WEBKIT_INCLUDE_DIR "${BUN_WORKDIR}/bun-webkit/include")
if(APPLE)
set(ICU_INCLUDE_DIR "")
else()
set(ICU_INCLUDE_DIR "${BUN_WORKDIR}/bun-webkit/include/wtf/unicode")
endif()
set(WEBKIT_LIB_DIR "${BUN_WORKDIR}/bun-webkit/lib")
elseif(WEBKIT_DIR STREQUAL "omit")
message(STATUS "Not using WebKit. This is only valid if you are only trying to build Zig code")
else()
# Expected to be WebKit/WebKitBuild/${CMAKE_BUILD_TYPE}
if(EXISTS "${WEBKIT_DIR}/cmakeconfig.h")
# You may need to run:
# make jsc-compile-debug jsc-copy-headers
include_directories(
"${WEBKIT_DIR}/"
"${WEBKIT_DIR}/JavaScriptCore/Headers/JavaScriptCore"
"${WEBKIT_DIR}/JavaScriptCore/PrivateHeaders"
"${WEBKIT_DIR}/bmalloc/Headers"
"${WEBKIT_DIR}/WTF/Headers"
)
set(WEBKIT_LIB_DIR "${WEBKIT_DIR}/lib")
if(USE_DEBUG_JSC)
add_compile_definitions("BUN_DEBUG=1")
set(ASSERT_ENABLED "1")
endif()
message(STATUS "Using WebKit from ${WEBKIT_DIR}")
else()
if(NOT EXISTS "${WEBKIT_DIR}/lib/${libWTF}.${STATIC_LIB_EXT}" OR NOT EXISTS "${WEBKIT_DIR}/lib/${libJavaScriptCore}.${STATIC_LIB_EXT}")
if(WEBKIT_DIR MATCHES "src/bun.js/WebKit$")
message(FATAL_ERROR "WebKit directory ${WEBKIT_DIR} does not contain all the required files for Bun. Did you forget to init submodules?")
endif()
message(FATAL_ERROR "WebKit directory ${WEBKIT_DIR} does not contain all the required files for Bun. Expected a path to the oven-sh/WebKit repository, or a path to a folder containing `include` and `lib`.")
endif()
set(WEBKIT_INCLUDE_DIR "${WEBKIT_DIR}/include")
set(WEBKIT_LIB_DIR "${WEBKIT_DIR}/lib")
message(STATUS "Using specified WebKit directory: ${WEBKIT_DIR}")
set(ASSERT_ENABLED "0")
message(STATUS "WebKit assertions: OFF")
endif()
endif()
# --- CMake Macros ---
# Append the given dependencies to the source file
macro(WEBKIT_ADD_SOURCE_DEPENDENCIES _source _deps)
set(_tmp)
get_source_file_property(_tmp ${_source} OBJECT_DEPENDS)
if(NOT _tmp)
set(_tmp "")
endif()
foreach(f ${_deps})
list(APPEND _tmp "${f}")
endforeach()
set_source_files_properties(${_source} PROPERTIES OBJECT_DEPENDS "${_tmp}")
unset(_tmp)
endmacro()
# --- BUILD ---
set(BUN_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src")
set(BUN_DEPS_DIR "${BUN_SRC}/deps")
set(BUN_CODEGEN_SRC "${BUN_SRC}/codegen")
if(NOT BUN_DEPS_OUT_DIR)
set(BUN_DEPS_OUT_DIR "${BUN_DEPS_DIR}")
endif()
set(BUN_RAW_SOURCES, "")
file(GLOB BUN_CPP ${CONFIGURE_DEPENDS}
"${BUN_SRC}/deps/*.cpp"
"${BUN_SRC}/io/*.cpp"
"${BUN_SRC}/bun.js/modules/*.cpp"
"${BUN_SRC}/bun.js/bindings/*.cpp"
"${BUN_SRC}/bun.js/bindings/webcore/*.cpp"
"${BUN_SRC}/bun.js/bindings/sqlite/*.cpp"
"${BUN_SRC}/bun.js/bindings/webcrypto/*.cpp"
"${BUN_SRC}/bun.js/bindings/webcrypto/*/*.cpp"
"${BUN_SRC}/deps/picohttpparser/picohttpparser.c"
)
list(APPEND BUN_RAW_SOURCES ${BUN_CPP})
# -- Brotli --
set(BROTLI_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/deps/brotli")
file(GLOB BROTLI_FILES ${CONFIGURE_DEPENDS}
"${BROTLI_SRC}/common/*.c"
"${BROTLI_SRC}/enc/*.c"
"${BROTLI_SRC}/dec/*.c"
)
list(APPEND BUN_RAW_SOURCES ${BROTLI_FILES})
include_directories("${BUN_DEPS_DIR}/brotli/include")
# -- uSockets --
set(USOCKETS_SRC "${CMAKE_CURRENT_SOURCE_DIR}/packages/bun-usockets/src")
file(GLOB USOCKETS_FILES ${CONFIGURE_DEPENDS}
"${USOCKETS_SRC}/*.c"
"${USOCKETS_SRC}/eventing/*.c"
"${USOCKETS_SRC}/internal/*.c"
"${USOCKETS_SRC}/crypto/*.c"
"${USOCKETS_SRC}/crypto/*.cpp"
)
list(APPEND BUN_RAW_SOURCES ${USOCKETS_FILES})
# --- Classes Generator ---
file(GLOB BUN_CLASSES_TS ${CONFIGURE_DEPENDS}
"${BUN_SRC}/bun.js/*.classes.ts"
"${BUN_SRC}/bun.js/api/*.classes.ts"
"${BUN_SRC}/bun.js/test/*.classes.ts"
"${BUN_SRC}/bun.js/webcore/*.classes.ts"
"${BUN_SRC}/bun.js/node/*.classes.ts"
)
add_custom_command(
OUTPUT "${BUN_WORKDIR}/codegen/ZigGeneratedClasses.h"
"${BUN_WORKDIR}/codegen/ZigGeneratedClasses.cpp"
"${BUN_WORKDIR}/codegen/ZigGeneratedClasses+lazyStructureHeader.h"
"${BUN_WORKDIR}/codegen/ZigGeneratedClasses+DOMClientIsoSubspaces.h"
"${BUN_WORKDIR}/codegen/ZigGeneratedClasses+DOMIsoSubspaces.h"
"${BUN_WORKDIR}/codegen/ZigGeneratedClasses+lazyStructureImpl.h"
"${BUN_WORKDIR}/codegen/ZigGeneratedClasses.zig"
COMMAND ${BUN_EXECUTABLE} run "${BUN_CODEGEN_SRC}/generate-classes.ts" ${BUN_CLASSES_TS} "${BUN_WORKDIR}/codegen"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
MAIN_DEPENDENCY "${BUN_CODEGEN_SRC}/generate-classes.ts"
DEPENDS ${BUN_CLASSES_TS}
VERBATIM
COMMENT "Generating *.classes.ts bindings"
)
list(APPEND BUN_RAW_SOURCES "${BUN_WORKDIR}/codegen/ZigGeneratedClasses.cpp")
# --- JSSink Generator ---
add_custom_command(
OUTPUT "${BUN_WORKDIR}/codegen/JSSink.cpp"
"${BUN_WORKDIR}/codegen/JSSink.h"
COMMAND ${BUN_EXECUTABLE} run "src/codegen/generate-jssink.ts" "${BUN_WORKDIR}/codegen"
VERBATIM
MAIN_DEPENDENCY "src/codegen/generate-jssink.ts"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating JSSink"
USES_TERMINAL
)
list(APPEND BUN_RAW_SOURCES "${BUN_WORKDIR}/codegen/JSSink.cpp")
# --- .lut.h Generator ---
set(BUN_OBJECT_LUT_SOURCES
bun.js/bindings/BunObject.cpp
bun.js/bindings/ZigGlobalObject.lut.txt
bun.js/bindings/JSBuffer.cpp
bun.js/bindings/BunProcess.cpp
bun.js/bindings/ProcessBindingConstants.cpp
bun.js/bindings/ProcessBindingNatives.cpp
)
set(BUN_OBJECT_LUT_OUTPUTS "")
set(BUN_HASH_LUT_GENERATOR "${BUN_CODEGEN_SRC}/create-hash-table.ts")
if(NOT BUN_LINK_ONLY)
macro(GENERATE_HASH_LUT _input _output _display_name)
if(NOT NO_CODEGEN)
add_custom_command(
OUTPUT ${_output}
MAIN_DEPENDENCY ${BUN_HASH_LUT_GENERATOR}
DEPENDS ${_input}
COMMAND ${BUN_EXECUTABLE} run ${BUN_HASH_LUT_GENERATOR} ${_input} ${_output}
VERBATIM
COMMENT "Generating ${_display_name}"
)
endif()
list(APPEND BUN_OBJECT_LUT_OUTPUTS "${_output}")
# list(APPEND Bun_HEADERS ${_output})
WEBKIT_ADD_SOURCE_DEPENDENCIES(${_input} ${_output})
endmacro()
foreach(_file ${BUN_OBJECT_LUT_SOURCES})
if(NOT EXISTS "${BUN_SRC}/${_file}")
message(FATAL_ERROR "Could not find ${_file} needed for LUT generation")
endif()
get_filename_component(_name ${_file} NAME_WE)
# workaround for ZigGlobalObject
if(_name MATCHES "ZigGlobalObject")
set(_name "ZigGlobalObject")
endif()
GENERATE_HASH_LUT(${BUN_SRC}/${_file} ${BUN_WORKDIR}/codegen/${_name}.lut.h ${_name}.lut.h)
endforeach()
WEBKIT_ADD_SOURCE_DEPENDENCIES(${BUN_SRC}/bun.js/bindings/ZigGlobalObject.cpp ${BUN_WORKDIR}/codegen/ZigGlobalObject.lut.h)
endif()
# --- Identifier Cache ---
if(NOT NO_CODEGEN)
set(BUN_IDENTIFIER_CACHE_OUT
"${BUN_SRC}/js_lexer/id_continue_bitset.blob"
"${BUN_SRC}/js_lexer/id_continue_bitset.meta.blob"
"${BUN_SRC}/js_lexer/id_start_bitset.blob"
"${BUN_SRC}/js_lexer/id_start_bitset.meta.blob")
add_custom_command(
OUTPUT ${BUN_IDENTIFIER_CACHE_OUT}
MAIN_DEPENDENCY "${BUN_SRC}/js_lexer/identifier_data.zig"
DEPENDS "${BUN_SRC}/js_lexer/identifier_cache.zig"
COMMAND ${ZIG_COMPILER} run "--zig-lib-dir" "${ZIG_LIB_DIR}" "${BUN_SRC}/js_lexer/identifier_data.zig"
VERBATIM
COMMENT "Building Identifier Cache"
)
endif()
# --- Bundled TS/JS ---
# Note: It's not worth doing this in parallel at the CMake/Ninja level, because this bundling
# requires all the JS files to be known, but also Bun will use all cores during bundling anyways.
if(NOT NO_CODEGEN)
file(GLOB BUN_TS_MODULES ${CONFIGURE_DEPENDS}
"${BUN_SRC}/js/node/*.ts"
"${BUN_SRC}/js/node/*.js"
"${BUN_SRC}/js/bun/*.ts"
"${BUN_SRC}/js/bun/*.js"
"${BUN_SRC}/js/builtins/*.ts"
"${BUN_SRC}/js/builtins/*.js"
"${BUN_SRC}/js/thirdparty/*.js"
"${BUN_SRC}/js/thirdparty/*.ts"
"${BUN_SRC}/js/internal/*.js"
"${BUN_SRC}/js/internal/*.ts"
"${BUN_SRC}/js/node/*.js"
"${BUN_SRC}/js/node/*.ts"
"${BUN_SRC}/js/thirdparty/*.js"
"${BUN_SRC}/js/thirdparty/*.ts"
"${BUN_SRC}/js/internal-for-testing.ts"
)
file(GLOB CODEGEN_FILES ${CONFIGURE_DEPENDS} "${BUN_CODEGEN_SRC}/*.ts")
add_custom_command(
OUTPUT
"${BUN_WORKDIR}/codegen/WebCoreJSBuiltins.cpp"
"${BUN_WORKDIR}/codegen/WebCoreJSBuiltins.h"
"${BUN_WORKDIR}/codegen/InternalModuleRegistryConstants.h"
"${BUN_WORKDIR}/codegen/InternalModuleRegistry+createInternalModuleById.h"
"${BUN_WORKDIR}/codegen/InternalModuleRegistry+enum.h"
"${BUN_WORKDIR}/codegen/InternalModuleRegistry+numberOfModules.h"
"${BUN_WORKDIR}/codegen/NativeModuleImpl.h"
"${BUN_WORKDIR}/codegen/ResolvedSourceTag.zig"
"${BUN_WORKDIR}/codegen/SyntheticModuleType.h"
"${BUN_WORKDIR}/codegen/GeneratedJS2Native.h"
"${BUN_SRC}/bun.js/bindings/GeneratedJS2Native.zig"
COMMAND ${BUN_EXECUTABLE} run "${BUN_SRC}/codegen/bundle-modules.ts" "--debug=${DEBUG}" "${BUN_WORKDIR}"
DEPENDS ${BUN_TS_MODULES} ${CODEGEN_FILES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Bundling JS"
)
endif()
WEBKIT_ADD_SOURCE_DEPENDENCIES(
"${BUN_SRC}/bun.js/bindings/InternalModuleRegistry.cpp"
"${BUN_WORKDIR}/codegen/InternalModuleRegistryConstants.h"
)
list(APPEND BUN_RAW_SOURCES "${BUN_WORKDIR}/codegen/WebCoreJSBuiltins.cpp")
# --- Peechy API ---
# if(NOT NO_CODEGEN)
# add_custom_command(
# OUTPUT "${BUN_SRC}/api/schema.js"
# "${BUN_SRC}/api/schema.d.ts"
# "${BUN_SRC}/api/schema.zig"
# WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
# COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/node_modules/.bin/peechy"
# "--schema" "${BUN_SRC}/api/schema.peechy"
# "--esm" "${BUN_SRC}/api/schema.js"
# "--ts" "${BUN_SRC}/api/schema.d.ts"
# "--zig" "${BUN_SRC}/api/schema.zig"
# COMMAND "${ZIG_COMPILER}" "fmt" "src/api/schema.zig"
# COMMAND "${PRETTIER}" "--config=.prettierrc.cjs" "--write" "src/api/schema.js" "src/api/schema.d.ts"
# DEPENDS "${BUN_SRC}/api/schema.peechy"
# COMMENT "Building schema"
# )
# add_custom_command(
# OUTPUT "${BUN_SRC}/analytics/analytics_schema.zig"
# WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
# COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/node_modules/.bin/peechy"
# "--schema" "${BUN_SRC}/analytics/schema.peechy"
# "--zig" "${BUN_SRC}/analytics/analytics_schema.zig"
# COMMAND "${ZIG_COMPILER}" "fmt" "${BUN_SRC}/analytics/analytics_schema.zig"
# DEPENDS "${BUN_SRC}/api/schema.peechy"
# COMMENT "Building analytics_schema.zig"
# )
# endif()
# --- Runtime.js ---
if(NOT NO_CODEGEN)
add_custom_command(
OUTPUT "src/fallback.out.js"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND "${ESBUILD}" "--target=esnext" "--bundle" "src/fallback.ts" "--format=iife" "--platform=browser" "--minify" "--outfile=src/fallback.out.js"
DEPENDS "src/fallback.ts"
)
endif()
# --- Zig Object ---
file(GLOB ZIG_FILES
"${BUN_SRC}/*.zig"
"${BUN_SRC}/*/*.zig"
"${BUN_SRC}/*/*/*.zig"
"${BUN_SRC}/*/*/*/*.zig"
"${BUN_SRC}/*/*/*/*/*.zig"
)
if(NOT BUN_ZIG_OBJ)
set(BUN_ZIG_OBJ "${BUN_WORKDIR}/CMakeFiles/bun-zig.o")
endif()
get_filename_component(BUN_ZIG_OBJ "${BUN_ZIG_OBJ}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
set(USES_TERMINAL_NOT_IN_CI "")
if(NOT CI)
set(USES_TERMINAL_NOT_IN_CI "USES_TERMINAL")
endif()
if(NOT BUN_LINK_ONLY AND NOT BUN_CPP_ONLY)
add_custom_command(
OUTPUT "${BUN_ZIG_OBJ}"
COMMAND
"${ZIG_COMPILER}" "build" "obj"
"--zig-lib-dir" "${ZIG_LIB_DIR}"
"-Doutput-file=${BUN_ZIG_OBJ}"
"-Dgenerated-code=${BUN_WORKDIR}/codegen"
"-freference-trace=10"
"-Dversion=${Bun_VERSION}"
"-Dcanary=${CANARY}"
"-Doptimize=${ZIG_OPTIMIZE}"
"-Dcpu=${CPU_TARGET}"
"-Dtarget=${ZIG_TARGET}"
DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/build.zig"
"${ZIG_FILES}"
"${BUN_WORKDIR}/codegen/ZigGeneratedClasses.zig"
"${BUN_WORKDIR}/codegen/ResolvedSourceTag.zig"
"${BUN_IDENTIFIER_CACHE_OUT}"
"${BUN_SRC}/api/schema.zig"
"${BUN_SRC}/bun.js/bindings/GeneratedJS2Native.zig"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Building zig code"
VERBATIM
# This is here to show Zig's progress indicator
${USES_TERMINAL_NOT_IN_CI}
)
endif()
if(WIN32)
list(APPEND BUN_RAW_SOURCES "${BUN_SRC}/bun.js/bindings/windows/musl-memmem.c")
include_directories("${BUN_SRC}/bun.js/bindings/windows")
endif()
if(NOT BUN_CPP_ARCHIVE)
# TODO: unified sources
set(BUN_SOURCES ${BUN_RAW_SOURCES})
else()
# used by ci
set(BUN_SOURCES "")
add_link_options("${BUN_CPP_ARCHIVE}")
endif()
# -- Windows resources (app icon) --
if(CANARY GREATER 0)
set(Bun_VERSION_WITH_TAG "${Bun_VERSION}-canary.${CANARY}")
else()
set(Bun_VERSION_WITH_TAG "${Bun_VERSION}")
endif()
if(WIN32)
set(BUN_ICO_PATH "${BUN_SRC}/bun.ico")
configure_file("${BUN_SRC}/windows-app-info.rc" "${BUN_WORKDIR}/CMakeFiles/windows-app-info.rc")
list(APPEND BUN_SOURCES "${BUN_WORKDIR}/CMakeFiles/windows-app-info.rc")
endif()
# -- The Buntime™️ ---
if(NOT BUN_CPP_ONLY)
add_executable(${bun} "${BUN_SOURCES}" "${BUN_ZIG_OBJ}")
else()
add_executable(${bun} "${BUN_SOURCES}")
endif()
set_target_properties(${bun} PROPERTIES
CXX_STANDARD 20
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS YES
CXX_VISIBILITY_PRESET hidden
C_STANDARD 17
C_STANDARD_REQUIRED YES
VISIBILITY_INLINES_HIDDEN YES
)
add_compile_definitions(
# TODO: are all of these variables strictly necessary?
"_HAS_EXCEPTIONS=0"
"LIBUS_USE_OPENSSL=1"
"UWS_HTTPRESPONSE_NO_WRITEMARK=1"
"LIBUS_USE_BORINGSSL=1"
"WITH_BORINGSSL=1"
"STATICALLY_LINKED_WITH_JavaScriptCore=1"
"STATICALLY_LINKED_WITH_WTF=1"
"STATICALLY_LINKED_WITH_BMALLOC=1"
"BUILDING_WITH_CMAKE=1"
"JSC_OBJC_API_ENABLED=0"
"BUN_SINGLE_THREADED_PER_VM_ENTRY_SCOPE=1"
"NAPI_EXPERIMENTAL=ON"
"NOMINMAX"
"IS_BUILD"
"BUILDING_JSCONLY__"
"BUN_DYNAMIC_JS_LOAD_PATH=\"${BUN_WORKDIR}/js\""
)
if(NOT ASSERT_ENABLED)
add_compile_definitions("NDEBUG=1")
else()
add_compile_definitions("ASSERT_ENABLED=1")
endif()
if(ICU_INCLUDE_DIR)
include_directories(${ICU_INCLUDE_DIR})
endif()
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/packages/
${CMAKE_CURRENT_SOURCE_DIR}/packages/bun-usockets
${CMAKE_CURRENT_SOURCE_DIR}/packages/bun-usockets/src
${CMAKE_CURRENT_SOURCE_DIR}/src/bun.js/bindings
${CMAKE_CURRENT_SOURCE_DIR}/src/bun.js/bindings/webcore
${CMAKE_CURRENT_SOURCE_DIR}/src/bun.js/bindings/webcrypto
${CMAKE_CURRENT_SOURCE_DIR}/src/bun.js/bindings/sqlite
${CMAKE_CURRENT_SOURCE_DIR}/src/bun.js/modules
${CMAKE_CURRENT_SOURCE_DIR}/src/js/builtins
${CMAKE_CURRENT_SOURCE_DIR}/src/napi
${CMAKE_CURRENT_SOURCE_DIR}/src/deps
${CMAKE_CURRENT_SOURCE_DIR}/src/deps/picohttpparser
${WEBKIT_INCLUDE_DIR}
"${BUN_WORKDIR}/codegen"
)
# -- BUN_CPP_ONLY Target
if(NOT BUN_CPP_ARCHIVE)
if(BUN_CPP_ONLY)
if(NOT WIN32)
string(REPLACE ";" ".o\n " BUN_OBJECT_LIST "${BUN_SOURCES}.o")
string(REPLACE "${BUN_WORKDIR}/" "CMakeFiles/${bun}.dir/" BUN_OBJECT_LIST "${BUN_OBJECT_LIST}")
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "CMakeFiles/${bun}.dir/" BUN_OBJECT_LIST "${BUN_OBJECT_LIST}")
write_file("${BUN_WORKDIR}/compile-cpp-only.sh"
"#!/usr/bin/env bash\n"
"# this file is generated in CMakeLists.txt\n"
"set -ex\n"
"OBJ_LIST=(\n ${BUN_OBJECT_LIST}\n)\n"
"ninja \${OBJ_LIST[@]} $@\n"
"\"${AR}\" rcvs bun-cpp-objects.a \${OBJ_LIST[@]}\n"
"echo '-> bun-cpp-objects.a'\n"
)
else()
string(REPLACE ";" ".obj\",\n \"" BUN_OBJECT_LIST "\"${BUN_SOURCES}.obj\"")
string(REPLACE "rc.obj" "rc.res" BUN_OBJECT_LIST "${BUN_OBJECT_LIST}")