Skip to content

Commit 8770511

Browse files
committed
fix: reaspi3.config not exist when make build
1 parent a54ab80 commit 8770511

File tree

116 files changed

+8511
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+8511
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ run_*
3333
exec_log
3434
make-tag.sh
3535

36-
!scripts/build/
36+
!/**/scripts/build/
3737

3838
/ramdisk
3939
/.chpm

Lab1/scripts/build/buildup_cpp.sh

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
#!/bin/bash
2+
# Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
3+
# Licensed under the Mulan PSL v2.
4+
# You can use this software according to the terms and conditions of the Mulan PSL v2.
5+
# You may obtain a copy of Mulan PSL v2 at:
6+
# http://license.coscl.org.cn/MulanPSL2
7+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8+
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9+
# PURPOSE.
10+
# See the Mulan PSL v2 for more details.
11+
12+
# The .cpp directory structure:
13+
# .cpp
14+
# ├── aarch64
15+
# │ ├── include
16+
# │ └── lib
17+
# ├─── x86_64
18+
# │ ├── include
19+
# │ └── lib
20+
# ├─── riscv64
21+
# │ ├── include
22+
# │ └── lib
23+
# └─ download
24+
# ├── musl-cross-make
25+
# └── prebuild
26+
#
27+
# When using C++ toolchains, {arch}/include & {arch}/include/{musl_target} directory
28+
# is included into prefix path by CMKAE function `include_directories`
29+
#
30+
# {arch}/lib/libgcc_s.so.1 & {arch}/lib/libstdc++.so.6 file is copy into ramdisk directory
31+
# to support staros C++ programs in runtime
32+
33+
set -e
34+
35+
project_dir=$(cd $(dirname $(dirname $(cd $(dirname "$0"); pwd))); pwd)
36+
cpp_dir="$project_dir/.cpp"
37+
download_dir="$project_dir/.cpp/download/"
38+
39+
libfile_url="git@ipads.se.sjtu.edu.cn:staros/cpp-libs.git"
40+
41+
musl_cross_dir="$download_dir/musl-cross-make"
42+
musl_cross_url="https://github.com/richfelker/musl-cross-make.git"
43+
44+
GCC_VER=9.2.0
45+
MUSL_VER=1.2.3
46+
47+
copy_to_ramdisk() {
48+
arch=$1
49+
50+
if [ ! -d $project_dir/ramdisk ]; then
51+
mkdir $project_dir/ramdisk
52+
fi
53+
54+
cp $cpp_dir/$arch/lib/libgcc_s.so.1 $project_dir/ramdisk
55+
cp $cpp_dir/$arch/lib/libstdc++.so.6 $project_dir/ramdisk
56+
}
57+
58+
prebuild_load() {
59+
retval=1
60+
61+
if [ ! -d "$cpp_dir" ]; then
62+
mkdir $cpp_dir
63+
mkdir $download_dir
64+
fi
65+
66+
# Get the package from the target URL
67+
if [ ! -d "$download_dir/prebuild" ]; then
68+
git clone --depth 1 $libfile_url $download_dir/prebuild
69+
fi
70+
71+
# if prebuild load success, exit
72+
if [ -d "$download_dir/prebuild" ]; then
73+
cp -r $download_dir/prebuild/* $cpp_dir
74+
75+
copy_to_ramdisk $1
76+
77+
retval=0
78+
fi
79+
80+
return $retval
81+
}
82+
83+
musl_cross_build() {
84+
pushd $musl_cross_dir
85+
86+
echo "TARGET = $1" > config.mak
87+
echo "GCC_VER=$GCC_VER" >> config.mak
88+
echo "MUSL_VER=$MUSL_VER" >> config.mak
89+
90+
make -j$(nproc)
91+
92+
rm config.mak
93+
94+
popd
95+
}
96+
97+
#usage: musl_cross_install $musl_target $arch
98+
musl_cross_install() {
99+
musl_target=$1
100+
target_arch=$2
101+
102+
musl_target_dir=$musl_cross_dir/build/local/$musl_target
103+
musl_libsupcpp_dir=$musl_target_dir/src_gcc/libstdc++-v3/libsupc++
104+
cpp_target_dir=$cpp_dir/$target_arch
105+
106+
if [ -d "$cpp_target_dir" ]; then
107+
rm -rf $cpp_target_dir
108+
fi
109+
110+
mkdir $cpp_target_dir
111+
mkdir $cpp_target_dir/lib
112+
113+
cp -Lr $musl_target_dir/obj_gcc/$musl_target/libstdc++-v3/include $cpp_target_dir/include
114+
cp $musl_libsupcpp_dir/exception $cpp_target_dir/include/
115+
cp $musl_libsupcpp_dir/typeinfo $cpp_target_dir/include/
116+
cp $musl_libsupcpp_dir/new $cpp_target_dir/include/
117+
cp $musl_libsupcpp_dir/initializer_list $cpp_target_dir/include/
118+
119+
cp $musl_target_dir/obj_gcc/$musl_target/libstdc++-v3/src/.libs/libstdc++.so* $cpp_dir/$2/lib
120+
cp $musl_target_dir/obj_gcc/gcc/libgcc_s.so* $cpp_dir/$2/lib
121+
122+
copy_to_ramdisk $2
123+
}
124+
125+
126+
_main() {
127+
case $1 in
128+
129+
x86_64)
130+
target_arch=x86_64
131+
musl_target=x86_64-linux-musl
132+
;;
133+
aarch64 | raspi3 | raspi4)
134+
target_arch=aarch64
135+
musl_target=aarch64-linux-musleabi
136+
;;
137+
riscv64)
138+
target_arch=riscv64
139+
musl_target=riscv64-linux-musl
140+
;;
141+
*)
142+
echo "Usage: $0 target_arch"
143+
exit
144+
;;
145+
esac
146+
147+
prebuild_load $target_arch
148+
if [ $? -eq 0 ]; then
149+
echo "Done! You can try to build the cpp project now!"
150+
exit 0
151+
fi
152+
153+
154+
read -n 1 -p "git clone from $libfile_url failed, if you want to build from source?[y/n] :" response
155+
156+
if [ ! "$response" == "y" ]; then
157+
echo "exit!"
158+
exit 0
159+
fi
160+
161+
#if prebuild load failed, build from source
162+
if [ ! -d $musl_cross_dir ]; then
163+
git clone $musl_cross_url $musl_cross_dir
164+
fi
165+
166+
if [ ! -d $musl_cross_dir ]; then
167+
echo "git clone failed"
168+
exit 1
169+
fi
170+
171+
musl_cross_build $musl_target
172+
musl_cross_install $musl_target $target_arch
173+
174+
echo "Done! You can try to build the cpp project now!"
175+
exit 0
176+
}
177+
178+
_main $@
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
2+
# Licensed under the Mulan PSL v2.
3+
# You can use this software according to the terms and conditions of the Mulan PSL v2.
4+
# You may obtain a copy of Mulan PSL v2 at:
5+
# http://license.coscl.org.cn/MulanPSL2
6+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
7+
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
8+
# PURPOSE.
9+
# See the Mulan PSL v2 for more details.
10+
11+
#[[
12+
Dump cache variables from `CMakeCache.txt` to `.config`.
13+
14+
This script is intended to be used as -C option of
15+
cmake command.
16+
#]]
17+
18+
include(${CMAKE_CURRENT_LIST_DIR}/Modules/CommonTools.cmake)
19+
20+
set(_config_lines)
21+
22+
macro(chcore_config _config_name _config_type _default _description)
23+
# Dump config lines in definition order
24+
list(APPEND _config_lines
25+
"${_config_name}:${_config_type}=${${_config_name}}")
26+
endmacro()
27+
28+
include(${CMAKE_SOURCE_DIR}/config.cmake)
29+
30+
string(REPLACE ";" "\n" _config_str "${_config_lines}")
31+
32+
file(WRITE ${CMAKE_SOURCE_DIR}/.config "${_config_str}\n")
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
# Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
3+
# Licensed under the Mulan PSL v2.
4+
# You can use this software according to the terms and conditions of the Mulan PSL v2.
5+
# You may obtain a copy of Mulan PSL v2 at:
6+
# http://license.coscl.org.cn/MulanPSL2
7+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8+
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9+
# PURPOSE.
10+
# See the Mulan PSL v2 for more details.
11+
12+
# This script prints a prompt and read user input.
13+
# Should only be used in `LoadConfigAsk.cmake`.
14+
15+
echo -n "$1 "
16+
read -p "" input
17+
echo $input >&2
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
2+
# Licensed under the Mulan PSL v2.
3+
# You can use this software according to the terms and conditions of the Mulan PSL v2.
4+
# You may obtain a copy of Mulan PSL v2 at:
5+
# http://license.coscl.org.cn/MulanPSL2
6+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
7+
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
8+
# PURPOSE.
9+
# See the Mulan PSL v2 for more details.
10+
11+
#[[
12+
Load cache variables from `.config` and `config.cmake`.
13+
14+
This script is intended to be used as -C option of
15+
cmake command.
16+
#]]
17+
18+
include(${CMAKE_CURRENT_LIST_DIR}/Modules/CommonTools.cmake)
19+
20+
if(EXISTS ${CMAKE_SOURCE_DIR}/.config)
21+
# Read in config file
22+
file(READ ${CMAKE_SOURCE_DIR}/.config _config_str)
23+
string(REPLACE "\n" ";" _config_lines "${_config_str}")
24+
unset(_config_str)
25+
26+
# Set config cache variables
27+
foreach(_line ${_config_lines})
28+
if(${_line} MATCHES "^//" OR ${_line} MATCHES "^#")
29+
continue()
30+
endif()
31+
string(REGEX MATCHALL "^([^:=]+):([^:=]+)=(.*)$" _config "${_line}")
32+
if("${_config}" STREQUAL "")
33+
message(FATAL_ERROR "Invalid line in `.config`: ${_line}")
34+
endif()
35+
set(${CMAKE_MATCH_1}
36+
${CMAKE_MATCH_3}
37+
CACHE ${CMAKE_MATCH_2} "" FORCE)
38+
endforeach()
39+
unset(_config_lines)
40+
else()
41+
message(WARNING "There is no `.config` file")
42+
endif()
43+
44+
# Check if there exists `chcore_config` macro, which will be used in
45+
# `config.cmake`
46+
if(NOT COMMAND chcore_config)
47+
message(FATAL_ERROR "Don't directly use `LoadConfig.cmake`")
48+
endif()
49+
50+
macro(chcore_config _config_name _config_type _default _description)
51+
if(DEFINED ${_config_name})
52+
# config is in `.config`, set description
53+
set(${_config_name}
54+
${${_config_name}}
55+
CACHE ${_config_type} ${_description} FORCE)
56+
else()
57+
# config is not in `.config`, use previously-defined chcore_config
58+
# Note: use quota marks to allow forwarding empty arguments
59+
_chcore_config("${_config_name}" "${_config_type}" "${_default}"
60+
"${_description}")
61+
endif()
62+
endmacro()
63+
64+
# Include the top-level config definition file
65+
include(${CMAKE_SOURCE_DIR}/config.cmake)
66+
67+
# Hide unrelavant builtin cache variables
68+
mark_as_advanced(CMAKE_BUILD_TYPE)
69+
mark_as_advanced(CMAKE_INSTALL_PREFIX)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
2+
# Licensed under the Mulan PSL v2.
3+
# You can use this software according to the terms and conditions of the Mulan PSL v2.
4+
# You may obtain a copy of Mulan PSL v2 at:
5+
# http://license.coscl.org.cn/MulanPSL2
6+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
7+
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
8+
# PURPOSE.
9+
# See the Mulan PSL v2 for more details.
10+
11+
#[[
12+
Load config values from `.config` and check if all
13+
cache variables defined in `config.cmake` are set,
14+
if not, abort.
15+
16+
This script is intended to be used as -C option of
17+
cmake command.
18+
#]]
19+
20+
macro(chcore_config _config_name _config_type _default _description)
21+
if(NOT DEFINED ${_config_name})
22+
message(FATAL_ERROR "${_config_name} is not set")
23+
endif()
24+
endmacro()
25+
26+
include(${CMAKE_CURRENT_LIST_DIR}/LoadConfig.cmake)

0 commit comments

Comments
 (0)