mirror of
https://github.com/openharmony/third_party_rust_rust.git
synced 2026-07-18 17:34:40 -04:00
rename std by adding .dylib and deleting metadata id
rename std by adding .dylib and deleting metadata id Signed-off-by: fengting <fengting11@huawei.com>
This commit is contained in:
@@ -668,6 +668,18 @@ impl Step for Std {
|
||||
verify_uefi_rlib_format(builder, target, &stamp);
|
||||
copy_target_libs(builder, target, &tarball.image_dir(), &stamp);
|
||||
|
||||
// For std of linux-ohos target,
|
||||
// we want to delete metadata-id from the filename, and add '.dylib' for `libstd` and `libtest`.
|
||||
// After changing the filename,
|
||||
// we modify the dependency of `libtest.dylib.so` from `libstd-{metadata-id}.so` to `libstd.dylib.so`.
|
||||
if target.triple.ends_with("-linux-ohos") {
|
||||
let script = builder.src.join("src/bootstrap/std_rename.sh");
|
||||
Command::new("bash")
|
||||
.arg(script)
|
||||
.arg(&target.triple)
|
||||
.output()
|
||||
.expect("Renaming for std fails.");
|
||||
}
|
||||
Some(tarball.generate())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
readonly script_path=$(cd $(dirname $0);pwd)
|
||||
readonly build_path="${script_path}/../../build"
|
||||
|
||||
# $1 is target triple, such as `x86_64-unknown-linux-ohos`.
|
||||
readonly lib_path="${build_path}/tmp/tarball/rust-std/$1/image/lib/rustlib/$1/lib"
|
||||
|
||||
for file in $(find "${lib_path}" -name "lib*.*")
|
||||
do
|
||||
dir_name=${file%/*}
|
||||
file_name=${file##*/}
|
||||
file_prefix=$(echo "$file_name" | awk '{split($1, arr, "."); print arr[1]}')
|
||||
file_suffix=$(echo "$file_name" | awk '{split($1, arr, "."); print arr[2]}')
|
||||
|
||||
# Get filename without metadata-id.
|
||||
file_prefix=$(echo "$file_prefix" | awk '{split($1, arr, "-"); print arr[1]}')
|
||||
|
||||
if [[ "$file_suffix" != "rlib" && "$file_suffix" != "so" || "$file_prefix" == "librustc_demangle" || "$file_prefix" == "libcfg_if" || "$file_prefix" == "libunwind" ]]
|
||||
then
|
||||
continue
|
||||
fi
|
||||
if [[ "$file_suffix" == "rlib" ]]
|
||||
then
|
||||
if [[ "$file_prefix" == "libstd" || "$file_prefix" == "libtest" ]]
|
||||
then
|
||||
# Add '.dylib' for `libstd` and `libtest`.
|
||||
newfile_name="$file_prefix.dylib.rlib"
|
||||
else
|
||||
newfile_name="$file_prefix.rlib"
|
||||
fi
|
||||
fi
|
||||
|
||||
# `libstd` and `libtest` have both `so` and `rlib`, the other libs only have `rlib`.
|
||||
if [[ "$file_suffix" == "so" ]]
|
||||
then
|
||||
newfile_name="$file_prefix.dylib.so"
|
||||
if [[ "$file_prefix" == "libtest" ]]
|
||||
then
|
||||
# Modify the dependency of `libtest.dylib.so` from `libstd-{metadata-id}.so` to `libstd.dylib.so`.
|
||||
readonly dynstr_section_vaddr=$(readelf -S "$file" | grep ".dynstr" | awk -F']' '{print $2}' | awk '{print strtonum("0x"$3)}')
|
||||
readonly libstd_str_offset=$(readelf -p .dynstr "$file" | grep "libstd-[a-z0-9]\{16\}\.so" | awk -F'[' '{print $2}' | awk '{print $1}' | awk -F']' '{print strtonum("0x"$1)}')
|
||||
readonly libstd_str_vaddr=`expr $dynstr_section_vaddr + $libstd_str_offset`
|
||||
$(printf 'libstd.dylib.so\0\0\0\0\0\0\0\0\0\0\0' | dd of="$file" bs=1 seek=$libstd_str_vaddr count=26 conv=notrunc)
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "$file_name" == "$newfile_name" ]]
|
||||
then
|
||||
continue
|
||||
fi
|
||||
|
||||
mv $file "$dir_name/$newfile_name"
|
||||
done
|
||||
Reference in New Issue
Block a user