Use rust for OPENWRT development applications. _openwrt

Source: Internet
Author: User
Tags rust programming language

Recently read the article Liigo the MIPS platform OPENWRT router system within the Rust application development, the benefit is very deep, resulting in the rust integration into the OPENWRT software package impulse. After one or two days of trying, the initial success was finally achieved. Share below the specific process.


First Step: Install dependencies

Apt-get Install Gyp bzip2

Step two: Modify the Python package

Let's assume that you're in the OpenWrt directory,
Into the package/feeds/packages/python/patches/
Open 110-enable-zlib.patch
Overwrite with the following content

---
 modules/setup.dist |    2 +-
 1 file changed, 1 insertion (+), 1 deletion (-)


---a/modules/setup.dist
+++ b/modules/setup.dist @@
-460,7 +460,9 @@ glhack=-dclear=__glclear
 # Andrew kuchling ' s zlib module.
 # this require zlib 1.1.3 (or later).
 # http://www.gzip.org/zlib/
-#zlib zlibmodule.c-i$ (prefix)/include-l$ exec_prefix/lib-lz
Zlibmodule.c-lz
+bz2 bz2module.c-lbz2  
+thread threadmodule.c-lpthread # Interface to the


 Expat XML Pars ER
 #

Open the Package/feeds/packages/python/makefile file, find the Define Host/configure section, modify the--without-threads inside to--with-threads
Finally execute make Package/feeds/packages/python/host/install v=s.


Finally, create a rust directory under the package directory. and create a new makefile

Include $ (topdir)/rules.mk pkg_name:=rust pkg_version:=0.12.0-nightly pkg_release:=1 pkg_source_proto:=git PKG_ Source_version:=master pkg_source_subdir:=$ (pkg_name)-$ (pkg_version) pkg_source_url:=https://github.com/ rust-lang/$ (pkg_name). Git pkg_source:=$ (pkg_name)-$ (pkg_version)-$ (pkg_source_version). tar.gz PKG_BUILD_DIR:=$ ( Build_dir)/$ (pkg_name)-$ (pkg_version)/pkg_build_parallel:=1 host_build_parallel:=1 HOST_BUILD_DEPENDS:=-python/ Host Python/bzip2/host include $ (include_dir)/package.mk include $ (include_dir)/host-build.mk define Package/rust SUB Menu:=rust category:=languages title:=the Rust programming Language url:=http://www.rust-lang.org/endef define Pac  Kage/rust/description Rust is a systems programming language this runs blazingly fast, prevents almost all crashes*, and 
Eliminates data races. Endef define build/configure CD $ (pkg_build_dir) &&/configure \ $ (configure_vars) Endef define Ile $ (make)-C $ (pkg_build_dir) Endef DefiNE build/installdev endef define Package/rust/install $ (install_dir) $ (1)/usr/bin $ (install_bin) $ (pkg_install_dir)/US R/bin/lua $ (1)/usr/bin/endef rust_host_name:=$ (Shell echo $ (gnu_host_name) | awk ' begin{fs= '-"} {print $$1"-unknown-"$$ 2 "-" $$3} ') Host_configure_vars = \--target=$ (real_gnu_target_name) \--host=$ (rust_host_name) \--build=$ (RUST_HOST_N AME) \--prefix=$ (staging_dir_host) \--disable-jemalloc \--disable-docs define host/configure cc=$ (HOSTCC_NOCACHE ) CD $ (host_build_dir) &&/configure \ $ (host_configure_vars) endef define Host/compile (\ CD $ (Host_buil D_dir) && $ (make) \) endef define Host/install (CD $ (HOST_BUILD_DIR) && $ (make) Install) Endef $ (EVA L $ (call Hostbuild)) $ (eval $ (call Buildpackage,rust))

Make patches for the target platform and put the patches in the Package/rust/patches directory

Take my router as an example: Target is MIPSEL-OPENWRT-LINUX-UCLIBC, and the patch I generated is: 001-append-mipsel-linux.patch

DIFF-UNR/a/mk/platform.mk/b/mk/platform.mk---a/mk/platform.mk +++ b/mk/platform.mk @@ -404,6 +404,36 @@ -404,6 S_mipsel-linux: =-C target-cpu=mips32-c target-feature= "+mips32,+o32" +# mipsel-openwrt-linux-uclibc configuration + CC_MIPSEL-OPENWRT-LINUX-UCLIBC=MIPSEL-OPENWRT-LINUX-UCLIBC-GCC +cxx_mipsel-openwrt-linux-uclibc= mipsel-openwrt-linux-uclibc-g++ +CPP_MIPSEL-OPENWRT-LINUX-UCLIBC=MIPSEL-OPENWRT-LINUX-UCLIBC-GCC +AR_
Mipsel-openwrt-linux-uclibc=mipsel-openwrt-linux-uclibc-ar +cfg_lib_name_mipsel-openwrt-linux-uclibc=lib$ (1). So +cfg_static_lib_name_mipsel-openwrt-linux-uclibc=lib$ (1). a +cfg_lib_glob_mipsel-openwrt-linux-uclibc=lib$ (1)-*. So +cfg_lib_dsym_glob_mipsel-openwrt-linux-uclibc=lib$ (1)-*.dylib.dsym +cfg_cflags_mipsel-openwrt-linux-uclibc: = -mips32-mabi=32 $ (cflags) +CFG_GCCISH_CFLAGS_MIPSEL-OPENWRT-LINUX-UCLIBC: =-wall-g-fpic-mips32-mabi=32 $ (CFLAGS) +C FG_GCCISH_CXXFLAGS_MIPSEL-OPENWRT-LINUX-UCLIBC: =-fno-rtti $ (cxxflags) +cfg_gccish_link_flags_mipsel-OPENWRT-LINUX-UCLIBC: =-shared-fpic-g-mips32 +cfg_gccish_def_flag_mipsel-openwrt-linux-uclibc: =-Wl,-- Export-dynamic,--dynamic-list= +cfg_gccish_pre_lib_flags_mipsel-openwrt-linux-uclibc: =-Wl,-whole-archive +CFG_ GCCISH_POST_LIB_FLAGS_MIPSEL-OPENWRT-LINUX-UCLIBC: =-wl,-no-whole-archive +cfg_def_suffix_ MIPSEL-OPENWRT-LINUX-UCLIBC: =. Linux.def +CFG_LLC_FLAGS_MIPSEL-OPENWRT-LINUX-UCLIBC: = +CFG_INSTALL_NAME_ MIPSEL-OPENWRT-LINUX-UCLIBC = +CFG_LIBUV_LINK_FLAGS_MIPSEL-OPENWRT-LINUX-UCLIBC = +CFG_EXE_SUFFIX_ MIPSEL-OPENWRT-LINUX-UCLIBC: = +cfg_windowsy_mipsel-openwrt-linux-uclibc: = +CFG_UNIXY_MIPSEL-OPENWRT-LINUX-UCLIBC : = 1 +CFG_PATH_MUNGE_MIPSEL-OPENWRT-LINUX-UCLIBC: = True +CFG_LDPATH_MIPSEL-OPENWRT-LINUX-UCLIBC: = +CFG_RUN_ mipsel-openwrt-linux-uclibc= +cfg_run_targ_mipsel-openwrt-linux-uclibc= +RUSTC_FLAGS_MIPSEL-OPENWRT-LINUX-UCLIBC : =-C target-cpu=mips32-c target-feature= "+mips32,+o32" + + # MIPS-UNKNOWN-LINUX-GNU configuration Cc_mips-unknown-linu
 x-gnu=mips-linux-gnu-gcccxx_mips-unknown-linux-gnu=mips-linux-gnu-g++ 

Final implementation

Make Package/rust/host/install v=s into a long wait.

If nothing happens, you'll be able to create a software package in the Rust language in OpenWrt.


The above code and project have been put into GitHub.

Location: Https://github.com/bywayboy/openwrt-packages/tree/master/rust

Hellorust is a rust-written test project

Location: Https://github.com/bywayboy/openwrt-packages/tree/master/hellorust




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.