diff --git a/components/ncnn/SConstruct b/components/ncnn/SConstruct index 314f615..d07f277 100644 --- a/components/ncnn/SConstruct +++ b/components/ncnn/SConstruct @@ -1,135 +1,152 @@ # component2/SConscript -Import('env') +Import("env") import os -with open(env['PROJECT_TOOL_S']) as f: + +with open(env["PROJECT_TOOL_S"]) as f: exec(f.read()) - - -if 'CONFIG_NCNN_ENABLED' in os.environ: - check_component('ncnn') - SRCS=[] +if "CONFIG_NCNN_ENABLED" in os.environ: + check_component("ncnn") + SRCS = [] SRCS_CUSTOM = {} - INCLUDE=[] - PRIVATE_INCLUDE=[] - REQUIREMENTS=[] - STATIC_LIB=[] - DYNAMIC_LIB=[] - DEFINITIONS=[] + INCLUDE = [] + PRIVATE_INCLUDE = [] + REQUIREMENTS = [] + STATIC_LIB = [] + DYNAMIC_LIB = [] + DEFINITIONS = [] DEFINITIONS_PRIVATE = [] - LDFLAGS=[] - LINK_SEARCH_PATH=[] - - INCLUDE.append(ADir('../../github_source/ncnn/src')) - INCLUDE.append(ADir('../../github_source/ncnn/src/layer')) - gcc_dumpmachine = env['GCC_DUMPMACHINE'].split('-') - if 'arm' in gcc_dumpmachine and 'gnueabihf' in gcc_dumpmachine: - DEFINITIONS_PRIVATE += ['-O3 -DNDEBUG -fPIC -DNCNN_STATIC_DEFINE -Wall -Wextra -Wno-unused-function -Ofast -ffast-math -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp -pthread'] - DEFINITIONS_PRIVATE += ['-march=armv7-a -mfloat-abi=hard -mfpu=neon'] + LDFLAGS = [] + LINK_SEARCH_PATH = [] + + INCLUDE.append(ADir("../../github_source/ncnn/src")) + INCLUDE.append(ADir("../../github_source/ncnn/src/layer")) + gcc_dumpmachine = env["GCC_DUMPMACHINE"].split("-") + if "arm" in gcc_dumpmachine and "gnueabihf" in gcc_dumpmachine: + DEFINITIONS_PRIVATE += [ + "-O3 -DNDEBUG -fPIC -DNCNN_STATIC_DEFINE -Wall -Wextra -Wno-unused-function -Ofast -ffast-math -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp -pthread" + ] + DEFINITIONS_PRIVATE += ["-march=armv7-a -mfloat-abi=hard -mfpu=neon"] # DEFINITIONS_PRIVATE += ['-DNCNN_SIMPLEOCV'] - - INCLUDE.append(ADir('include/arm-linux-gnueabihf')) - INCLUDE.append(ADir('../../github_source/ncnn/src/layer/arm')) - SRCS += AGlob('../../github_source/ncnn/src/*.cpp') - SRCS += AGlob('../../github_source/ncnn/src/layer/*.cpp') - SRCS += AGlob('../../github_source/ncnn/src/layer/arm/*.cpp') - filter_cpp = ['argmax.cpp' - ,'spp.cpp' - ,'mat_pixel_android.cpp' - ,'batchnorm_arm_asimdhp.cpp' - ,'binaryop_arm_asimdhp.cpp' - ,'clip_arm_asimdhp.cpp' - ,'convolution1d_arm_asimdhp.cpp' - ,'convolution_arm_asimddp.cpp' - ,'convolution_arm_asimdhp.cpp' - ,'convolution_arm_i8mm.cpp' - ,'convolutiondepthwise_arm_asimdhp.cpp' - ,'deconvolution_arm_asimdhp.cpp' - ,'deconvolutiondepthwise_arm_asimdhp.cpp' - ,'dequantize_arm_asimdhp.cpp' - ,'eltwise_arm_asimdhp.cpp' - ,'gelu_arm_asimdhp.cpp' - ,'gru_arm_asimddp.cpp' - ,'gru_arm_asimdhp.cpp' - ,'hardsigmoid_arm_asimdhp.cpp' - ,'hardswish_arm_asimdhp.cpp' - ,'instancenorm_arm_asimdhp.cpp' - ,'interp_arm_asimdhp.cpp' - ,'lstm_arm_asimddp.cpp' - ,'lstm_arm_asimdhp.cpp' - ,'mish_arm_asimdhp.cpp' - ,'pooling_arm_asimdhp.cpp' - ,'prelu_arm_asimdhp.cpp' - ,'quantize_arm_asimdhp.cpp' - ,'relu_arm_asimdhp.cpp' - ,'rnn_arm_asimddp.cpp' - ,'rnn_arm_asimdhp.cpp' - ,'sigmoid_arm_asimdhp.cpp' - ,'swish_arm_asimdhp.cpp' - ,'tanh_arm_asimdhp.cpp' - ,'unaryop_arm_asimdhp.cpp' - ,'cast_arm_bf16.cpp' - ,'gemm_arm_asimdhp.cpp' - ,'gemm_arm_vfpv4.cpp' - ,'gemm_arm_asimdfhm.cpp' - ,'innerproduct_arm_asimdfhm.cpp' - ,'innerproduct_arm_asimdhp.cpp' - ,'innerproduct_arm_vfpv4.cpp' - ,'softmax_arm_asimdhp.cpp' - ] + INCLUDE.append(ADir("include/arm-linux-gnueabihf")) + INCLUDE.append(ADir("../../github_source/ncnn/src/layer/arm")) + SRCS += AGlob("../../github_source/ncnn/src/*.cpp") + SRCS += AGlob("../../github_source/ncnn/src/layer/*.cpp") + SRCS += AGlob("../../github_source/ncnn/src/layer/arm/*.cpp") - SRCS = list(filter(lambda x: os.path.basename(str(x)) not in filter_cpp, SRCS)) - - elif 'x86_64' in gcc_dumpmachine and 'linux' in gcc_dumpmachine: - DEFINITIONS_PRIVATE += ['-std=c++11 -std=c++11 -O3 -DNDEBUG -DNCNN_STATIC_DEFINE -Wall -Wextra -Wno-unused-function -Ofast -ffast-math -fvisibility=hidden -fvisibility-inlines-hidden'] - DEFINITIONS_PRIVATE += ['-msse2 -msse -fopenmp'] - # -fPIC - - INCLUDE.append(ADir('include/build-host-gcc-linux')) - INCLUDE.append(ADir('../../github_source/ncnn/src/layer/x86')) - INCLUDE.append(ADir('../../github_source/ncnn/build-host-gcc-linux/src')) - SRCS += AGlob('../../github_source/ncnn/src/*.cpp') - SRCS += AGlob('../../github_source/ncnn/src/layer/*.cpp') - SRCS += AGlob('../../github_source/ncnn/src/layer/x86/*.cpp') - - filter_cpp = [ - 'mat_pixel_android.cpp' - ,'argmax.cpp' - ,'spp.cpp' - ,'cast_x86_avx512bf16.cpp' - ,'innerproduct_x86_f16c.cpp' + "argmax.cpp", + "spp.cpp", + "mat_pixel_android.cpp", + "batchnorm_arm_asimdhp.cpp", + "binaryop_arm_asimdhp.cpp", + "clip_arm_asimdhp.cpp", + "convolution1d_arm_asimdhp.cpp", + "convolution_arm_asimddp.cpp", + "convolution_arm_asimdhp.cpp", + "convolution_arm_i8mm.cpp", + "convolutiondepthwise_arm_asimdhp.cpp", + "deconvolution_arm_asimdhp.cpp", + "deconvolutiondepthwise_arm_asimdhp.cpp", + "dequantize_arm_asimdhp.cpp", + "eltwise_arm_asimdhp.cpp", + "gelu_arm_asimdhp.cpp", + "gru_arm_asimddp.cpp", + "gru_arm_asimdhp.cpp", + "hardsigmoid_arm_asimdhp.cpp", + "hardswish_arm_asimdhp.cpp", + "instancenorm_arm_asimdhp.cpp", + "interp_arm_asimdhp.cpp", + "lstm_arm_asimddp.cpp", + "lstm_arm_asimdhp.cpp", + "mish_arm_asimdhp.cpp", + "pooling_arm_asimdhp.cpp", + "prelu_arm_asimdhp.cpp", + "quantize_arm_asimdhp.cpp", + "relu_arm_asimdhp.cpp", + "rnn_arm_asimddp.cpp", + "rnn_arm_asimdhp.cpp", + "sigmoid_arm_asimdhp.cpp", + "swish_arm_asimdhp.cpp", + "tanh_arm_asimdhp.cpp", + "unaryop_arm_asimdhp.cpp", + "cast_arm_bf16.cpp", + "gemm_arm_asimdhp.cpp", + "gemm_arm_vfpv4.cpp", + "gemm_arm_asimdfhm.cpp", + "innerproduct_arm_asimdfhm.cpp", + "innerproduct_arm_asimdhp.cpp", + "innerproduct_arm_vfpv4.cpp", + "softmax_arm_asimdhp.cpp", + ] + SRCS = list(filter(lambda x: os.path.basename(str(x)) not in filter_cpp, SRCS)) + + elif "x86_64" in gcc_dumpmachine and "linux" in gcc_dumpmachine: + DEFINITIONS_PRIVATE += [ + "-std=c++11 -std=c++11 -O3 -DNDEBUG -DNCNN_STATIC_DEFINE -Wall -Wextra -Wno-unused-function -Ofast -ffast-math -fvisibility=hidden -fvisibility-inlines-hidden" + ] + DEFINITIONS_PRIVATE += ["-msse2 -msse -fopenmp"] + # -fPIC + + INCLUDE.append(ADir("include/build-host-gcc-linux")) + INCLUDE.append(ADir("../../github_source/ncnn/src/layer/x86")) + INCLUDE.append(ADir("../../github_source/ncnn/build-host-gcc-linux/src")) + SRCS += AGlob("../../github_source/ncnn/src/*.cpp") + SRCS += AGlob("../../github_source/ncnn/src/layer/*.cpp") + SRCS += AGlob("../../github_source/ncnn/src/layer/x86/*.cpp") + + filter_cpp = [ + "mat_pixel_android.cpp", + "argmax.cpp", + "spp.cpp", + "cast_x86_avx512bf16.cpp", + "innerproduct_x86_f16c.cpp", ] SRCS = list(filter(lambda x: os.path.basename(str(x)) not in filter_cpp, SRCS)) - - - SRCS_TMP = AGlob('../../github_source/ncnn/build-host-gcc-linux/src/layer/x86/*.cpp') + SRCS_TMP = AGlob( + "../../github_source/ncnn/build-host-gcc-linux/src/layer/x86/*.cpp" + ) for src in SRCS_TMP: if os.path.basename(str(src)) in filter_cpp: continue - elif str(src).endswith('avx512.cpp'): - SRCS_CUSTOM[src] = {'CPPFLAGS':['-mavx512f', '-mavx512cd', '-mavx512bw', '-mavx512dq', '-mavx512vl', '-mfma', '-mf16c'], 'CCFLAGS':[]} - elif str(src).endswith('fma.cpp'): - SRCS_CUSTOM[src] = {'CPPFLAGS':['-mavx', '-mfma', '-mf16c'], 'CCFLAGS':[]} - elif str(src).endswith('avx.cpp'): - SRCS_CUSTOM[src] = {'CPPFLAGS':['-mavx'], 'CCFLAGS':[]} + elif str(src).endswith("avx512.cpp"): + SRCS_CUSTOM[src] = { + "CPPFLAGS": [ + "-mavx512f", + "-mavx512cd", + "-mavx512bw", + "-mavx512dq", + "-mavx512vl", + "-mfma", + "-mf16c", + ], + "CCFLAGS": [], + } + elif str(src).endswith("fma.cpp"): + SRCS_CUSTOM[src] = { + "CPPFLAGS": ["-mavx", "-mfma", "-mf16c"], + "CCFLAGS": [], + } + elif str(src).endswith("avx.cpp"): + SRCS_CUSTOM[src] = {"CPPFLAGS": ["-mavx"], "CCFLAGS": []} - # for f in SRCS: - # print(str(f)) - env['COMPONENTS'].append({'target':os.path.basename(env['component_dir']), - 'SRCS':SRCS, - 'SRCS_CUSTOM':SRCS_CUSTOM, - 'INCLUDE':INCLUDE, - 'PRIVATE_INCLUDE':PRIVATE_INCLUDE, - 'REQUIREMENTS':REQUIREMENTS, - 'STATIC_LIB':STATIC_LIB, - 'DYNAMIC_LIB':DYNAMIC_LIB, - 'DEFINITIONS':DEFINITIONS, - 'DEFINITIONS_PRIVATE':DEFINITIONS_PRIVATE, - 'LDFLAGS':LDFLAGS, - 'LINK_SEARCH_PATH':LINK_SEARCH_PATH, - 'REGISTER':'static' - }) + env["COMPONENTS"].append( + { + "target": os.path.basename(env["component_dir"]), + "SRCS": SRCS, + "SRCS_CUSTOM": SRCS_CUSTOM, + "INCLUDE": INCLUDE, + "PRIVATE_INCLUDE": PRIVATE_INCLUDE, + "REQUIREMENTS": REQUIREMENTS, + "STATIC_LIB": STATIC_LIB, + "DYNAMIC_LIB": DYNAMIC_LIB, + "DEFINITIONS": DEFINITIONS, + "DEFINITIONS_PRIVATE": DEFINITIONS_PRIVATE, + "LDFLAGS": LDFLAGS, + "LINK_SEARCH_PATH": LINK_SEARCH_PATH, + "REGISTER": "static", + } + ) diff --git a/components/simdjson_component/Kconfig b/components/simdjson_component/Kconfig new file mode 100644 index 0000000..c55c1f2 --- /dev/null +++ b/components/simdjson_component/Kconfig @@ -0,0 +1,9 @@ +menuconfig SIMDJSON_COMPENENT_ENABLED + bool "Enable simdjson" + default n + + config SIMDJSON_COMPENENT_DYNAMIC + bool "compile component as dynamic(shared) lib" + default n + depends on SIMDJSON_COMPENENT_ENABLED + diff --git a/components/simdjson_component/SConstruct b/components/simdjson_component/SConstruct new file mode 100644 index 0000000..e704b34 --- /dev/null +++ b/components/simdjson_component/SConstruct @@ -0,0 +1,53 @@ +# component2/SConscript +Import("env") +import os + +with open(env["PROJECT_TOOL_S"]) as f: + exec(f.read()) + +if "CONFIG_SIMDJSON_COMPENENT_ENABLED" in os.environ: + check_component("simdjson") + SRCS = [] + INCLUDE = [] + PRIVATE_INCLUDE = [] + REQUIREMENTS = [] + STATIC_LIB = [] + DYNAMIC_LIB = [] + DEFINITIONS = [] + DEFINITIONS_PRIVATE = [] + LDFLAGS = [] + LINK_SEARCH_PATH = [] + + COMPONENT_PATH = os.path.join(os.environ["GIT_REPO_PATH"], "simdjson") + SRCS += [os.path.join(COMPONENT_PATH, "src/simdjson.cpp")] + + gcc_dumpmachine = env["GCC_DUMPMACHINE"].split("-") + if "x86_64" in gcc_dumpmachine and "linux" in gcc_dumpmachine: + DEFINITIONS_PRIVATE += [ + "-mno-avx256-split-unaligned-load", + "-mno-avx256-split-unaligned-store", + ] + DEFINITIONS_PRIVATE += [ + "-DSIMDJSON_AVX512_ALLOWED=1", + "-DSIMDJSON_THREADS_ENABLED=1", + "-DSIMDJSON_UTF8VALIDATION=1", + ] + INCLUDE.append(os.path.join(COMPONENT_PATH, "include")) + PRIVATE_INCLUDE.append(os.path.join(COMPONENT_PATH, "src")) + + env["COMPONENTS"].append( + { + "target": os.path.basename(env["component_dir"]), + "SRCS": SRCS, + "INCLUDE": INCLUDE, + "PRIVATE_INCLUDE": PRIVATE_INCLUDE, + "REQUIREMENTS": REQUIREMENTS, + "STATIC_LIB": STATIC_LIB, + "DYNAMIC_LIB": DYNAMIC_LIB, + "DEFINITIONS": DEFINITIONS, + "DEFINITIONS_PRIVATE": DEFINITIONS_PRIVATE, + "LDFLAGS": LDFLAGS, + "LINK_SEARCH_PATH": LINK_SEARCH_PATH, + "REGISTER": "shared" if "CONFIG_LNNG_DYNAMIC" in os.environ else "static", + } + ) diff --git a/components/sqlite3_component/SConstruct b/components/sqlite3_component/SConstruct index e0b0240..79e60e9 100644 --- a/components/sqlite3_component/SConstruct +++ b/components/sqlite3_component/SConstruct @@ -1,75 +1,50 @@ # component/SConscript -Import('env') +Import("env") import os -with open(env['PROJECT_TOOL_S']) as f: + +with open(env["PROJECT_TOOL_S"]) as f: exec(f.read()) + def get_sqlite3_lib(): - sqlite3_path = str(ADir('../../github_source/sqlite3')) - if not os.path.exists(sqlite3_path): - zip_file = str(AFile('../../github_source/sqlite-amalgamation-3460000.zip')) - zip_file_extrpath = sqlite3_path + '_tmp' - down_url = "https://sqlite.org/2024/sqlite-amalgamation-3460000.zip" - - if 'CONFIG_REPO_AUTOMATION' in os.environ: - down = 'y' - else: - down = input('{} does not exist. Please choose whether to download it automatically? Y/N :'.format('sqlite-amalgamation-3460000.zip')) - down = down.lower() - if down == 'y': - # from git import Repo - import requests - import parse - import zipfile - import shutil - try: - # Downloading via HTTP (more common) - if not os.path.exists(zip_file): - response = requests.get(down_url) - if response.status_code == 200: - with open(zip_file, 'wb') as file: - file.write(response.content) - else: - env.Fatal("{} down failed".format(down_url)) - with zipfile.ZipFile(zip_file, 'r') as zip_ref: - zip_ref.extractall(zip_file_extrpath) - shutil.move(os.path.join(zip_file_extrpath, 'sqlite-amalgamation-3460000'), sqlite3_path) - shutil.rmtree(zip_file_extrpath) - print("The {} download successful.".format(down_url)) - except Exception as e: - print('Please manually download {} to {} .'.format(down_url, zip_file)) - env.Fatal("Cloning failed.: {}".format(e)) - else: - env.Fatal('Please manually download {} to {} .'.format(down_url, zip_file)) - INCLUDE = [sqlite3_path] - SRCS = [AFile('../../github_source/sqlite3/sqlite3.c')] + sqlite3_path = check_wget_down( + "https://sqlite.org/2024/sqlite-amalgamation-3460000.zip", + "sqlite-amalgamation-3460000.zip", + ) + sqlite3_project_path = os.path.join(sqlite3_path, "sqlite-amalgamation-3460000") + INCLUDE = [sqlite3_project_path] + SRCS = [os.path.join(sqlite3_project_path, "sqlite3.c")] return INCLUDE, SRCS -if 'CONFIG_SQLITE3_COMPOENENT_ENABLED' in os.environ: - SRCS=[] - INCLUDE=[] - PRIVATE_INCLUDE=[] - REQUIREMENTS=[] - STATIC_LIB=[] - DYNAMIC_LIB=[] - DEFINITIONS=[] - DEFINITIONS_PRIVATE=[] - LDFLAGS=[] - LINK_SEARCH_PATH=[] + +if "CONFIG_SQLITE3_COMPOENENT_ENABLED" in os.environ: + SRCS = [] + INCLUDE = [] + PRIVATE_INCLUDE = [] + REQUIREMENTS = [] + STATIC_LIB = [] + DYNAMIC_LIB = [] + DEFINITIONS = [] + DEFINITIONS_PRIVATE = [] + LDFLAGS = [] + LINK_SEARCH_PATH = [] _INCLUDE, _SRCS = get_sqlite3_lib() INCLUDE += _INCLUDE SRCS += _SRCS - env['COMPONENTS'].append({'target':os.path.basename(env['component_dir']), - 'SRCS':SRCS, - 'INCLUDE':INCLUDE, - 'PRIVATE_INCLUDE':PRIVATE_INCLUDE, - 'REQUIREMENTS':REQUIREMENTS, - 'STATIC_LIB':STATIC_LIB, - 'DYNAMIC_LIB':DYNAMIC_LIB, - 'DEFINITIONS':DEFINITIONS, - 'DEFINITIONS_PRIVATE':DEFINITIONS_PRIVATE, - 'LDFLAGS':LDFLAGS, - 'LINK_SEARCH_PATH':LINK_SEARCH_PATH, - 'REGISTER':'static' - }) + env["COMPONENTS"].append( + { + "target": os.path.basename(env["component_dir"]), + "SRCS": SRCS, + "INCLUDE": INCLUDE, + "PRIVATE_INCLUDE": PRIVATE_INCLUDE, + "REQUIREMENTS": REQUIREMENTS, + "STATIC_LIB": STATIC_LIB, + "DYNAMIC_LIB": DYNAMIC_LIB, + "DEFINITIONS": DEFINITIONS, + "DEFINITIONS_PRIVATE": DEFINITIONS_PRIVATE, + "LDFLAGS": LDFLAGS, + "LINK_SEARCH_PATH": LINK_SEARCH_PATH, + "REGISTER": "static", + } + ) diff --git a/components/static_package/SConstruct b/components/static_package/SConstruct index 46d78b4..e16b726 100644 --- a/components/static_package/SConstruct +++ b/components/static_package/SConstruct @@ -1,198 +1,189 @@ # component2/SConscript -Import('env') +Import("env") import os -with open(env['PROJECT_TOOL_S']) as f: + +with open(env["PROJECT_TOOL_S"]) as f: exec(f.read()) def get_opencv_from_axera(): - opencv_path = str(ADir('../../github_source/opencv-arm-linux')) - if not os.path.exists(opencv_path): - zip_file = str(AFile('../../github_source/opencv-arm-linux-gnueabihf-gcc-7.5.0.zip')) - zip_file_extrpath = opencv_path + '_tmp' - down_url = "https://github.com/AXERA-TECH/ax-samples/releases/download/v0.1/opencv-arm-linux-gnueabihf-gcc-7.5.0.zip" - - if 'CONFIG_REPO_AUTOMATION' in os.environ: - down = 'y' - else: - down = input('{} does not exist. Please choose whether to download it automatically? Y/N :'.format('opencv-mobile-2.4.13.7-armlinux')) - down = down.lower() - if down == 'y': - # from git import Repo - import requests - import parse - import zipfile - import shutil - try: - # Downloading via HTTP (more common) - if not os.path.exists(zip_file): - response = requests.get(down_url) - if response.status_code == 200: - with open(zip_file, 'wb') as file: - file.write(response.content) - else: - env.Fatal("{} down failed".format(down_url)) - with zipfile.ZipFile(zip_file, 'r') as zip_ref: - zip_ref.extractall(zip_file_extrpath) - shutil.move(os.path.join(zip_file_extrpath, 'opencv-arm-linux'), opencv_path) - shutil.rmtree(zip_file_extrpath) - print("The {} download successful.".format(down_url)) - except Exception as e: - print('Please manually download {} to {} .'.format(down_url, zip_file)) - env.Fatal("Cloning failed.: {}".format(e)) - else: - env.Fatal('Please manually download {} to {} .'.format(down_url, zip_file)) - INCLUDE = [os.path.join(opencv_path, 'include/opencv4')] - STATIC_LIB = AGlob(os.path.join('../../github_source/opencv-arm-linux', 'lib/*.a')) - STATIC_LIB += AGlob(os.path.join('../../github_source/opencv-arm-linux', 'lib/opencv4/3rdparty/*.a')) + opencv_path = check_wget_down( + "https://github.com/AXERA-TECH/ax-samples/releases/download/v0.1/opencv-arm-linux-gnueabihf-gcc-7.5.0.zip", + "opencv-arm-linux-gnueabihf-gcc-7.5.0.zip", + ) + INCLUDE = [os.path.join(opencv_path, "opencv-arm-linux/include/opencv4")] + STATIC_LIB = AGlob(os.path.join(opencv_path, "opencv-arm-linux/lib/*.a")) + STATIC_LIB += AGlob( + os.path.join(opencv_path, "opencv-arm-linux/lib/opencv4/3rdparty/*.a") + ) return INCLUDE, STATIC_LIB + def get_opencv_from_ncnn(): - opencv_path = str(ADir('../../github_source/opencv-mobile-2.4.13.7-armlinux')) - if not os.path.exists(opencv_path): - zip_file = opencv_path + '.zip' - zip_file_extrpath = opencv_path + '_tmp' - down_url = "https://github.com/nihui/opencv-mobile/releases/download/v26/opencv-mobile-2.4.13.7-armlinux.zip" - - if 'CONFIG_REPO_AUTOMATION' in os.environ: - down = 'y' - else: - down = input('{} does not exist. Please choose whether to download it automatically? Y/N :'.format('opencv-mobile-2.4.13.7-armlinux')) - down = down.lower() - if down == 'y': - # from git import Repo - import requests - import parse - import zipfile - import shutil - try: - # Downloading via HTTP (more common) - if not os.path.exists(zip_file): - response = requests.get(down_url) - if response.status_code == 200: - with open(zip_file, 'wb') as file: - file.write(response.content) - else: - env.Fatal("{} down failed".format(down_url)) - with zipfile.ZipFile(zip_file, 'r') as zip_ref: - zip_ref.extractall(zip_file_extrpath) - shutil.move(os.path.join(zip_file_extrpath, 'opencv-mobile-2.4.13.7-armlinux'), opencv_path) - shutil.rmtree(zip_file_extrpath) - print("The {} download successful.".format(down_url)) - except Exception as e: - print('Please manually download {} to {} .'.format(down_url, zip_file)) - env.Fatal("Cloning failed.: {}".format(e)) - else: - env.Fatal('Please manually download {} to {} .'.format(down_url, zip_file)) - - gcc_dumpmachine = env['GCC_DUMPMACHINE'] - INCLUDE = [os.path.join(opencv_path, gcc_dumpmachine, 'include')] - STATIC_LIB = AGlob(os.path.join('../../github_source/opencv-mobile-2.4.13.7-armlinux', gcc_dumpmachine, 'lib/*.a')) + opencv_path = str(ADir("../../github_source/opencv-mobile-2.4.13.7-armlinux")) + opencv_path = check_wget_down( + "https://github.com/nihui/opencv-mobile/releases/download/v26/opencv-mobile-2.4.13.7-armlinux.zip", + "opencv-mobile-2.4.13.7-armlinux.zip", + ) + gcc_dumpmachine = env["GCC_DUMPMACHINE"] + INCLUDE = [os.path.join(opencv_path, gcc_dumpmachine, "include")] + STATIC_LIB = AGlob( + os.path.join( + "../../github_source/opencv-mobile-2.4.13.7-armlinux", + gcc_dumpmachine, + "lib/*.a", + ) + ) return INCLUDE, STATIC_LIB + def get_grpc_from_m5stack(): - grpc_name = "grpc-1.65.0-pre1" - grpc_path = str(ADir('../../github_source/grpc-1.65.0-pre1')) - if not os.path.exists(grpc_path): - zip_file = grpc_path + '.zip' - zip_file_extrpath = grpc_path - down_url = "https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/linux/linux_static_packages/grpc-1.65.0-pre1.zip" - - if 'CONFIG_REPO_AUTOMATION' in os.environ: - down = 'y' - else: - down = input('{} does not exist. Please choose whether to download it automatically? Y/N :'.format(grpc_name)) - down = down.lower() - if down == 'y': - # from git import Repo - import requests - import parse - import zipfile - import shutil - try: - # Downloading via HTTP (more common) - if not os.path.exists(zip_file): - response = requests.get(down_url) - if response.status_code == 200: - with open(zip_file, 'wb') as file: - file.write(response.content) - else: - env.Fatal("{} down failed".format(down_url)) - with zipfile.ZipFile(zip_file, 'r') as zip_ref: - zip_ref.extractall(zip_file_extrpath) - print("The {} download successful.".format(down_url)) - except Exception as e: - print('Please manually download {} to {} .'.format(down_url, zip_file)) - env.Fatal("Cloning failed.: {}".format(e)) - else: - env.Fatal('Please manually download {} to {} .'.format(down_url, zip_file)) + grpc_path = check_wget_down( + "https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/linux/linux_static_packages/grpc-1.65.0-pre1.zip", + "grpc-1.65.0-pre1.zip", + ) return grpc_path -if 'CONFIG_STATIC_PACKAGE_ENABLED' in os.environ: - SRCS=[] - INCLUDE=[] - PRIVATE_INCLUDE=[] - REQUIREMENTS=[] - STATIC_LIB=[] - DYNAMIC_LIB=[] - DEFINITIONS=[] - DEFINITIONS_PRIVATE=[] - LDFLAGS=[] - LINK_SEARCH_PATH=[] +if "CONFIG_STATIC_PACKAGE_ENABLED" in os.environ: + SRCS = [] + INCLUDE = [] + PRIVATE_INCLUDE = [] + REQUIREMENTS = [] + STATIC_LIB = [] + DYNAMIC_LIB = [] + DEFINITIONS = [] + DEFINITIONS_PRIVATE = [] + LDFLAGS = [] + LINK_SEARCH_PATH = [] - if 'CONFIG_OPENCV_LIB_AXERA_ENABLED' in os.environ: + if "CONFIG_OPENCV_LIB_AXERA_ENABLED" in os.environ: inc, slib = get_opencv_from_axera() INCLUDE += inc STATIC_LIB += slib + slib - if 'CONFIG_OPENCV_LIB_NCNN_ENABLED' in os.environ: + if "CONFIG_OPENCV_LIB_NCNN_ENABLED" in os.environ: inc, slib = get_opencv_from_ncnn() INCLUDE += inc STATIC_LIB += slib + slib - if 'CONFIG_GRPC_LIB_ENABLED' in os.environ: + if "CONFIG_GRPC_LIB_ENABLED" in os.environ: grpc_path = get_grpc_from_m5stack() - gcc_dumpmachine = env['GCC_DUMPMACHINE'] - DEFINITIONS = ['-DEFINITIONS', '-DNOMINMAX'] - INCLUDE = [os.path.join(grpc_path, gcc_dumpmachine, 'include')] - LINK_SEARCH_PATH = [os.path.join(grpc_path, gcc_dumpmachine, 'lib')] - LDFLAGS = ['-l:libgrpc++.a', '-l:libgrpc.a', '-l:libgpr.a', '-l:libabsl_random_distributions.a', '-l:libabsl_random_seed_sequences.a', - '-l:libabsl_random_internal_pool_urbg.a', '-l:libabsl_random_internal_randen.a', '-l:libabsl_random_internal_randen_hwaes.a', - '-l:libabsl_random_internal_randen_hwaes_impl.a', '-l:libabsl_random_internal_randen_slow.a', '-l:libabsl_random_internal_platform.a', - '-l:libabsl_random_internal_seed_material.a', '-l:libabsl_random_seed_gen_exception.a', - '-l:libprotobuf.a', '-l:libabsl_log_internal_check_op.a', '-l:libabsl_leak_check.a', '-l:libabsl_die_if_null.a', - '-l:libabsl_log_internal_conditions.a', '-l:libabsl_log_internal_message.a', '-l:libabsl_examine_stack.a', - '-l:libabsl_log_internal_format.a', '-l:libabsl_log_internal_proto.a', '-l:libabsl_log_internal_nullguard.a', - '-l:libabsl_log_internal_log_sink_set.a', '-l:libabsl_log_sink.a', '-l:libabsl_log_entry.a', - '-l:libabsl_flags_internal.a', '-l:libabsl_flags_marshalling.a', '-l:libabsl_flags_reflection.a', - '-l:libabsl_flags_private_handle_accessor.a', '-l:libabsl_flags_commandlineflag.a', '-l:libabsl_flags_commandlineflag_internal.a', - '-l:libabsl_flags_config.a', '-l:libabsl_flags_program_name.a', '-l:libabsl_log_initialize.a', '-l:libabsl_log_globals.a', - '-l:libabsl_vlog_config_internal.a', '-l:libabsl_log_internal_fnmatch.a', '-l:libabsl_log_internal_globals.a', - '-l:libabsl_raw_hash_set.a', '-l:libabsl_hash.a', '-l:libabsl_city.a', '-l:libabsl_low_level_hash.a', '-l:libabsl_hashtablez_sampler.a', - '-l:libabsl_statusor.a', '-l:libabsl_status.a', '-l:libabsl_cord.a', '-l:libabsl_cordz_info.a', '-l:libabsl_cord_internal.a', - '-l:libabsl_cordz_functions.a', '-l:libabsl_exponential_biased.a', '-l:libabsl_cordz_handle.a', '-l:libabsl_crc_cord_state.a', - '-l:libabsl_crc32c.a', '-l:libabsl_crc_internal.a', '-l:libabsl_crc_cpu_detect.a', '-l:libabsl_bad_optional_access.a', - '-l:libabsl_strerror.a', '-l:libabsl_str_format_internal.a', '-l:libabsl_synchronization.a', '-l:libabsl_graphcycles_internal.a', - '-l:libabsl_kernel_timeout_internal.a', '-l:libabsl_stacktrace.a', '-l:libabsl_symbolize.a', '-l:libabsl_debugging_internal.a', - '-l:libabsl_demangle_internal.a', '-l:libabsl_malloc_internal.a', '-l:libabsl_time.a', '-l:libabsl_civil_time.a', - '-l:libabsl_time_zone.a', '-l:libabsl_bad_variant_access.a', '-l:libutf8_validity.a', '-l:libutf8_range.a', - '-l:libabsl_strings.a', '-l:libabsl_strings_internal.a', '-l:libabsl_string_view.a', '-l:libabsl_base.a', '-l:librt.a', - '-l:libabsl_spinlock_wait.a', '-l:libabsl_int128.a', '-l:libabsl_throw_delegate.a', '-l:libabsl_raw_logging_internal.a', - '-l:libabsl_log_severity.a', '-l:libssl.a', '-l:libcrypto.a', '-l:libre2.a', '-l:libgrpc_authorization_provider.a', - '-l:libupb_message_lib.a', '-l:libupb_mem_lib.a', '-l:libcares.a', '-l:libaddress_sorting.a', '-l:libupb_json_lib.a', - '-l:libupb_base_lib.a', '-l:libupb_textformat_lib.a', '-l:libz.a' ] - - env['COMPONENTS'].append({'target':os.path.basename(env['component_dir']), - 'SRCS':SRCS, - 'INCLUDE':INCLUDE, - 'PRIVATE_INCLUDE':PRIVATE_INCLUDE, - 'REQUIREMENTS':REQUIREMENTS, - 'STATIC_LIB':STATIC_LIB, - 'DYNAMIC_LIB':DYNAMIC_LIB, - 'DEFINITIONS':DEFINITIONS, - 'DEFINITIONS_PRIVATE':DEFINITIONS_PRIVATE, - 'LDFLAGS':LDFLAGS, - 'LINK_SEARCH_PATH':LINK_SEARCH_PATH, - 'REGISTER':'static' - }) + gcc_dumpmachine = env["GCC_DUMPMACHINE"] + DEFINITIONS = ["-DEFINITIONS", "-DNOMINMAX"] + INCLUDE = [os.path.join(grpc_path, gcc_dumpmachine, "include")] + LINK_SEARCH_PATH = [os.path.join(grpc_path, gcc_dumpmachine, "lib")] + LDFLAGS = [ + "-l:libgrpc++.a", + "-l:libgrpc.a", + "-l:libgpr.a", + "-l:libabsl_random_distributions.a", + "-l:libabsl_random_seed_sequences.a", + "-l:libabsl_random_internal_pool_urbg.a", + "-l:libabsl_random_internal_randen.a", + "-l:libabsl_random_internal_randen_hwaes.a", + "-l:libabsl_random_internal_randen_hwaes_impl.a", + "-l:libabsl_random_internal_randen_slow.a", + "-l:libabsl_random_internal_platform.a", + "-l:libabsl_random_internal_seed_material.a", + "-l:libabsl_random_seed_gen_exception.a", + "-l:libprotobuf.a", + "-l:libabsl_log_internal_check_op.a", + "-l:libabsl_leak_check.a", + "-l:libabsl_die_if_null.a", + "-l:libabsl_log_internal_conditions.a", + "-l:libabsl_log_internal_message.a", + "-l:libabsl_examine_stack.a", + "-l:libabsl_log_internal_format.a", + "-l:libabsl_log_internal_proto.a", + "-l:libabsl_log_internal_nullguard.a", + "-l:libabsl_log_internal_log_sink_set.a", + "-l:libabsl_log_sink.a", + "-l:libabsl_log_entry.a", + "-l:libabsl_flags_internal.a", + "-l:libabsl_flags_marshalling.a", + "-l:libabsl_flags_reflection.a", + "-l:libabsl_flags_private_handle_accessor.a", + "-l:libabsl_flags_commandlineflag.a", + "-l:libabsl_flags_commandlineflag_internal.a", + "-l:libabsl_flags_config.a", + "-l:libabsl_flags_program_name.a", + "-l:libabsl_log_initialize.a", + "-l:libabsl_log_globals.a", + "-l:libabsl_vlog_config_internal.a", + "-l:libabsl_log_internal_fnmatch.a", + "-l:libabsl_log_internal_globals.a", + "-l:libabsl_raw_hash_set.a", + "-l:libabsl_hash.a", + "-l:libabsl_city.a", + "-l:libabsl_low_level_hash.a", + "-l:libabsl_hashtablez_sampler.a", + "-l:libabsl_statusor.a", + "-l:libabsl_status.a", + "-l:libabsl_cord.a", + "-l:libabsl_cordz_info.a", + "-l:libabsl_cord_internal.a", + "-l:libabsl_cordz_functions.a", + "-l:libabsl_exponential_biased.a", + "-l:libabsl_cordz_handle.a", + "-l:libabsl_crc_cord_state.a", + "-l:libabsl_crc32c.a", + "-l:libabsl_crc_internal.a", + "-l:libabsl_crc_cpu_detect.a", + "-l:libabsl_bad_optional_access.a", + "-l:libabsl_strerror.a", + "-l:libabsl_str_format_internal.a", + "-l:libabsl_synchronization.a", + "-l:libabsl_graphcycles_internal.a", + "-l:libabsl_kernel_timeout_internal.a", + "-l:libabsl_stacktrace.a", + "-l:libabsl_symbolize.a", + "-l:libabsl_debugging_internal.a", + "-l:libabsl_demangle_internal.a", + "-l:libabsl_malloc_internal.a", + "-l:libabsl_time.a", + "-l:libabsl_civil_time.a", + "-l:libabsl_time_zone.a", + "-l:libabsl_bad_variant_access.a", + "-l:libutf8_validity.a", + "-l:libutf8_range.a", + "-l:libabsl_strings.a", + "-l:libabsl_strings_internal.a", + "-l:libabsl_string_view.a", + "-l:libabsl_base.a", + "-l:librt.a", + "-l:libabsl_spinlock_wait.a", + "-l:libabsl_int128.a", + "-l:libabsl_throw_delegate.a", + "-l:libabsl_raw_logging_internal.a", + "-l:libabsl_log_severity.a", + "-l:libssl.a", + "-l:libcrypto.a", + "-l:libre2.a", + "-l:libgrpc_authorization_provider.a", + "-l:libupb_message_lib.a", + "-l:libupb_mem_lib.a", + "-l:libcares.a", + "-l:libaddress_sorting.a", + "-l:libupb_json_lib.a", + "-l:libupb_base_lib.a", + "-l:libupb_textformat_lib.a", + "-l:libz.a", + ] + + env["COMPONENTS"].append( + { + "target": os.path.basename(env["component_dir"]), + "SRCS": SRCS, + "INCLUDE": INCLUDE, + "PRIVATE_INCLUDE": PRIVATE_INCLUDE, + "REQUIREMENTS": REQUIREMENTS, + "STATIC_LIB": STATIC_LIB, + "DYNAMIC_LIB": DYNAMIC_LIB, + "DEFINITIONS": DEFINITIONS, + "DEFINITIONS_PRIVATE": DEFINITIONS_PRIVATE, + "LDFLAGS": LDFLAGS, + "LINK_SEARCH_PATH": LINK_SEARCH_PATH, + "REGISTER": "static", + } + ) diff --git a/examples/firebird_demo/config_defaults.mk b/examples/firebird_demo/config_defaults.mk index 69cf956..de34167 100644 --- a/examples/firebird_demo/config_defaults.mk +++ b/examples/firebird_demo/config_defaults.mk @@ -1,4 +1,4 @@ -# CONFIG_TOOLCHAIN_PATH="/opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin" +CONFIG_TOOLCHAIN_PATH="/opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin" # CONFIG_COMPONENT1_ENABLED=y CONFIG_TOOLCHAIN_PREFIX="arm-linux-gnueabihf-" CONFIG_TOMMATH_ENABLED=y diff --git a/examples/firebird_demo/main/SConstruct b/examples/firebird_demo/main/SConstruct index 8a9380d..7883028 100644 --- a/examples/firebird_demo/main/SConstruct +++ b/examples/firebird_demo/main/SConstruct @@ -1,15 +1,16 @@ # project_root/src/SConscript import os import shutil + # Import the environment from the SConstruct file -Import('env') -with open(env['PROJECT_TOOL_S']) as f: +Import("env") +with open(env["PROJECT_TOOL_S"]) as f: exec(f.read()) -SRCS = Glob('src/*.c*') -INCLUDE = [ADir('include'), ADir('.')] +SRCS = Glob("src/*.c*") +INCLUDE = [ADir("include"), ADir(".")] PRIVATE_INCLUDE = [] -REQUIREMENTS = ['pthread','tommath'] +REQUIREMENTS = ["pthread", "tommath"] STATIC_LIB = [] DYNAMIC_LIB = [] DEFINITIONS = [] @@ -17,68 +18,63 @@ DEFINITIONS_PRIVATE = [] LDFLAGS = [] LINK_SEARCH_PATH = [] -gcc_dumpmachine = env['GCC_DUMPMACHINE'].split('-') +gcc_dumpmachine = env["GCC_DUMPMACHINE"].split("-") -if 'arm' in gcc_dumpmachine and 'gnueabihf' in gcc_dumpmachine: - package_name = 'Firebird-5.0.0.1306-0-linux-arm32' - Firebird_path = str(ADir('../../../github_source/Firebird-5.0.0.1306-0-linux-arm32')) +if "arm" in gcc_dumpmachine and "gnueabihf" in gcc_dumpmachine: + package_name = "Firebird-5.0.0.1306-0-linux-arm32" + Firebird_path = str( + ADir("../../../github_source/Firebird-5.0.0.1306-0-linux-arm32") + ) down_url = "https://github.com/FirebirdSQL/firebird/releases/download/v5.0.0/Firebird-5.0.0.1306-0-linux-arm32.tar.gz" - INCLUDE.append(ADir('../../../github_source/Firebird-5.0.0.1306-0-linux-arm32/Firebird-5.0.0.1306-0-linux-arm32/buildroot/opt/firebird/include')) - DYNAMIC_LIB.append(AFile('../../../github_source/Firebird-5.0.0.1306-0-linux-arm32/Firebird-5.0.0.1306-0-linux-arm32/buildroot/opt/firebird/lib/libfbclient.so.2')) -elif 'x86_64' in gcc_dumpmachine and 'linux' in gcc_dumpmachine: - Firebird_path = str(ADir('../../../github_source/Firebird-5.0.0.1306-0-linux-x64')) + INCLUDE.append( + ADir( + "../../../github_source/Firebird-5.0.0.1306-0-linux-arm32/Firebird-5.0.0.1306-0-linux-arm32/buildroot/opt/firebird/include" + ) + ) + DYNAMIC_LIB.append( + AFile( + "../../../github_source/Firebird-5.0.0.1306-0-linux-arm32/Firebird-5.0.0.1306-0-linux-arm32/buildroot/opt/firebird/lib/libfbclient.so.2" + ) + ) +elif "x86_64" in gcc_dumpmachine and "linux" in gcc_dumpmachine: + Firebird_path = str(ADir("../../../github_source/Firebird-5.0.0.1306-0-linux-x64")) down_url = "https://github.com/FirebirdSQL/firebird/releases/download/v5.0.0/Firebird-5.0.0.1306-0-linux-x64.tar.gz" - package_name = 'Firebird-5.0.0.1306-0-linux-x64' - INCLUDE.append(os.path.join(str(Firebird_path),package_name, 'buildroot/opt/firebird/include')) - DYNAMIC_LIB.append(os.path.join(str(Firebird_path),package_name, 'buildroot/opt/firebird/lib/libfbclient.so.2')) + package_name = "Firebird-5.0.0.1306-0-linux-x64" + INCLUDE.append( + os.path.join(str(Firebird_path), package_name, "buildroot/opt/firebird/include") + ) + DYNAMIC_LIB.append( + os.path.join( + str(Firebird_path), + package_name, + "buildroot/opt/firebird/lib/libfbclient.so.2", + ) + ) +Firebird_path = check_wget_down( + down_url, + package_name + ".tar.gz", +) +Firebird_buildroot = os.path.join(Firebird_path, package_name, "buildroot") +if not os.path.exists(Firebird_buildroot): + import tarfile -if not os.path.exists(Firebird_path): - zip_file = Firebird_path + '.tar.gz' - zip_file_extrpath = Firebird_path - - if 'CONFIG_REPO_AUTOMATION' in os.environ: - down = 'y' - else: - down = input('{} does not exist. Please choose whether to download it automatically? Y/N :'.format(package_name)) - down = down.lower() - if down == 'y': - # from git import Repo - import requests - import parse - import tarfile - import shutil - try: - # Downloading via HTTP (more common) - if not os.path.exists(zip_file): - response = requests.get(down_url) - if response.status_code == 200: - with open(zip_file, 'wb') as file: - file.write(response.content) - else: - env.Fatal("{} down failed".format(down_url)) - with tarfile.open(zip_file, 'r:gz') as tar: - tar.extractall(zip_file_extrpath) - with tarfile.open(os.path.join(zip_file_extrpath, package_name, 'buildroot.tar.gz'), 'r:gz') as tar: - tar.extractall(os.path.join(zip_file_extrpath, package_name, 'buildroot')) - print("The {} download successful.".format(down_url)) - except Exception as e: - print('Please manually download {} to {} .'.format(down_url, zip_file)) - env.Fatal("Cloning failed.: {}".format(e)) - else: - env.Fatal('Please manually download {} to {} .'.format(down_url, zip_file)) + with tarfile.open(Firebird_buildroot + ".tar.gz", "r:gz") as tar: + tar.extractall(Firebird_buildroot) - -env['COMPONENTS'].append({'target':env['PROJECT_NAME'], - 'SRCS':SRCS, - 'INCLUDE':INCLUDE, - 'PRIVATE_INCLUDE':PRIVATE_INCLUDE, - 'REQUIREMENTS':REQUIREMENTS, - 'STATIC_LIB':STATIC_LIB, - 'DYNAMIC_LIB':DYNAMIC_LIB, - 'DEFINITIONS':DEFINITIONS, - 'DEFINITIONS_PRIVATE':DEFINITIONS_PRIVATE, - 'LDFLAGS':LDFLAGS, - 'LINK_SEARCH_PATH':LINK_SEARCH_PATH, - 'REGISTER':'project' - }) \ No newline at end of file +env["COMPONENTS"].append( + { + "target": env["PROJECT_NAME"], + "SRCS": SRCS, + "INCLUDE": INCLUDE, + "PRIVATE_INCLUDE": PRIVATE_INCLUDE, + "REQUIREMENTS": REQUIREMENTS, + "STATIC_LIB": STATIC_LIB, + "DYNAMIC_LIB": DYNAMIC_LIB, + "DEFINITIONS": DEFINITIONS, + "DEFINITIONS_PRIVATE": DEFINITIONS_PRIVATE, + "LDFLAGS": LDFLAGS, + "LINK_SEARCH_PATH": LINK_SEARCH_PATH, + "REGISTER": "project", + } +) diff --git a/examples/firebird_demo/main_firebird/SConstruct b/examples/firebird_demo/main_firebird/SConstruct index db6ae31..c7cef4f 100644 --- a/examples/firebird_demo/main_firebird/SConstruct +++ b/examples/firebird_demo/main_firebird/SConstruct @@ -1,91 +1,88 @@ # project_root/src/SConscript import os import shutil + # Import the environment from the SConstruct file -Import('env') -with open(env['PROJECT_TOOL_S']) as f: +Import("env") +with open(env["PROJECT_TOOL_S"]) as f: exec(f.read()) # The GCC version needs to be greater than or equal to 8. -gcc_dumpversion = CC_cmd_execute('-dumpversion') -if int(gcc_dumpversion.split('.')[0]) >= 8: - check_component('firebird') +gcc_dumpversion = CC_cmd_execute("-dumpversion") +if int(gcc_dumpversion.split(".")[0]) >= 8: + check_component("firebird") - SRCS = Glob('src/*.c*') - INCLUDE = [ADir('include'), ADir('.')] + SRCS = Glob("src/*.c*") + INCLUDE = [ADir("include"), ADir(".")] PRIVATE_INCLUDE = [] - REQUIREMENTS = ['pthread','tommath'] + REQUIREMENTS = ["pthread", "tommath"] STATIC_LIB = [] DYNAMIC_LIB = [] - DEFINITIONS = ['--std=c++17'] + DEFINITIONS = ["--std=c++17"] DEFINITIONS_PRIVATE = [] LDFLAGS = [] LINK_SEARCH_PATH = [] - INCLUDE.append(ADir('../../../github_source/firebird/single')) - - gcc_dumpmachine = env['GCC_DUMPMACHINE'].split('-') - - if 'arm' in gcc_dumpmachine and 'gnueabihf' in gcc_dumpmachine: - package_name = 'Firebird-5.0.0.1306-0-linux-arm32' - Firebird_path = str(ADir('../../../github_source/Firebird-5.0.0.1306-0-linux-arm32')) + INCLUDE.append(ADir("../../../github_source/firebird/single")) + gcc_dumpmachine = env["GCC_DUMPMACHINE"].split("-") + if "arm" in gcc_dumpmachine and "gnueabihf" in gcc_dumpmachine: + package_name = "Firebird-5.0.0.1306-0-linux-arm32" + Firebird_path = str( + ADir("../../../github_source/Firebird-5.0.0.1306-0-linux-arm32") + ) down_url = "https://github.com/FirebirdSQL/firebird/releases/download/v5.0.0/Firebird-5.0.0.1306-0-linux-arm32.tar.gz" - INCLUDE.append(ADir('../../../github_source/Firebird-5.0.0.1306-0-linux-arm32/Firebird-5.0.0.1306-0-linux-arm32/buildroot/opt/firebird/include')) - DYNAMIC_LIB.append(AFile('../../../github_source/Firebird-5.0.0.1306-0-linux-arm32/Firebird-5.0.0.1306-0-linux-arm32/buildroot/opt/firebird/lib/libfbclient.so.2')) - elif 'x86_64' in gcc_dumpmachine and 'linux' in gcc_dumpmachine: - Firebird_path = str(ADir('../../../github_source/Firebird-5.0.0.1306-0-linux-x64')) + INCLUDE.append( + ADir( + "../../../github_source/Firebird-5.0.0.1306-0-linux-arm32/Firebird-5.0.0.1306-0-linux-arm32/buildroot/opt/firebird/include" + ) + ) + DYNAMIC_LIB.append( + AFile( + "../../../github_source/Firebird-5.0.0.1306-0-linux-arm32/Firebird-5.0.0.1306-0-linux-arm32/buildroot/opt/firebird/lib/libfbclient.so.2" + ) + ) + elif "x86_64" in gcc_dumpmachine and "linux" in gcc_dumpmachine: + Firebird_path = str( + ADir("../../../github_source/Firebird-5.0.0.1306-0-linux-x64") + ) down_url = "https://github.com/FirebirdSQL/firebird/releases/download/v5.0.0/Firebird-5.0.0.1306-0-linux-x64.tar.gz" - package_name = 'Firebird-5.0.0.1306-0-linux-x64' - INCLUDE.append(os.path.join(str(Firebird_path),package_name, 'buildroot/opt/firebird/include')) - DYNAMIC_LIB.append(os.path.join(str(Firebird_path),package_name, 'buildroot/opt/firebird/lib/libfbclient.so.2')) + package_name = "Firebird-5.0.0.1306-0-linux-x64" + INCLUDE.append( + os.path.join( + str(Firebird_path), package_name, "buildroot/opt/firebird/include" + ) + ) + DYNAMIC_LIB.append( + os.path.join( + str(Firebird_path), + package_name, + "buildroot/opt/firebird/lib/libfbclient.so.2", + ) + ) + Firebird_path = check_wget_down( + down_url, + package_name + ".tar.gz", + ) + Firebird_buildroot = os.path.join(Firebird_path, package_name, "buildroot") + if not os.path.exists(Firebird_buildroot): + import tarfile + with tarfile.open(Firebird_buildroot + ".tar.gz", "r:gz") as tar: + tar.extractall(Firebird_buildroot) - if not os.path.exists(Firebird_path): - zip_file = Firebird_path + '.tar.gz' - zip_file_extrpath = Firebird_path - - if 'CONFIG_REPO_AUTOMATION' in os.environ: - down = 'y' - else: - down = input('{} does not exist. Please choose whether to download it automatically? Y/N :'.format(package_name)) - down = down.lower() - if down == 'y': - # from git import Repo - import requests - import parse - import tarfile - import shutil - try: - # Downloading via HTTP (more common) - if not os.path.exists(zip_file): - response = requests.get(down_url) - if response.status_code == 200: - with open(zip_file, 'wb') as file: - file.write(response.content) - else: - env.Fatal("{} down failed".format(down_url)) - with tarfile.open(zip_file, 'r:gz') as tar: - tar.extractall(zip_file_extrpath) - with tarfile.open(os.path.join(zip_file_extrpath, package_name, 'buildroot.tar.gz'), 'r:gz') as tar: - tar.extractall(os.path.join(zip_file_extrpath, package_name, 'buildroot')) - print("The {} download successful.".format(down_url)) - except Exception as e: - print('Please manually download {} to {} .'.format(down_url, zip_file)) - env.Fatal("Cloning failed.: {}".format(e)) - else: - env.Fatal('Please manually download {} to {} .'.format(down_url, zip_file)) - - - env['COMPONENTS'].append({'target':'cpp_firebird_demo', - 'SRCS':SRCS, - 'INCLUDE':INCLUDE, - 'PRIVATE_INCLUDE':PRIVATE_INCLUDE, - 'REQUIREMENTS':REQUIREMENTS, - 'STATIC_LIB':STATIC_LIB, - 'DYNAMIC_LIB':DYNAMIC_LIB, - 'DEFINITIONS':DEFINITIONS, - 'DEFINITIONS_PRIVATE':DEFINITIONS_PRIVATE, - 'LDFLAGS':LDFLAGS, - 'LINK_SEARCH_PATH':LINK_SEARCH_PATH, - 'REGISTER':'project' - }) \ No newline at end of file + env["COMPONENTS"].append( + { + "target": "cpp_firebird_demo", + "SRCS": SRCS, + "INCLUDE": INCLUDE, + "PRIVATE_INCLUDE": PRIVATE_INCLUDE, + "REQUIREMENTS": REQUIREMENTS, + "STATIC_LIB": STATIC_LIB, + "DYNAMIC_LIB": DYNAMIC_LIB, + "DEFINITIONS": DEFINITIONS, + "DEFINITIONS_PRIVATE": DEFINITIONS_PRIVATE, + "LDFLAGS": LDFLAGS, + "LINK_SEARCH_PATH": LINK_SEARCH_PATH, + "REGISTER": "project", + } + ) diff --git a/examples/framebuffer_OpenCV/config_defaults.mk b/examples/framebuffer_OpenCV/config_defaults.mk index 24d7c3f..455faac 100644 --- a/examples/framebuffer_OpenCV/config_defaults.mk +++ b/examples/framebuffer_OpenCV/config_defaults.mk @@ -1,5 +1,5 @@ # unix -# CONFIG_TOOLCHAIN_PATH="/opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin" +CONFIG_TOOLCHAIN_PATH="/opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin" # win # CONFIG_TOOLCHAIN_PATH="..\\gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf\\bin" diff --git a/examples/grpc_demo/config_defaults.mk b/examples/grpc_demo/config_defaults.mk index fcaba7c..54a10cc 100644 --- a/examples/grpc_demo/config_defaults.mk +++ b/examples/grpc_demo/config_defaults.mk @@ -1,6 +1,6 @@ # CONFIG_COMPONENT1_ENABLED=y -# CONFIG_TOOLCHAIN_PATH="/opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin" +CONFIG_TOOLCHAIN_PATH="/opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin" CONFIG_TOOLCHAIN_PREFIX="arm-linux-gnueabihf-" CONFIG_STATIC_PACKAGE_ENABLED=y CONFIG_GRPC_LIB_ENABLED=y \ No newline at end of file diff --git a/examples/simdjson_demo/.gitignore b/examples/simdjson_demo/.gitignore new file mode 100644 index 0000000..76b743d --- /dev/null +++ b/examples/simdjson_demo/.gitignore @@ -0,0 +1,6 @@ + +dist +build +.config.mk +.flash.conf.json + diff --git a/examples/simdjson_demo/SConstruct b/examples/simdjson_demo/SConstruct new file mode 100644 index 0000000..076d65c --- /dev/null +++ b/examples/simdjson_demo/SConstruct @@ -0,0 +1,4 @@ +from pathlib import Path +import os +with open(str(Path(os.getcwd())/'..'/'..'/'tools'/'scons'/'project.py')) as f: + exec(f.read()) diff --git a/examples/simdjson_demo/config_defaults.mk b/examples/simdjson_demo/config_defaults.mk new file mode 100644 index 0000000..15fcb5d --- /dev/null +++ b/examples/simdjson_demo/config_defaults.mk @@ -0,0 +1,3 @@ +# CONFIG_TOOLCHAIN_PATH="/opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin" +# CONFIG_TOOLCHAIN_PREFIX="arm-linux-gnueabihf-" +CONFIG_SIMDJSON_COMPENENT_ENABLED=y diff --git a/examples/simdjson_demo/main/Kconfig b/examples/simdjson_demo/main/Kconfig new file mode 100644 index 0000000..e69de29 diff --git a/examples/simdjson_demo/main/SConstruct b/examples/simdjson_demo/main/SConstruct new file mode 100644 index 0000000..4d3aace --- /dev/null +++ b/examples/simdjson_demo/main/SConstruct @@ -0,0 +1,42 @@ +# project_root/src/SConscript +import os +# Import the environment from the SConstruct file +Import('env') +with open(env['PROJECT_TOOL_S']) as f: + exec(f.read()) + +SRCS = [] +INCLUDE = [ADir('include'), ADir('.')] +PRIVATE_INCLUDE = [] +REQUIREMENTS = ['simdjson_component', 'pthread'] +STATIC_LIB = [] +DYNAMIC_LIB = [] +DEFINITIONS = [] +DEFINITIONS_PRIVATE = [] +LDFLAGS = [] +LINK_SEARCH_PATH = [] + +LDFLAGS += ['-Wl,-rpath=./'] + +all_src_files = Glob('src/*.c*') + +for src in all_src_files: + SRCS = [src] + if str(src).endswith('.cpp'): + target_name = os.path.basename(str(src)[:-4]) + elif str(src).endswith('.c'): + target_name = os.path.basename(str(src)[:-2]) + + env['COMPONENTS'].append({'target':target_name, + 'SRCS':SRCS, + 'INCLUDE':INCLUDE, + 'PRIVATE_INCLUDE':PRIVATE_INCLUDE, + 'REQUIREMENTS':REQUIREMENTS, + 'STATIC_LIB':STATIC_LIB, + 'DYNAMIC_LIB':DYNAMIC_LIB, + 'DEFINITIONS':DEFINITIONS, + 'DEFINITIONS_PRIVATE':DEFINITIONS_PRIVATE, + 'LDFLAGS':LDFLAGS, + 'LINK_SEARCH_PATH':LINK_SEARCH_PATH, + 'REGISTER':'project' + }) \ No newline at end of file diff --git a/examples/simdjson_demo/main/include/main.h b/examples/simdjson_demo/main/include/main.h new file mode 100644 index 0000000..e69de29 diff --git a/examples/simdjson_demo/main/src/simdjson_demo.cpp b/examples/simdjson_demo/main/src/simdjson_demo.cpp new file mode 100644 index 0000000..341fbb9 --- /dev/null +++ b/examples/simdjson_demo/main/src/simdjson_demo.cpp @@ -0,0 +1,45 @@ +/* + * SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD + * + * SPDX-License-Identifier: MIT + */ +#include +#include + +int main() +{ + // JSON string + const char *json = R"({ + "name": "Alice", + "age": 30, + "city": "Wonderland" + })"; + + // Create a simdjson::dom::parser object + simdjson::dom::parser parser; + + // Parse the JSON string + simdjson::dom::element doc; + auto error = parser.parse(json, std::strlen(json)).get(doc); + if (error) { + std::cerr << "Parsing error: " << error << std::endl; + return 1; + } + + // Extract field values + std::string_view name; + int64_t age; + std::string_view city; + + if (doc["name"].get(name) || doc["age"].get(age) || doc["city"].get(city)) { + std::cerr << "Error extracting field values" << std::endl; + return 1; + } + + // Output the results + std::cout << "Name: " << name << std::endl; + std::cout << "Age: " << age << std::endl; + std::cout << "City: " << city << std::endl; + + return 0; +} diff --git a/github_source/source-list.sh b/github_source/source-list.sh index 88eb882..9b6c9ae 100755 --- a/github_source/source-list.sh +++ b/github_source/source-list.sh @@ -46,6 +46,7 @@ git_clone_and_checkout_commit https://github.com/wqking/eventpp.git c472fb22e71e git_clone_and_checkout_commit https://github.com/DaveGamble/cJSON.git 078c4e6c53f13dff15f0eaac1611abb6379e0206 git_clone_and_checkout_commit https://github.com/zpl-c/zpl.git 7e4d5889e9fc7c67251e627d30b7673c915fab0d git_clone_and_checkout_commit https://github.com/nanomsg/nng.git 9ea51a5bd5828648c68dbfbc43b2edcde65e5262 +git_clone_and_checkout_commit https://github.com/simdjson/simdjson.git 9b314922a1f5ecbda366115992893e368cd2f0e0 # opencv-mobile-2.4.13.7-armlinux https://github.com/nihui/opencv-mobile/releases/download/v26/opencv-mobile-2.4.13.7-armlinux.zip diff --git a/tools/scons/SConstruct_tool.py b/tools/scons/SConstruct_tool.py index 89f718a..8cdf73a 100644 --- a/tools/scons/SConstruct_tool.py +++ b/tools/scons/SConstruct_tool.py @@ -69,6 +69,53 @@ def compare_and_copy(file1, file2): with open(file1, "rb") as f1, open(file2, "wb") as f2: f2.write(f1.read()) +def sample_wget(down_url, file_path): + if not os.path.exists(file_path): + import requests + response = requests.get(down_url) + if response.status_code == 200: + with open(file_path, 'wb') as file: + file.write(response.content) + else: + env.Fatal("{} down failed".format(down_url)) + return file_path + +def wget_tar_gz(url, file_name): + file_path = os.path.join(os.environ['GIT_REPO_PATH'], file_name) + path = file_path[:-7] + if not os.path.exists(path): + sample_wget(url, file_path) + import tarfile + with tarfile.open(file_path, 'r:gz') as tar: + tar.extractall(path=path) + return path + +def wget_zip(url, file_name): + file_path = os.path.join(os.environ['GIT_REPO_PATH'], file_name) + path = file_path[:-4] + if not os.path.exists(path): + sample_wget(url, file_path) + import zipfile + with zipfile.ZipFile(file_path, 'r') as zip_ref: + for file_info in zip_ref.infolist(): + try: + zip_ref.extract(file_info, path) + except Exception as e: + pass + return path + +def wget_github_commit(url, commit): + import parse + import shutil + repo = parse.parse("{}://{}/{}/{}.git", url) + github_url = url.rstrip('.git') + down_url = github_url + "/archive/{}.zip".format(commit) + zip_file_name = '{}-{}.zip'.format(repo[3], commit) + file_path = wget_zip(down_url, zip_file_name) + shutil.move(os.path.join(file_path, zip_file_name[:-4]), os.path.join(os.environ['GIT_REPO_PATH'], repo[3])) + shutil.rmtree(file_path) + return down_url + def check_component(component_name): if component_name in env['GIT_REPO_LISTS']: if not os.path.exists(env['GIT_REPO_LISTS'][component_name]['path']): @@ -78,37 +125,8 @@ def check_component(component_name): down = input('{} does not exist. Please choose whether to download it automatically? Y/N :'.format(component_name)) down = down.lower() if down == 'y': - # from git import Repo - import requests - import parse - import zipfile - import shutil try: - # Downloading via HTTP (more common) - repo = parse.parse("{}://{}/{}/{}.git", env['GIT_REPO_LISTS'][component_name]['url']) - zip_file = "{}-{}.zip".format(env['GIT_REPO_LISTS'][component_name]['path'], env['GIT_REPO_LISTS'][component_name]['commit']) - zip_file_extrpath = "{}-{}".format(env['GIT_REPO_LISTS'][component_name]['path'], env['GIT_REPO_LISTS'][component_name]['commit']) - zip_file_next_path = os.path.join(zip_file_extrpath, "{}-{}".format(repo[3], env['GIT_REPO_LISTS'][component_name]['commit'])) - down_url = "https://github.com/{}/{}/archive/{}.zip".format(repo[2], repo[3], env['GIT_REPO_LISTS'][component_name]['commit']) - if not os.path.exists(zip_file): - response = requests.get(down_url) - if response.status_code == 200: - with open(zip_file, 'wb') as file: - file.write(response.content) - else: - env.Fatal("{} down failed".format(down_url)) - with zipfile.ZipFile(zip_file, 'r') as zip_ref: - for file_info in zip_ref.infolist(): - try: - zip_ref.extract(file_info, zip_file_extrpath) - except Exception as e: - pass - shutil.move(zip_file_next_path, env['GIT_REPO_LISTS'][component_name]['path']) - shutil.rmtree(zip_file_extrpath) - # The way to download Git is to download the Git software package. - # Repo.clone_from(env['GIT_REPO_LISTS'][component_name]['url'], env['GIT_REPO_LISTS'][component_name]['path']) - # repo = Repo(env['GIT_REPO_LISTS'][component_name]['path']) - # repo.git.checkout(env['GIT_REPO_LISTS'][component_name]['commit']) + down_url = wget_github_commit(env['GIT_REPO_LISTS'][component_name]['url'], env['GIT_REPO_LISTS'][component_name]['commit']) print("The {} download successful.".format(down_url)) except Exception as e: print('Please manually download {} to {}.'.format(env['GIT_REPO_LISTS'][component_name]['url'], env['GIT_REPO_LISTS'][component_name]['path'])) @@ -116,6 +134,34 @@ def check_component(component_name): else: env.Fatal('Please manually download {} to {}.'.format(env['GIT_REPO_LISTS'][component_name]['url'], env['GIT_REPO_LISTS'][component_name]['path'])) +def check_wget_down(url, file_name): + if file_name.endswith('.zip'): + file_path = os.path.join(os.environ['GIT_REPO_PATH'], file_name) + path = file_path[:-4] + if not os.path.exists(path): + if 'CONFIG_REPO_AUTOMATION' in os.environ: + down = 'y' + else: + down = input('{} does not exist. Please choose whether to download it automatically? Y/N :'.format(file_path)) + down = down.lower() + if down == 'y': + return wget_zip(url, file_name) + return path + elif file_name.endswith('.tar.gz'): + file_path = os.path.join(os.environ['GIT_REPO_PATH'], file_name) + path = file_path[:-7] + if not os.path.exists(path): + if 'CONFIG_REPO_AUTOMATION' in os.environ: + down = 'y' + else: + down = input('{} does not exist. Please choose whether to download it automatically? Y/N :'.format(file_path)) + down = down.lower() + if down == 'y': + return wget_tar_gz(url, file_name) + return path + else: + env.Fatal('{} not support'.format(file_name)) + def CC_cmd_execute(cmd): import os env.ParseConfig('${{CC}} {} > gcc_out.txt 2>&1'.format(cmd))