move src/clangdCommands.bqn to build/build clangd

This commit is contained in:
dzaima 2023-02-17 18:39:27 +02:00
parent f76836aedd
commit 0aada6163a
4 changed files with 129 additions and 109 deletions

View File

@ -37,9 +37,10 @@ opts ← ⟨
2, "rm_lf", , "forcibly remove linker flag(s)" 2, "rm_lf", , "forcibly remove linker flag(s)"
0, "v", @, "Version to report by --version; 'v=' to use git commit"@+10 0, "v", @, "Version to report by --version; 'v=' to use git commit"@+10
1, "shared", 0, "build a shared library; default output is libcbqn.[so|dylib]" 1, "shared", 0, "Build a shared library; default output is libcbqn.[so|dylib]"
1, "wasi", 0, "build with WASI; default output name is BQN.wasm" 1, "wasi", 0, "Build with WASI; default output name is BQN.wasm"
1, "emcc", 0, "build with emscripten; outputs BQN.wasm & BQN.js in a folder" 1, "emcc", 0, "Build with emscripten; outputs two files - BQN.wasm and BQN.js"
1, "clangd", 0, "Don't build, instead generate a compile_commands.json for clangd"@+10
1, "FFI", @, "Enable FFI through libffi; On by default, except for WASM builds" 1, "FFI", @, "Enable FFI through libffi; On by default, except for WASM builds"
1, "pkgconfig", 1, "Attempt to use pkg-config to find libffi flags" 1, "pkgconfig", 1, "Attempt to use pkg-config to find libffi flags"
@ -132,7 +133,7 @@ AtRoot ← rootDir⊸•file.At
po { # parsed options po { # parsed options
verbose, J, rebuildAll, tui, output, versionName, verbose, J, rebuildAll, tui, output, clangd, versionName,
os, arch, native, os, arch, native,
emcc, wasm, replxx, singeli, emcc, wasm, replxx, singeli,
ffi, o3, ffi, o3,
@ -141,6 +142,7 @@ po ← { # parsed options
custom GetOpt "c" custom GetOpt "c"
clangd GetOpt "clangd"
DOpt {@,𝕨 GetOpt 𝕩} DOpt {@,𝕨 GetOpt 𝕩}
J {𝕊: vGetOpt "j" v@? •BQN v; •BQN4 "4" TrySH "nproc"} J {𝕊: vGetOpt "j" v@? •BQN v; •BQN4 "4" TrySH "nproc"}
rebuildAll GetOpt "rebuild" rebuildAll GetOpt "rebuild"
@ -210,7 +212,7 @@ po ← { # parsed options
{𝕊: "Output location: "𝕩}_verboseLog output {𝕊: "Output location: "𝕩}_verboseLog output
CBQNc { 𝕊: CBQNc { 𝕊:
isClang ´"clang"SH cc"--version" # TODO exclude from hash? isClang {clangd? 1; ´"clang"SH cc"--version"} # TODO exclude from hash?
args args
cc, cc,
"-std=gnu11", "-std=gnu11",
@ -226,6 +228,8 @@ po ← { # parsed options
args 0GetLibs@ args 0GetLibs@
color (GetOpt "color") ¬clangd
args GetOpt "f" args GetOpt "f"
args GetOpt "CCFLAGS" args GetOpt "CCFLAGS"
args (singeliarch "x86-64") / "-DSINGELI_X86_64" args (singeliarch "x86-64") / "-DSINGELI_X86_64"
@ -238,7 +242,7 @@ po ← { # parsed options
args ( o3) / "-O3" args ( o3) / "-O3"
args ( native) / "-march=native" args ( native) / "-march=native"
args ( debug) / "-DDEBUG" args ( debug) / "-DDEBUG"
args ( GetOpt "color") / isClang"-fdiagnostics-color=always""-fcolor-diagnostics" # TODO exclude from hash? args ( color) / isClang"-fdiagnostics-color=always""-fcolor-diagnostics" # TODO exclude from hash?
args ( GetOpt "rtverify") / "-DRT_VERIFY", "-DEEQUAL_NEGZERO" args ( GetOpt "rtverify") / "-DRT_VERIFY", "-DEEQUAL_NEGZERO"
args (GetOpt"heapverify") / "-DHEAP_VERIFY" args (GetOpt"heapverify") / "-DHEAP_VERIFY"
args ( exportSymbols) / "-DCBQN_EXPORT" args ( exportSymbols) / "-DCBQN_EXPORT"
@ -505,7 +509,10 @@ AddRule ← { 𝕊 cache‿cacheKey‿dst‿GetCMD‿disp‿deps:
res res
} }
clangd {¬po.clangd? {_add{𝕨𝔽_𝕣𝕩:@} Files}; AtRoot •Import "clangd.bqn"}
MakeCCInv { 𝕊 GetArgsInitcacheidsrccustomDeps: # src should be CBQN-base-dir-relative, so that cache doesn't store full paths MakeCCInv { 𝕊 GetArgsInitcacheidsrccustomDeps: # src should be CBQN-base-dir-relative, so that cache doesn't store full paths
GetArgs clangd._add src
dst cache.File id".o" dst cache.File id".o"
GetCMD { 𝕊: GetCMD { 𝕊:
Init @ Init @
@ -538,7 +545,7 @@ MakeLinkerInv ← { 𝕊 GetArgs‿cache‿name‿srcs:
# actual CBQN/Singeli/REPLXX definitions # actual CBQN/Singeli/REPLXX definitions
cachedBinlinkerCache { cachedBinlinkerCache {
Shorten {r {𝕩˜¯1-'.'˜𝕩}¨ •file.Name¨ 𝕩 ! ´ r r} Shorten {po.clangd? 𝕩; r {𝕩˜¯1-'.'˜𝕩}¨ •file.Name¨ 𝕩 ! ´ r r}
cbqnSrc {(𝕩)•file.At¨ 1𝕩}¨ cbqnSrc {(𝕩)•file.At¨ 1𝕩}¨
"src/builtins/", "arithd.c", "arithm.c", "cmp.c", "sfns.c", "squeeze.c", "select.c", "slash.c", "group.c", "sort.c", "search.c", "selfsearch.c", "fold.c", "scan.c", "md1.c", "md2.c", "fns.c", "sysfn.c", "internal.c", "inverse.c" "src/builtins/", "arithd.c", "arithm.c", "cmp.c", "sfns.c", "squeeze.c", "select.c", "slash.c", "group.c", "sort.c", "search.c", "selfsearch.c", "fold.c", "scan.c", "md1.c", "md2.c", "fns.c", "sysfn.c", "internal.c", "inverse.c"
"src/core/", "tyarr.c", "harr.c", "fillarr.c", "stuff.c", "derv.c", "mm.c", "heap.c" "src/core/", "tyarr.c", "harr.c", "fillarr.c", "stuff.c", "derv.c", "mm.c", "heap.c"
@ -546,6 +553,7 @@ cachedBin‿linkerCache ← {
"src/jit/", "nvm.c" "src/jit/", "nvm.c"
"src/utils/", "ryu.c", "utf.c", "hash.c", "file.c", "mut.c", "each.c", "bits.c" "src/utils/", "ryu.c", "utf.c", "hash.c", "file.c", "mut.c", "each.c", "bits.c"
cbqnSrc cbqnSrc clangd.Files "src"
singeliMap {po.arch"aarch64"? 𝕩/˜(1¨𝕩)"cmp""bits""equal""dyarith""monarith""squeeze"; 𝕩} singeliMap {po.arch"aarch64"? 𝕩/˜(1¨𝕩)"cmp""bits""equal""dyarith""monarith""squeeze"; 𝕩}
"src/builtins/arithm.c""monarith", "src/builtins/arithm.c""monarith",
"src/core/stuff.c""equal", "src/utils/mut.c""copy", "src/utils/bits.c""bits" "src/core/stuff.c""equal", "src/utils/mut.c""copy", "src/utils/bits.c""bits"
@ -628,6 +636,9 @@ cachedBin‿linkerCache ← {
} }
outPath •wdpath •file.At po.output outPath •wdpath •file.At po.output
{
po.clangd? clangd.Finish@;
# else, regular build
success Run cachedBin success Run cachedBin
{ 𝕊: { 𝕊:
po.emcc? po.emcc?
@ -636,6 +647,6 @@ success ← Run cachedBin
; ;
SH "cp", "-f", AtRoot cachedBin, outPath SH "cp", "-f", AtRoot cachedBin, outPath
} success } success
OnExit@ OnExit@
•Exit ¬success •Exit ¬success
}

95
build/src/clangd.bqn Normal file
View File

@ -0,0 +1,95 @@
AtRoot •args
Esc{
in (@+091013)"'""" # Null, Tab, LF, CR, and quotes
out "0tnr" # Whitespace characters changed to letters
i in𝕩
𝕩 i out((i<out)/) 𝕩 # Replace
(i<in) /"\"¨ 𝕩 # Insert \
}
n@+10
JStr {"""",Esc 𝕩,""""}
JArr {'['']'˜2𝕨¨ 𝕩}
JObj {'{',n,¯2(JStr¨𝕨) {" ",𝕨,": ",𝕩,',',n}¨ 𝕩, n,'}'}
Files {
res
{'d'=•file.Type AtRoot 𝕩? 𝕊¨ 𝕩•file.At¨ •file.List AtRoot 𝕩; res <𝕩} 𝕩
{(<¯2𝕩)".c"".h"}¨/ res
}
ModifyCBQNFlags {
filenames 4¨ ¨ 𝕩
flagK
flagV
WantsFlags {
𝕨 •file.At # ⋄ •Out 𝕨∾" wants flags "∾JArr JStr¨ 𝕩
flagK <𝕨
flagV <𝕩
}
WantsIncludes {
𝕨 WantsFlags ("-include""src"•file.At)¨ 𝕩
}
FilterPrefix {𝕨{𝕨(𝕨)𝕩}¨/ 𝕩}
# main core.h sequence, assuming MM==1
coreIncludes "h.h","core/stuff.h","core/heap.h","opt/mm_buddy.h","core/gstack.h","core/harr.h","core/numarr.h","core/chrarr.h","core/fillarr.h","core/derv.h","core/arrFns.h"
{(¯1𝕩) WantsIncludes ¯1𝕩}¨ 2 coreIncludes
CoreTil {coreIncludes˜coreIncludes<𝕩}
# MM==0 and MM==2
coreTilMM CoreTil "opt/mm_buddy.h"
{𝕩 WantsIncludes coreTilMM}¨ "opt/mm_2buddy.h""opt/mm_malloc.h"
# non-'utils/' headers & optional .c files
{𝕩 WantsIncludes "core.h"}¨
"ns.h", "vm.h", "builtins.h"
"opt/mm_malloc.c", "opt/mm_buddy.c", "opt/mm_2buddy.c", "opt/mm_buddyTemplate.c", "opt/mm_buddyTemplate.h", "opt/gc.c", "opt/gc.h"
"builtins/radix.h"
"jit/nvm.h"
# and all the utils/ onces
{𝕩 WantsIncludes "core.h"}¨ "utils/" FilterPrefix filenames
# and some other things
"core/tyarrTemplate.h" WantsIncludes CoreTil "core/chrarr.h"
"core/tyarrTemplate.c" WantsIncludes "core/tyarr.c"
"builtins/grade.h" WantsIncludes "builtins/sort.c"
"singeli/c/arithdDispatch.c" WantsIncludes "builtins/arithd.c"
"singeli/c/cmp.c" WantsIncludes "builtins/cmp.c"
"utils/hashmapTemplate.h" WantsIncludes "utils/hash.h"
# give the expected environment for configuration-specific files
"opt/mm_2buddy.c" WantsFlags "-DMM=2"
"opt/mm_malloc.c" WantsFlags "-DMM=0"
"utils/valgrind.h" WantsFlags "-DUSE_VALGRIND"
"core/heap.h" WantsFlags "-DHEAP_VERIFY"
{𝕩 WantsFlags "-DSINGELI"}¨ "singeli/c/" FilterPrefix filenames
# template files
"builtins/sortTemplate.h" WantsIncludes "core.h", "utils/talloc.h"
"builtins/sortTemplate.h" WantsFlags "-DSORT_NAME=", "-DSORT_TYPE=B", "-DSORT_CMP=compare"
# deduplicate flag files
gfk flagK
gfv ¨ (flagK) flagV
# resolve flags to actual files
𝕩 {nf 𝕊 f2: n, ff2}¨ (gfk•file.At¨ filenames)gfv <
}
objects
Finish { 𝕊:
objects ModifyCBQNFlags(({"src/"4𝕩}¨ objects)/)
FileObj { nameflags:
"file""directory""arguments" JObj JStr name, JStr AtRoot "", ", " JArr JStr¨ flags
}
res (","n) JArr FileObj¨ objects
resPath AtRoot "compile_commands.json"
resPath •FChars res
•Out "Wrote clangd compile commands to "•file.At resPath
}
_add {objects <𝕩, (𝔽@)<𝕩}

View File

@ -1,5 +1,10 @@
# Overview of the CBQN source # Overview of the CBQN source
## clangd
Run `build/build clangd` to generate a `compile_commands.json` file which clangd will use to resolve the flags CBQN expects. Other `build/build` flags will also be respected, e.g. `build/build replxx singeli native clangd` will result in clangd assuming the `SINGELI` and `USE_REPLXX` macros are defined, and will resolve generated Singeli sources to ones `build/build replxx singeli native` generates (along with everything else the configurations change).
(depending on the LSP in use, you may need to restart the LSP/clangd/editor after a modified `compile_commands.json`)
## Conventions ## Conventions
Functions starting with `m_` create a new object (some NaN-boxed, some heap-allocated). Functions starting with `m_` create a new object (some NaN-boxed, some heap-allocated).

View File

@ -1,91 +0,0 @@
# list all .c & .h files
enableSingeli 1
additionalFlags
allFiles
{'d'=•file.Type𝕩? 𝕊¨ 𝕩•file.At¨ •file.List𝕩; allFiles <𝕩} ""
allFiles {(<¯2𝕩)".c"".h"}¨/
initialFlags
"/usr/bin/clang","-std=gnu11","-Wall","-DCLANGD","-DFFI=2","-DCBQN_EXPORT","-fms-extensions"
"-Wno-microsoft-anon-tag","-Wno-unused-function","-Wno-undefined-internal","-Wno-bitwise-instead-of-logical","-Wno-unknown-warning-option"
additionalFlags enableSingeli/"-DSINGELI","-DSINGELI_X86_64","-DSINGELI_NEON","-march=native"
Esc{
in (@+091013)"'""" # Null, Tab, LF, CR, and quotes
out "0tnr" # Whitespace characters changed to letters
i in𝕩
𝕩 i out((i<out)/) 𝕩 # Replace
(i<in) /"\"¨ 𝕩 # Insert \
}
n@+10
JStr {"""",Esc 𝕩,""""}
JArr {'['']'˜2𝕨¨ 𝕩}
JObj {'{',n,¯2(JStr¨𝕨) {" ",𝕨,": ",𝕩,',',n}¨ 𝕩, n,'}'}
flagK
flagV
WantsFlags {
𝕨 •file.At
# •Out 𝕨∾" wants flags "∾JArr JStr¨ 𝕩
flagK <𝕨
flagV <𝕩
}
WantsIncludes {
𝕨 WantsFlags ("-include"•file.At)¨ 𝕩
}
FilterPrefix {𝕨{𝕨(𝕨)𝕩}¨/ 𝕩}
# main core.h sequence, assuming MM==1
coreIncludes "h.h","core/stuff.h","core/heap.h","opt/mm_buddy.h","core/gstack.h","core/harr.h","core/numarr.h","core/chrarr.h","core/fillarr.h","core/derv.h","core/arrFns.h"
{(¯1𝕩) WantsIncludes ¯1𝕩}¨ 2 coreIncludes
CoreTil {coreIncludes˜coreIncludes<𝕩}
# MM==0 and MM==2
coreTilMM CoreTil "opt/mm_buddy.h"
{𝕩 WantsIncludes coreTilMM}¨ "opt/mm_2buddy.h""opt/mm_malloc.h"
# non-'utils/' headers & optional .c files
{𝕩 WantsIncludes "core.h"}¨
"ns.h", "vm.h", "builtins.h"
"opt/mm_malloc.c", "opt/mm_buddy.c", "opt/mm_2buddy.c", "opt/mm_buddyTemplate.c", "opt/mm_buddyTemplate.h", "opt/gc.c", "opt/gc.h"
"builtins/radix.h"
"jit/nvm.h"
# and all the utils/ onces
{𝕩 WantsIncludes "core.h"}¨ "utils/" FilterPrefix allFiles
# and some other things
"core/tyarrTemplate.h" WantsIncludes CoreTil "core/chrarr.h"
"core/tyarrTemplate.c" WantsIncludes "core/tyarr.c"
"builtins/grade.h" WantsIncludes "builtins/sort.c"
"singeli/c/arithdDispatch.c" WantsIncludes "builtins/arithd.c"
"singeli/c/cmp.c" WantsIncludes "builtins/cmp.c"
"utils/hashmapTemplate.h" WantsIncludes "utils/hash.h"
# give the expected environment for configuration-specific files
"opt/mm_2buddy.c" WantsFlags "-DMM=2"
"opt/mm_malloc.c" WantsFlags "-DMM=0"
"utils/valgrind.h" WantsFlags "-DUSE_VALGRIND"
"core/heap.h" WantsFlags "-DHEAP_VERIFY"
{𝕩 WantsFlags "-DSINGELI"}¨ "singeli/c/" FilterPrefix allFiles
# template files
"builtins/sortTemplate.h" WantsIncludes "core.h", "utils/talloc.h"
"builtins/sortTemplate.h" WantsFlags "-DSORT_NAME=", "-DSORT_TYPE=B", "-DSORT_CMP=compare"
# deduplicate flag files
gfk flagK
gfv ¨ (flagK) flagV
# resolve flags to actual files
allFlags (gfk•file.At¨ allFiles)gfv <
FileObj {
"file""directory""arguments" JObj JStr 𝕨, JStr •path, ", " JArr JStr¨ initialFlags𝕩
}
resPath "../compile_commands.json", •wdpath•file.At •args
resPath •FChars (","n) JArr allFiles FileObj¨ allFlags
•Out "Wrote clangd compile commands to "•file.At resPath