kilanote's People
kilanote's Issues
Xcode 使用Prelink Single Object
Tips
- 最好PRELINK_FLAGS配合-flistist /tmp/xxx.txt作为输入(支持静态库和.o)来避免参数过长
- PRELINK_FLAGS 注意加上-ObjChe和-all_load否则无法把静态库合并到一起
brew usage
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
brew install --cask rapidapi
brew install --cask fork
brew install --cask visual-studio-code
brew install --cask beyond-compare@beta
brew install --cask hopper-disassembler
brew install --cask medis
brew install --cask zed
brew install --cask charles
brew install --cask xcodes
brew install --cask feishu
brew install --cask google-chrome
brew install --cask sublime-text
brew install --cask intellij-idea-ce
brew install bazelisk
brew install aria2
brew install rust
brew install git
brew install git-lfs
git lfs install
xcodes install --latest
Charles catch response at terminal
export http_proxy="http://127.0.0.1:1086"
export https_proxy="http://127.0.0.1:1086"
export ALL_PROXY="socks5://127.0.0.1:1080"
export no_proxy="127.0.0.1,localhost"
for curl
echo insecure >> ~/.curlrc
for ruby
cp /path/to/my/root_certificate.pem /usr/local/etc/openssl/certs
/usr/local/opt/openssl/bin/c_rehash
for ruby Net::HTTP
url = URI(url)
https = Net::HTTP.new(url.host, url.port);
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(url)
response = https.request(request)
return response.read_body()
for ssh
host = github.com
ProxyCommand /usr/bin/nc -X 5 -x 127.0.0.1:1080 %h %p
#for git http
git config --global http.proxy http://127.0.0.1:1080
git config --global https.proxy http://127.0.0.1:1080
mongodb统计成功率
db.collection.aggregate([
{
$group: {
_id: null,
sum: {
$sum: 1
},
success: {
$sum: {
$cond: [
{
$eq: [
"$success",
1
]
},
1,
0
]
}
},
failed: {
$sum: {
$cond: [
{
$eq: [
"$success",
0
]
},
1,
0
]
}
},
}
},
{
$project: {
"percent": {
$multiply: [
{
$divide: [
"$success",
"$sum"
]
},
100
]
}
}
},
])
mac远程调试
目标机
/Library/Developer/CommandLineTools/Library/PrivateFrameworks/LLDB.framework/Versions/A/Resources/debugserver 0.0.0.0:8081 [--attach pid]
客户端
lldb
platform select remote-macosx
process connect connect://<ip>:8081
xcode hook
CC=/xxx/clang
SWIFT_EXEC=/xxx/swiftc
LIBTOOL=/xxx/libtool
LD=/xxx/ld
xcode build fat binary
Catalina app已损坏解决方法
自己修改二进制后发现在Catalina上无法运行提示已损坏
- 信任任何来源
sudo spctl --master-disable
- GateKeeper添加白名单
sudo xattr -d com.apple.quarantine /Applications/xxx.app
- 使用自签名证书给二进制签名
KeyChain->证书助理->创建证书填写证书名,选择自签名根证书,选择代码签名
创建好后会自动添加到KeyChain中,可以到KeyChain中选择始终信任
然后对二进制进行签名
codesign -f -s 证书名 /Applications/xxx.app
或者
codesign -f -s - --deep /Applications/xxx.app
对应的路径可能需要在第二步中加入白名单 - 终极方案 关闭SIP
gradle和maven加速
gradle加速
gradle-wrapper.properties中distributionUrl换成镜像地址
distributionUrl=https://downloads.gradle-dn.com/distributions/gradle-6.1.1-all.zip
可以下载到本地通过file://访问
distributionUrl=file:///Volumes/Mojave2/gradle-6.1.1-all.zip
组件加速
vi ~/.gradle/init.gradle
填入一下内容
gradle.projectsLoaded {
rootProject.allprojects {
buildscript {
repositories {
def JCENTER_URL = 'https://maven.aliyun.com/repository/jcenter'
def GOOGLE_URL = 'https://maven.aliyun.com/repository/google'
def NEXUS_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
all { ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $JCENTER_URL."
println("buildscript ${repo.url} replaced by $JCENTER_URL.")
remove repo
}
else if (url.startsWith('https://dl.google.com/dl/android/maven2/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $GOOGLE_URL."
println("buildscript ${repo.url} replaced by $GOOGLE_URL.")
remove repo
}
else if (url.startsWith('https://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
println("buildscript ${repo.url} replaced by $REPOSITORY_URL.")
remove repo
}
}
}
jcenter {
url JCENTER_URL
}
google {
url GOOGLE_URL
}
maven {
url NEXUS_URL
}
}
}
repositories {
def JCENTER_URL = 'https://maven.aliyun.com/repository/jcenter'
def GOOGLE_URL = 'https://maven.aliyun.com/repository/google'
def NEXUS_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
all { ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $JCENTER_URL."
println("buildscript ${repo.url} replaced by $JCENTER_URL.")
remove repo
}
else if (url.startsWith('https://dl.google.com/dl/android/maven2/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $GOOGLE_URL."
println("buildscript ${repo.url} replaced by $GOOGLE_URL.")
remove repo
}
else if (url.startsWith('https://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
println("buildscript ${repo.url} replaced by $REPOSITORY_URL.")
remove repo
}
}
}
jcenter {
url JCENTER_URL
}
google {
url GOOGLE_URL
}
maven {
url NEXUS_URL
}
}
}
}
AMD hackintosh with torch
- 手动转换需要给torch打补丁
AMD Hackintosh torch 依赖了Intel MKL。可以用amdfriend对动态库或二进制打补丁。 - 无法正常图片的话需要手动转换模型并设置CoreML模型精度为FP32。
coreml_model = ct.convert(
torchscript_module,
convert_to="mlprogram",
minimum_deployment_target=ct.target.macOS13,
inputs=_get_coreml_inputs(sample_inputs, args),
outputs=[ct.TensorType(name=name) for name in output_names],
compute_units=ct.ComputeUnit[args.compute_unit],
compute_precision=ct.precision.FLOAT32,
# skip_model_load=True,
)
ida64.app 无法打开
在终端执行下面的代码
sudo xattr -rd com.apple.quarantine /Applications/IDA\ Pro\ 7.0/ida64.app
imp_implementationWithBlock
LLDB debug cheat sheet
po [obj fp_methodDescription]
po [obj fp_ivarDescription]
po @import Foundation
po [NSString stringWithFormat:@"%@", $arg1]
po (char *)$arg1
po [[NSString alloc] initWithData:$arg3 encoding:8]
JSONObjectWithData:options:error:
dataWithJSONObject:options:error:
dispatch thunk of CryptoKit.HashFunction.update(bufferPointer: Swift.UnsafeRawBufferPointer) -> ()
settings set target.language swift
po import Foundation
break set -r using -s Foundation
break set -a 0x00007ff81cc1dfa0
https://github.com/Kila2/KilaNote/issues/27#issue-1328229302
lldb学习资料
debug xcode
create SSR cert name is kila
codesign -s kila -f /Applications/Xcode.app/Contents/MacOS/Xcode
use lldb debug it
bazel cheat sheet
bazel query OutputGroupInfo
# defs.bzl:
def _output_group_query_aspect_impl(target, ctx):
for og in target.output_groups:
print("output group " + str(og) + ": " + str(getattr(target.output_groups, og)))
return []
output_group_query_aspect = aspect(
implementation = _output_group_query_aspect_impl,
)
bazel build --nobuild Foo --aspects=//:defs.bzl%output_group_query_aspect
REF:https://stackoverflow.com/questions/61252620/how-to-list-the-output-groups-of-a-bazel-rule
获取clang错误定义json
/Users/`whami`/Desktop/Workspace/llvm-project/build/Debug/bin/clang-tblgen -dump-json -I /Users/`whami`/Desktop/Workspace/llvm-project/clang/include -I /Users/`whami`/Desktop/Workspace/llvm-project/clang/docs -I /Users/`whami`/Desktop/Workspace/llvm-project/llvm/include -I/Users/`whami`/Desktop/Workspace/llvm-project/clang/docs/../include/clang/Basic /Users/`whami`/Desktop/Workspace/llvm-project/clang/docs/../include/clang/Basic/Diagnostic.td --write-if-changed -o /Users/`whami`/Desktop/Workspace/llvm-project/build/tools/clang/docs/DiagnosticsReference.rst
hackintosh disable storemi driver
/*
* Intel ACPI Component Architecture
* AML/ASL+ Disassembler version 20200925 (64-bit version)
* Copyright (c) 2000 - 2020 Intel Corporation
*
* Disassembling to symbolic ASL+ operators
*
* Disassembly of iASLTuMtMQ.aml, Sat Aug 20 10:30:30 2022
*
* Original Table Header:
* Signature "SSDT"
* Length 0x000000F1 (241)
* Revision 0x02
* Checksum 0x84
* OEM ID "Kila"
* OEM Table ID "BYDFix"
* OEM Revision 0x00000000 (0)
* Compiler ID "INTL"
* Compiler Version 0x20200925 (538970405)
*/
DefinitionBlock ("", "SSDT", 2, "Kila", "BYDFix", 0x00000000)
{
External (_SB_.PCI0.BXBR.BYUP, DeviceObj) // 声明外部设备
Scope (\_SB.PCI0.BXBR.BYUP)
{
Device (BYD9) //添加设备BYD9,我的StoreMI设备挂在BYD9.BYS9下。但是IORegistryExplorer中识别成了pci-bridgexxx,通过自定义Device让IORegistryExplorer可以识别到BYD9
{
Name (_ADR, 0x00090000) // _ADR: Address 参考其他BYD[1-8]的地址这里填写为0x00090000
Device (BYS9) //添加设备BYS9
{
Name (_ADR, Zero) // _ADR: Address 参考其他BYS的地址这里填写为Zero
}
Method (BYS9._DSM, 4, NotSerialized) // _DSM: Device-Specific Method 定义BYS9有关的方法。以下来自网络可以起到屏蔽设备的作用。
{
If ((!Arg2 || !_OSI ("Darwin")))
{
Return (Buffer (One)
{
0x03 // .
})
}
Return (Package (0x06) // 06表示接下来有6个参数。屏蔽GPU时根据需求增加。
{
"name",
Buffer (0x09)
{
"#display"
},
"IOName",
"#display",
"class-code",
Buffer (0x04)
{
0xFF, 0xFF, 0xFF, 0xFF // ....
}
})
}
}
Device (BYDA) //添加设备BYDA即BYD10 顺手补全一下,可以省略
{
Name (_ADR, 0x000A0000) // _ADR: Address
Device (BYSA) //添加设备BYSA即BYS10
{
Name (_ADR, Zero) // _ADR: Address
}
}
}
}
ARM 指令集
ROR(Rotate Right)
语法:
ROR{S}{cond} Rd, Rm, Rs
ROR{S}{cond} Rd, Rm, #sh
参数:
- S
- 可选后缀,在使用时可根据操作的结果更新条件标志位NCZV。
- Rd
- 目标寄存器
- Rm
- 存放待右移的操作数的寄存器
- Rs
- 存放偏移量的寄存器,取最低有效位(0x01~0x1F)
- sh
- 偏移常量,1-31
将操作数循环右移,记将操作数中的位向右移动,右边移出的位依次作为补位加入到左边的空位。
ASR(Arithmetic Shift Right)
语法:
ASR{S}{cond} Rd, Rm, Rs
ASR{S}{cond} Rd, Rm, #sh
参数:
- S
- 可选后缀,在使用时可根据操作的结果更新条件标志位NCZV。
- Rd
- 目标寄存器
- Rm
- 存放待右移的操作数的寄存器
- Rs
- 存放偏移量的寄存器,取最低有效位(0x01~0x20)
- sh
- 偏移常量,1-32
对寄存器的中的值进右移,空出来的位使用第31位进行填充。例如正数31位是0,负数31位是1。
此操作相当于操作数除以2的n次幂,同时保留正/负符号。
如将r1右移动3位存放到r0中
MOV r0, r1, ASR #3
Z123456789ABCDEFGHIJKLMNOPQRSTUV
ZZZZ123456789ABCDEFGHIJKLMNOPQRS
LSL(Logical Shift Left)
语法:
LSL{S}{cond} Rd, Rm, Rs
LSL{S}{cond} Rd, Rm, #sh
参数:
- S
- 可选后缀,在使用时可根据操作的结果更新条件标志位NCZV。
- Rd
- 目标寄存器
- Rm
- 存放待左移的操作数的寄存器
- Rs
- 存放偏移量的寄存器,取最低有效位(0x00~0x1F)
- sh
- 偏移常量,0-31
对寄存器的中的值进左移,对空位进行补0。相当于对操作数乘以2的n次幂。
LSR(Logical Shift Right)
语法:
LSR{S}{cond} Rd, Rm, Rs
LSR{S}{cond} Rd, Rm, #sh
参数:
- S
- 可选后缀,在使用时可根据操作的结果更新条件标志位NCZV。
- Rd
- 目标寄存器
- Rm
- 存放待右移的操作数的寄存器
- Rs
- 存放偏移量的寄存器,取最低有效位(0x01~0x20)
- sh
- 偏移常量,1-32
对寄存器的中的值进右移,对空位进行补0。相当于对操作数除以2的n次幂。
BFI(Bit Field Insert)
语法:
BFI{cond} Rd, Rn, #lsb, #width
参数:
- cond
- 可选参数,条件码
- Rd
- 目标寄存器
- Rn
- 源寄存器
- lsb
- 要复制的最低有效位
- width
- 要复制的位数。 width 不能为 0,并且 (width+lsb) 必须小于或等于 32。
将一个寄存器中的相邻位插入到另一个寄存器中。 Rd 中从 lsb 开始的width位被 Rn 中从位 [0] 开始的width位替换。 Rd 中的其他位不变。
备注:
ASR算术右移动需要理解负数在计算机中的正码、反码、补码(取反+1)。
Rd中R得含义,R可以是W或X,其中W用于32位,X用于64位。
Rn或Rm中n和m的含义,无特指,尽在存在多个寄存器参数的指令中用于区分不同的寄存器。
图片引用自:AZERIA
compile watchman cppclient with homebrew
- download source code watchman
- download source code folly
- compile folly
edit ./build/bootstrap-osx-homebrew.sh
./configure --disable-silent-rules --disable-dependency-tracking --prefix=/Users/xxx/Downloads/folly-2017.10.16.00/folly/install
cd folly
./build/bootstrap-osx-homebrew.sh
- brew sh --env
- compile
export PKG_CONFIG_PATH="/Users/xxx/Downloads/folly-2017.10.16.00/folly/install/lib/pkgconfig:$PKG_CONFIG_PATH"
./autogen.sh
./configure --prefix=/usr/local/Cellar/watchman/4.9.0_4 --with-pcre --without-python --enable-statedir=/usr/local/var/run/watchman --enable-cppclient --with-folly=/Users/xxx/Downloads/folly-2017.10.16.00/folly/install
make
syncthing usage
enable internet access
syncthing cli config gui raw-address set 0.0.0.0:8384
setup gui user and password and without default-folder
syncthing generate --gui-user=<user_name> --gui-password=<password> --no-default-folder
get device-id
syncthing --device-id
add device
syncthing cli config devices add --device-id <device-id>
add folder
syncthing cli config folders add --label <label> --path <path> --id <id>
delete folder
syncthing cli config folders <id> delete
add device for folder
syncthing cli config folders <folder-id> devices add --device-id <device-id>
delete device for folder
syncthing cli config folders <folder-id> devices <device-id> delete
reduce file watcher delay
syncthing cli config folders <folder-id> fswatcher-delays set 1
macOS compile switch retroarch need install dependency
Reference https://docs.libretro.com/development/retroarch/compilation/switch-libnx
sudo dkp-pacman -Sy devkit-env devkitA64 libnx switch-tools switch-mesa switch-zlib switch-bzip2 switch-freetype switch-libpng
still need to install these dependency
sudo dkp-pacman -S switch-mesa switch-libopus switch-libvpx switch-liblzma switch-ffmpeg
virtualbox ubuntu配置双向通信和代理
关闭防火墙 简单点可以直接关闭虚拟机防火墙。也可以通过iptables配置22端口
sudo ufw disbale
开启防火墙
sudo ufw enable
开启22端口
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
仅对某ip开启22端口
sudo iptables -A INPUT -p tcp -s --dport 22 -j ACCEPT
virtualbox 配置双网卡
如果host-only无法添加。需要先创建一个到偏好设置-网络中添加一个网络。
配置好网卡后到虚拟机中配置ip 注意名字要匹配
$ls /sys/class/net
docker0 enp0s3 enp0s8 lo
$sudo vi /etc/netplan/00-installer-config.yaml
注意如果是安装好系统后添加的网卡。配置文件中可能没有第二块网卡,需要自己填写。
# This is the network config written by 'subiquity'
network:
ethernets:
enp0s3:
dhcp4: false
addresses:
- 192.168.56.12/24
enp0s8:
dhcp4: true
version: 2
让配置生效
sudo netplan generate
sudo netplan apply
这时应该可以在主机通过ssh登陆虚拟机了。
设置host的http代理可能无法访问
可以尝试更改配置文件中的127.0.0.1改为局域网ip。然后重启服务。之后虚拟机可以通过下面的代码访问代理了
export http_proxy=http://<ip:port>;export https_proxy=https://<ip:port>;
共享文件夹需要安装软件
sudo apt-get install virtualbox-guest-utils
开机自启动
注意sudo vi /etc/vbox/autostart.cfg
时替换成自己的用户名
https://gist.github.com/str8edgedave/b0b96e12396aaa7d383456778079ee7b
Shell代码片
# 批量压缩
ls|awk '{ cmd="7z a -t7z \""$0".7z\" \""$0"\" -mx=7"; system(cmd) }'
# 导出当前目录下所有的可执行文件中的字符串
find . -perm +111 -type f -exec echo {} \; -exec strings {} \; > ~/a
dlsym
import Darwin
let handle = dlopen("/usr/lib/libc.dylib", RTLD_NOW)
let sym = dlsym(handle, "random")
typealias randomFunc = @convention(c) () -> CInt
let f = unsafeBitCast(sym, to: randomFunc.self)
let result = f()
dlclose(handle)
print(result)
dlsym(dlopen(nil, RTLD_NOW), "$s28HelloReverseEnginerringSwift5BStruV1aACSS_tcfC")
vscode debug darwin kernel
prepare
- use gibMacOS download 10.15.6 Beta (19G60d) image
- install the image on host and vmware ref
- download KDK from https://developer.apple.com/download/more/ and install it
- download open source at https://opensource.apple.com/release/macos-10156.html and unzip it to
/AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources
# eg.
/AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/xnu/xnu-6153.141.1
ps: other config ref
VSCode config
{
"type": "lldb",
"request": "custom",
"name": "Custom launch",
"targetCreateCommands": [
"settings set target.load-script-from-symbol-file true",
"target create /Library/Developer/KDKs/KDK_10.15.6_19G60d.kdk/System/Library/Kernels/kernel.development"
],
"processCreateCommands": [
"kdp-remote 172.16.156.128",
]
}
ps2: another kernel debug tool https://blog.quarkslab.com/lldbagility-practical-macos-kernel-debugging.html
编译sk-stress-test
- 修改package.swift
- 添加代码setenv("SWIFTCI_USE_LOCAL_DEPS", "1", 1) 修改成本地依赖
- 设置sourcekitSearchPath = "/path/to/swift-source/build/Xcode-DebugAssert/swift-macosx-x86_64/Debug/lib"
firewall-cmd
firewall-cmd --zone=public --list-ports
firewall-cmd --list-services
firewall-cmd --zone=public --add-port=12535/tcp --permanent
ruby子进程
centos8 enable bbr
How to enable BBR on CentOS 8
BBR stands for Bottleneck Bandwidth and RTT is a congestion control system. You can enable TCP BBR on your Linux desktop to improve overall web surfing experience. By default, Linux uses the Reno and CUBIC congestion control algorithm.
Requirements:
BBR requires Linux kernel version 4.9 or above. Since CentOS 8 comes with the 4.18.0 kernel, we can enable BBR right away.
Run the following command to check available congestion control algorithms,
sysctl net.ipv4.tcp_available_congestion_control
Output:
root@vps:~# sysctl net.ipv4.tcp_available_congestion_control
net.ipv4.tcp_available_congestion_control = reno cubic
Run the below command to check the current congestion control algorithm used in your system,
sysctl net.ipv4.tcp_congestion_control
Output:
[root@vps ~]# sysctl net.ipv4.tcp_available_congestion_control
net.ipv4.tcp_available_congestion_control = reno cubic
Enabling TCP BBR in CentOS
Open the following configuration file vi /etc/sysctl.conf to enable enable TCP BBR.
vi /etc/sysctl.conf
At the end of the config file, add the following lines.
net.core.default_qdisc=fq
net.ipv4.tcp_congestion_control=bbr
Save the file, and refresh your configuration by using this command,
sysctl -p
Output:
[root@vps ~]# sysctl -p
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
Now, Verify if BBR is enabled in your system,
sysctl net.ipv4.tcp_congestion_control
Output:
[root@vps ~]# sysctl net.ipv4.tcp_congestion_control
net.ipv4.tcp_congestion_control = bbr
Done!
ref
idea configure chrome debug typescript
编译llvm方法和编译swift方法
llvm
git clone [email protected]:apple/llvm-project-v2.git --depth=1 --branch=apple/stable/20190619
cd llvm-project-v2
cd llvm-project
mkdir build
cd build
cmake -DLLVM_ENABLE_PROJECTS=clang -G "Unix Makefiles" ../llvm
#或者
#cmake -DLLVM_ENABLE_PROJECTS=clang -G Xcode ../llvm
make -j 8
#静态库
cmake -DLLVM_ENABLE_PROJECTS=clang -DLIBCLANG_BUILD_STATIC=ON -DLLVM_ENABLE_PIC=OFF -G Xcode ../llvm
其他编译参数
-DLLVM_TARGETS_TO_BUILD="X86"
-DLLVM_TARGET_ARCH=X86
-DCMAKE_BUILD_TYPE="Release"
-DLLVM_BUILD_EXAMPLES=1
-DCLANG_BUILD_EXAMPLES=1
-DLLVM_ENABLE_LTO=ON
-DCMAKE_OSX_DEPLOYMENT_TARGET="11.0"
-DCMAKE_OSX_SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
c-index-test 瘦身
step1 修改cmake将IndexStore设置成静态库
step2 生成静态库工程
cmake -DLLVM_ENABLE_PROJECTS=clang -DLIBCLANG_BUILD_STATIC=ON -DLLVM_ENABLE_PIC=OFF -DLLVM_ENABLE_LTO=ON -G Xcode
step3 给入口Target(c-index-test)增加C_Flags和CXX_Flags -fvisibility=hidden 配置好__attribute__((visibility("default")))和__attribute__((visibility("hidden")))(-fvisibility=hidden 保证默认hidden),其余Target由GCC_SYMBOLS_PRIVATE_EXTERN来配置
step4 编译c-index-test
xcodebuild -project LLVM.xcodeproj archive -target c-index-test -configuration Release GCC_SYMBOLS_PRIVATE_EXTERN=YES
备注
- GCC_SYMBOLS_PRIVATE_EXTERN=YES 增加-fvisibility=hidden 调整可见性默认不导出符号,配合LTO和-dead_strip进一步删除无用代码
swift
先安装ninja和cmake可以使用homebrew
brew install cmake ninja
mkdir swift-source
cd swift-source
git clone https://github.com/apple/swift.git
checkout到5.1的分支
./swift/utils/update-checkout --clone --scheme=swift-5.1-branch
checkout到5.3的分支
./swift/utils/update-checkout --clone --scheme=release/5.3
可能需要使用xcode11来编译
切换工具链
sudo xcode-select -s /Applications/Xcode-beta.app
清理缓存重新编译
./swift/utils/build-script --release-debuginfo --clean
使用xcode
./swift/utils/build-script --debug --clean --xcode
compile swift5.7 at wsl2 ubuntu2204
require homebrew for linux
mkdir swift-project
cd swift-project
git clone [email protected]:apple/swift.git swift
cd swift
./utils/update-checkout --skip-history --scheme release/5.7 --clone
brew bundle
sccache --start-server
sudo apt install ncurses-dev libsqlite3-dev
sudo apt-get install \
binutils \
git \
gnupg2 \
libc6-dev \
libcurl4 \
libedit2 \
libgcc-9-dev \
libpython2.7 \
libsqlite3-0 \
libstdc++-9-dev \
libxml2 \
libz3-dev \
pkg-config \
tzdata \
uuid-dev \
zlib1g-dev
utils/build-script --skip-build-benchmarks \
--skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "$(uname -m)" \
--sccache --release-debuginfo --swift-disable-dead-stripping
Xcode cheat sheet
Command Line
# enable internal menu
defaults write com.apple.dt.Xcode ShowDVTDebugMenu -bool YES (deprecated)
touch /Applications/Xcode.app/Contents/Developer/AppleInternal/Library/Xcode/AppleInternal.plist (deprecated)
alias xcbuild=$(xcode-select -p)/../SharedFrameworks/XCBuild.framework/Versions/A/Support/xcbuild
# THIS DOESNT WORK YET: xcbuild openIDEConsole # … then switch to Xcode ➡️
xcbuild showSpecs
xcbuild build <foo.pif> [—target <target>]
# Some minimal additional logging (this is safe to leave on).
defaults write com.apple.dt.XCBuild EnableDebugActivityLogs -bool YES
# Enable build debugging mode (safe to leave on, but slows down the build system & litters DerivedData/<project>/Build/Intermediates.noindex), generally should only be enabled when trying to capture a trace for incremental build debugging purposes.
defaults write com.apple.dt.XCBuild EnableBuildDebugging -bool YES
# You can also use:
env EnableBuildDebugging=YES xcodebuild -UseNewBuildSystem=1 ...
# Use `xcbuild` to dump a headermap.
xcbuild headermap --dump <path>
# Change XCBuildService
open --env XCBBUILDSERVICE_PATH="$(XCODE_ROOT)/Contents/SharedFrameworks/XCBuild.framework/Versions/A/PlugIns/XCBBuildService.bundle/Contents/MacOS/XCBBuildService" $(SOURCE_ROOT)/DevKit.xcworkspace
# Enable Index Log
defaults write com.apple.dt.XCode IDEIndexDisable 0
# Disable Index Log
defaults write com.apple.dt.XCode IDEIndexDisable 1
# Enable Index Log
defaults write com.apple.dt.Xcode IDEIndexShowLog -bool YES
# Disable Index Log
defaults write com.apple.dt.Xcode IDEIndexShowLog -bool NO
IDE Console
open with Internal > XCBuild Console
writePIF <workspace name> <path>
# … you can use this with the `xcbuild build …` command (above) to build via the service directly
showStatistics
clearAllCaches
setConfig EnableBuildDebugging true
# … then save DerivedData & build log; same as above dwrite, but not persisted
Xcode Versions
https://xcodereleases.com/data.json
Xcode defaults
Backup Xcode defaults
defaults read com.apple.dt.Xcode > ~/Desktop/XcodeDefaults.plist
Restore Xcode vanilla defaults
If you delete/move the current plist, Xcode will write a fresh one next time you run it.
killall Xcode
mv ~/Library/Preferences/com.apple.dt.Xcode.plist ~/Desktop/XcodeDefaults.plist
open -b com.apple.dt.Xcode
New Swift build system mode
With Xcode 13.3 the build system and Swift compiler have a new mode that better utilizes available cores, resulting in faster builds for Swift projects. The mode is opt-in, and you can enable globally with the following user default:
defaults write com.apple.dt.XCBuild EnableSwiftBuildSystemIntegration 1
Source @BenchR
Enable project build time
defaults write com.apple.dt.Xcode ShowBuildOperationDuration -bool YES
Enable parallel builds for Swift
defaults write com.apple.dt.Xcode BuildSystemScheduleInherentlyParallelCommandsExclusively -bool YES
Disable parallel builds for Swift
Xcode 9.3 now runs more Swift build tasks in parallel with other commands. This may improve build times for Swift projects, but may also increase memory use during the build. This feature can be disabled from Terminal by setting a user default with
defaults write com.apple.dt.Xcode BuildSystemScheduleInherentlyParallelCommandsSerially -bool YES
Enable multi-cursor editing
defaults write com.apple.dt.Xcode PegasusMultipleCursorsEnabled -bool YES
Set maximum number of concurrent compile tasks
defaults write com.apple.dt.Xcode IDEBuildOperationMaxNumberOfConcurrentCompileTasks `sysctl -n hw.ncpu`
Where sysctl -n hw.ncpu
gives you the number of CPU threads.
Set maximum number of parallel build subtasks
defaults write com.apple.dt.Xcode PBXNumberOfParallelBuildSubtasks `sysctl -n hw.ncpu`
Where sysctl -n hw.ncpu
gives you the number of CPU threads.
Enable/Disable indexing
Keep in mind that disabling indexing will disable refactor
code action so you probably won't be able to generate protocol conformances or memberwise initializers
Enable indexing
defaults delete com.apple.dt.Xcode IDEIndexDisable
defaults write com.apple.dt.Xcode IDEIndexEnable -bool YES
Disable indexing
defaults delete com.apple.dt.Xcode IDEIndexEnable
defaults write com.apple.dt.Xcode IDEIndexDisable -bool YES
Show Indexing numeric progress
defaults write com.apple.dt.Xcode IDEIndexerActivityShowNumericProgress -bool YES
Show Indexing logging
This will show you why a particular file is having trouble being compiled for indexing.
defaults write com.apple.dt.Xcode IDEIndexShowLog -bool YES
Show prebuild step logs
defaults write com.apple.dt.Xcode IDEShowPrebuildLogs -bool YES
Set SourceKit log level
If set to SourceKit will write a log to /tmp with all the details of what it is doing while indexing.
A lot of people find they have header hygiene problems or module problems that happen to work while building in certain configurations but aren't actually correct, resulting in missing modules or broken headers from the indexer's point of view.
May not work anymore.
defaults write com.apple.dt.Xcode IDESourceKitServiceLogLevel -int 3
Also you can do this temporarily by pre-pending this environment variable when starting Xcode:
SOURCEKIT_LOGGING=3 /Applications/Xcode.app/Contents/MacOS/Xcode
Source AppCode under the hood - Aydar Mukhametzyanov - NSSpain 2021
Disable Main Thread Checker
Deactivates the Main Thread Checker. Found in Xcode 12 release notes
defaults write com.apple.dt.Xcode DVTDisableMainThreadChecker 1
Enable internal Xcode (debug) menu
defaults write com.apple.dt.Xcode ShowDVTDebugMenu -bool YES
Disable automatic reopening of last project
Prevents Xcode from automatically restoring the last open project.
This enables running multiple Xcode versions for different projects.
defaults write com.apple.dt.Xcode ApplePersistenceIgnoreState -bool YES
Some minimal additional logging
defaults write com.apple.dt.XCBuild EnableDebugActivityLogs -bool YES
Enable build debugging mode
This slows down the build system & litters DerivedData//Build/Intermediates.noindex), generally should only be enabled when trying to capture a trace for incremental build debugging purposes.
defaults write com.apple.dt.XCBuild EnableBuildDebugging -bool YES
Make Assistant aware of more companion files
Make Xcode's Assistant aware of your ViewModels, Views, etc.
Found by @peterfriese
defaults write com.apple.dt.Xcode IDEAdditionalCounterpartSuffixes -array-add "ViewModel" "View" "Screen"
Disable move files on restructure
Do not move files when you restructure things in an Xcode project. Found by @steinpete
defaults write com.apple.dt.Xcode IDEDisableStructureEditingCoordinator -bool YES
Disable state restoration
Stop Xcode from reopening files on launch. Found by @SmileyKeith
defaults write com.apple.dt.Xcode IDEDisableStateRestoration -bool YES
Homebrew prefix path
Homebrew's default prefix/install path can point to different locations depending on your system.
Xcode by default only looks for /opt/brew
and /usr/local
.
You can adjust that location by writing the following default.
To get your Homebrew prefix call brew --prefix
.
Source @NeoNacho
defaults write com.apple.dt.Xcode IDEHomebrewPrefixPath -string <BREW_PREFIX>
Swift package remote source path
Specify the directory to which remote source packages are fetch or expected to be found.
xcodebuild
has the same option as clonedSourcePackagesDirPath
.
Source @bguidolim
defaults write com.apple.dt.Xcode IDEClonedSourcePackagesDirPathOverride -string <PATH>
📱 Simulator
Enable Simulator fullscreen mode
defaults write com.apple.iphonesimulator AllowFullscreenMode -bool YES
🏗️ XCBuild
Enable Build Debugging
Creates an XCBuildData folder in ~/Library/Developer/Xcode/DerivedData/<your target>/Build/Intermediates.noindex/
which contains debugging info for xcodebuild.
defaults write com.apple.dt.XCBuild -bool YES
🗑️ Xcode Cleanups
Remove all Xcode DerivedData
... provided Xcode is set to default folder locations.
This is a quick win and helps to get back gigabytes of storage space.
Do this regularly.
rm -rdf ~/Library/Developer/Xcode/DerivedData/*
Remove all Xcode DeveloperTools cache files
... provided Xcode is set to default folder locations.
CACHE=$(getconf DARWIN_USER_CACHE_DIR)
rm -rdf ${CACHE}com.apple.DeveloperTools
rm -rdf ${CACHE}org.llvm.clang.$(whoami)/ModuleCache
rm -rdf ${CACHE}org.llvm.clang/ModuleCache
rm -rdf ~/Library/Caches/com.apple.dt.*/*
Remove all Xcode / Swift temporary files.
TMP=$(getconf DARWIN_USER_TEMP_DIR)
rm -rdf ${TMP}*.swift
rm -rdf ${TMP}ibtool*
rm -rdf ${TMP}*IBTOOLD*
rm -rdf ${TMP}supplementaryOutputs-*
rm -rdf ${TMP}xcrun_db
rm -rdf ${TMP}sources-*
rm -rdf ${TMP}com.apple.dt.*
rm -rdf ${TMP}com.apple.test.*
🧰 Tools
- DevCleaner If you want to reclaim tens of gigabytes of your storage used for various Xcode caches - this tool is for you!
- Kintsugi A tool to automatically resolve Git conflicts that occur in Xcode project files
- BuildTimeAnalyzer A build time analyzer for Xcode
- XCLogParser A tool to parse Xcode and xcodebuild logs stored in the xcactivitylog format
- XCMetrics A tool to collect Xcode build metrics and improve developer productivity
Useful Xcode Knowledge
Xcconfig
Xcode uses files that end in .xcconfig
for storing configuration about various compiler settings.
While most of the variables in these xcconfig
files are pretty self-explanatory, their meaning is
specified in files with extension .xcspec
that are stored in the Xcode.app
bundle. You can find
these files by running the following:
$ find /Applications/Xcode.app -name \*.xcspec
Xcode Index Files
Xcode stores index files for code completion and general navigation. A good explanation of how this works
is in this video. If you need to dump the index files,
follow the instructions on this gist.
Xcodebuild flags
-UseSanitizedBuildSystemEnvironment=YES
– Makesxcodebuild
behave like the IDE.-IDEBuildOperationTimingLogLevel=3
– Enable extensive per-task timings.-IDEBuildOperationDependenciesLogLevel=3
– Enable old build system logging for "implicit dependencies"-IDEShowPrebuildLogs=YES
– Show logs from the "prebuild" step.-ShowBuildOperationDuration=YES
– Enable timings on build operations.
All of these can be set permanently using:
defaults write com.apple.dt.Xcode $OPTION [-bool|-int|-string] $VALUE
See man defaults
利用macport快速调试开源软件
使用vscode打开 bash的Portfile
port edit --editor code bash
追加几个debug相关的参数
对于make
configure.args --mandir=${prefix}/share/man \
--infodir=${prefix}/share/info \
--without-installed-readline \
CFLAGS_FOR_BUILD="[get_canonical_archflags]" \
CPPFLAGS=-DDEBUG \
CFLAGS="-g -O0" \
CXXFLAGS="-g -O0"
对于cmake
-DCMAKE_BUILD_TYPE=Debug
编译并调试
port configure bash
port build bash
cd $(port work bash)
cd bash-5.0
lldb bash
通过Portfile安装软件
需要保证Portfile和资源齐全。例如bash需要Portfile和files/patch-configure.diff
port -df install -D .
Ubuntu下编译ruby
- install linuxbrew
brew sh --env=std
./configure --prefix=/home/kila/workspace/ruby-2.7.1/hello --enable-shared --disable-silent-rules --with-sitedir=/home/linuxbrew/.linuxbrew/lib/ruby/site_ruby --with-vendordir=/home/linuxbrew/.linuxbrew/lib/ruby/vendor_ruby --with-opt-dir=/home/linuxbrew/.linuxbrew/opt/libyaml:/home/linuxbrew/.linuxbrew/opt/[email protected]:/home/linuxbrew/.linuxbrew/opt/readline --without-gmp MJIT_CC=/usr/bin/gcc
make
make install
bash note
# 转义\n
sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/\\n/g' <file>
# 批量转换文本替换
find **/**/project.pbxproj -exec sed -i '' -e 's/.*\dummy.m.*//g' {} +
避免 zsh 进入大型仓库卡顿
git config --add oh-my-zsh.hide-status 1
git config --add oh-my-zsh.hide-dirty 1
git config --add oh-my-zsh.hide-info 1
git config core.fsmonitor true
git config core.untrackedcache true
ref: https://github.blog/2022-06-29-improve-git-monorepo-performance-with-a-file-system-monitor/
git config feature.manyFiles true
ref: https://github.blog/2019-11-03-highlights-from-git-2-24/
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.