diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index b34a4b2dc63baa7e8c44a2af5221af145f6b544c..0f989c0e59084e0abaeadc4a6af139582fc9f44a 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -668,6 +668,18 @@ fn run(self, builder: &Builder<'_>) -> Option { 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()) } } diff --git a/src/bootstrap/std_rename.sh b/src/bootstrap/std_rename.sh new file mode 100644 index 0000000000000000000000000000000000000000..634fb40e1c17a4314ef7841a4ac4e7d5d72a7aac --- /dev/null +++ b/src/bootstrap/std_rename.sh @@ -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 \ No newline at end of file