移动开发:树莓派开发环境构建

我在最初的 移动工作思考 方案中,是想采用 macOS 的 MacBook Pro来实现的: 我从2011年自费购买了MacBook Air 11” 就一直使用 Apple Atlas 家的系列产品,确实是非常成熟的软硬件融合的生态。不过,2022年3月,魔都一个多月疫情封闭在家,我开始折腾 树莓派Raspberry Pi 400 运行 sway - i3兼容Wayland compositor (基于 wayland显示服务器协议 的平铺式窗口管理器),意外发现 wayland+sway 居然能够充分释放 Raspberry Pi Atlas 的性能,这触发我思考用日常 Linux桌面 来完成所有开发运维,磨炼技术的方案。

Raspberry Pi OS

我在 Raspberry Pi Atlas 上使用过多种Linux发行版:

不过,上述第三方Linux for Raspberry Pi Atlas 各自有一些限制,对于充分发挥树莓派性能以及特有功能存在不足。所以最终,作为图形桌面,我还是回归到树莓派官方提供的 Raspberry Pi OS :

  • 官方 Raspberry Pi OS 提供了针对树莓派硬件配置的 raspi-config 工具,可以非常方便调整系统设置

  • 官方 Raspberry Pi OS 升级包含了firmware升级,可以为系统带来更多改进

  • 出现和树莓派硬件相关的问题更容易找到参考资料

安装Raspberry Pi OS

配置上海本地时区
cd /etc
sudo unlink localtime
sudo ln -s /usr/share/zoneinfo/Asia/Shanghai localtime
  • 更新系统:

APT更新整个系统
sudo apt update
sudo apt upgrade -y
  • 字符集配置UTF-8:

字符集支持UTF-8
echo "en_US.UTF-8 UTF-8" | sudo tee /etc/locale.gen
localegen
  • 安装中文字体:

apt安装文泉驿字体
sudo apt install fonts-wqy-microhei -y
apt安装sway
sudo apt install sway wofi
  • 修订 ~/.zshrc 添加以下内容方便自动启动 sway :

复制sway个人配置
if [ -z $DISPLAY ] && [ "$(tty)" = "/dev/tty1" ]; then
  exec sway
fi
  • 创建 sway 个人定制配置文件 ~/.config/sway/config :

sway个人配置
# Default config for sway
#
# Copy this to ~/.config/sway/config and edit it to your liking.
#
# Read `man 5 sway` for a complete reference.

### Variables
#
# Logo key. Use Mod1 for Alt.
# 我尝试过使用 Alt ,但是有些应用默认内置了 Alt 作为快捷键,可能会有冲突
set $mod Mod4

# Home row direction keys, like vim
# 结合 $mod + 移动键可以快速在4个方向上移动聚焦窗口
set $left h
set $down j
set $up k
set $right l

# Your preferred terminal emulator
# 将默认foot终端修改成qtermianl可以支持fcitx中文输入
#set $term foot
set $term qterminal

# Your preferred application launcher
# Note: pass the final command to swaymsg so that the resulting window can be opened
# on the original workspace that the command was run on.
set $menu dmenu_path | dmenu | xargs swaymsg exec --

include /etc/sway/config-vars.d/*

### Output configuration
#
# Default wallpaper (more resolutions are available in /usr/share/backgrounds/sway/)
output * bg /usr/share/backgrounds/sway/Sway_Wallpaper_Blue_1920x1080.png fill
#
# Example configuration:
#
#   output HDMI-A-1 resolution 1920x1080 position 1920,0
#
# You can get the names of your outputs by running: swaymsg -t get_outputs

### Idle configuration
#
# Example configuration:
#
# exec swayidle -w \
#          timeout 300 'swaylock -f -c 000000' \
#          timeout 600 'swaymsg "output * dpms off"' resume 'swaymsg "output * dpms on"' \
#          before-sleep 'swaylock -f -c 000000'
#
# This will lock your screen after 300 seconds of inactivity, then turn off
# your displays after another 300 seconds, and turn your screens back on when
# resumed. It will also lock your screen before your computer goes to sleep.

exec_always fcitx5 -d --replace

### Input configuration
#
# Example configuration:
#
#   input "2:14:SynPS/2_Synaptics_TouchPad" {
#       dwt enabled
#       tap enabled
#       natural_scroll enabled
#       middle_emulation enabled
#   }
#
# You can get the names of your inputs by running: swaymsg -t get_inputs
# Read `man 5 sway-input` for more information about this section.

### Key bindings
#
# Basics:
#
    # Start a terminal
    bindsym $mod+Return exec $term

    # Start chromium with wayland
    bindsym $mod+o exec chromium --enable-features=UseOzonePlatform --ozone-platform=wayland --proxy-server="http://192.168.10.9:3128"
    
    # Start firefox
    bindsym $mod+i exec firefox

    # Kill focused window
    bindsym $mod+Shift+q kill

    # Start your launcher
    bindsym $mod+d exec $menu

    # Drag floating windows by holding down $mod and left mouse button.
    # Resize them with right mouse button + $mod.
    # Despite the name, also works for non-floating windows.
    # Change normal to inverse to use left mouse button for resizing and right
    # mouse button for dragging.
    floating_modifier $mod normal

    # Reload the configuration file
    bindsym $mod+Shift+c reload

    # Exit sway (logs you out of your Wayland session)
    bindsym $mod+Shift+e exec swaynag -t warning -m 'You pressed the exit shortcut. Do you really want to exit sway? This will end your Wayland session.' -B 'Yes, exit sway' 'swaymsg exit'
#
# Moving around:
#
    # Move your focus around
    bindsym $mod+$left focus left
    bindsym $mod+$down focus down
    bindsym $mod+$up focus up
    bindsym $mod+$right focus right
    # Or use $mod+[up|down|left|right]
    bindsym $mod+Left focus left
    bindsym $mod+Down focus down
    bindsym $mod+Up focus up
    bindsym $mod+Right focus right

    # Move the focused window with the same, but add Shift
    bindsym $mod+Shift+$left move left
    bindsym $mod+Shift+$down move down
    bindsym $mod+Shift+$up move up
    bindsym $mod+Shift+$right move right
    # Ditto, with arrow keys
    bindsym $mod+Shift+Left move left
    bindsym $mod+Shift+Down move down
    bindsym $mod+Shift+Up move up
    bindsym $mod+Shift+Right move right
#
# Workspaces:
#
    # Switch to workspace
    bindsym $mod+1 workspace number 1
    bindsym $mod+2 workspace number 2
    bindsym $mod+3 workspace number 3
    bindsym $mod+4 workspace number 4
    bindsym $mod+5 workspace number 5
    bindsym $mod+6 workspace number 6
    bindsym $mod+7 workspace number 7
    bindsym $mod+8 workspace number 8
    bindsym $mod+9 workspace number 9
    bindsym $mod+0 workspace number 10
    # Move focused container to workspace
    bindsym $mod+Shift+1 move container to workspace number 1
    bindsym $mod+Shift+2 move container to workspace number 2
    bindsym $mod+Shift+3 move container to workspace number 3
    bindsym $mod+Shift+4 move container to workspace number 4
    bindsym $mod+Shift+5 move container to workspace number 5
    bindsym $mod+Shift+6 move container to workspace number 6
    bindsym $mod+Shift+7 move container to workspace number 7
    bindsym $mod+Shift+8 move container to workspace number 8
    bindsym $mod+Shift+9 move container to workspace number 9
    bindsym $mod+Shift+0 move container to workspace number 10
    # Note: workspaces can have any name you want, not just numbers.
    # We just use 1-10 as the default.
#
# Layout stuff:
#
    # You can "split" the current object of your focus with
    # $mod+b or $mod+v, for horizontal and vertical splits
    # respectively.
    bindsym $mod+b splith
    bindsym $mod+v splitv

    # Switch the current container between different layout styles
    bindsym $mod+s layout stacking
    bindsym $mod+w layout tabbed
    bindsym $mod+e layout toggle split

    # Make the current focus fullscreen
    bindsym $mod+f fullscreen

    # Toggle the current focus between tiling and floating mode
    bindsym $mod+Shift+space floating toggle

    # Swap focus between the tiling area and the floating area
    bindsym $mod+space focus mode_toggle

    # Move focus to the parent container
    bindsym $mod+a focus parent
#
# Scratchpad:
#
    # Sway has a "scratchpad", which is a bag of holding for windows.
    # You can send windows there and get them back later.

    # Move the currently focused window to the scratchpad
    bindsym $mod+Shift+minus move scratchpad

    # Show the next scratchpad window or hide the focused scratchpad window.
    # If there are multiple scratchpad windows, this command cycles through them.
    bindsym $mod+minus scratchpad show
#
# Resizing containers:
#
mode "resize" {
    # left will shrink the containers width
    # right will grow the containers width
    # up will shrink the containers height
    # down will grow the containers height
    bindsym $left resize shrink width 10px
    bindsym $down resize grow height 10px
    bindsym $up resize shrink height 10px
    bindsym $right resize grow width 10px

    # Ditto, with arrow keys
    bindsym Left resize shrink width 10px
    bindsym Down resize grow height 10px
    bindsym Up resize shrink height 10px
    bindsym Right resize grow width 10px

    # Return to default mode
    bindsym Return mode "default"
    bindsym Escape mode "default"
}
bindsym $mod+r mode "resize"

#
# Status Bar:
#
# Read `man 5 sway-bar` for more information about this section.
bar {
    position top

    # When the status_command prints a new line to stdout, swaybar updates.
    # The default just shows the current date and time.
    status_command while date +'%Y-%m-%d %I:%M:%S %p'; do sleep 1; done

    colors {
        statusline #ffffff
        background #323232
        inactive_workspace #32323200 #32323200 #5c5c5c
    }
}

include /etc/sway/config.d/*
  • 配置 /etc/environment 添加以下环境变量适配QT5应用:

QT5应用环境变量 /etc/environment
QT_QPA_PLATFORM=wayland
  • 安装中文输入法:

apt安装fcitx
sudo apt install fcitx5 fcitx5-chinese-addons
  • 配置 /etc/environment :

启用fcitx5环境变量配置 /etc/environment
GTK_IM_MODULE=fcitx
QT_IM_MODULE=fcitx
XMODIFIERS=@im=fcitx
INPUT_METHOD=fcitx
SDL_IM_MODULE=fcitx
GLFW_IM_MODULE=ibus
  • 安装应用软件:

debian系安装应用
sudo apt install git vim-nox mpd ncmpc \
                 qterminal falkon keepassx \
                 -y
  • 重新登陆后自动进入 sway - i3兼容Wayland compositor

  • sway 环境中,直接 Mod4+return 启动终端,然后执行 fcitx5-configtool 进行配置,完成配置后退出重新登陆即可输入中文

开发环境

采用 我的vim配置 部署开发环境

安装Ultimate vimrc Awsome版本
git clone --depth=1 https://github.com/amix/vimrc.git ~/.vim_runtime
sh ~/.vim_runtime/install_awesome_vimrc.sh
  • 配置 ~/.vim_runtime/my_configs.vim :

~/.vim_runtime/my_configs.vim
" 行号和配色
"
set nu rnu
set background=dark
colorscheme dracula

" 自动缩进
"
filetype indent on
set ai
set si

" 折叠
"
set foldmethod=syntax
set foldlevelstart=99
编译YouCompleteMe依赖软件安装
sudo apt install build-essential cmake vim-nox python3-dev -y
  • 安装Rust:

Liinux平台安装Rust
curl https://sh.rustup.rs -sSf | sh -s -- --profile default
source $HOME/.cargo/env
安装Go和node.js
sudo apt install golang nodejs npm -y
alias设置go代理
alias go='http_proxy=192.168.7.9:3128 go'
alias设置npm代理
alias npm='npm --proxy http_proxy=192.168.7.9:3128'
  • 按需编译YouCompleteMe:

按需编译YouCompleteMe
git submodule update --init --recursive

python3 install.py --clangd-completer --go-completer \
        --ts-completer --rust-completer

现在,一切就绪,使用 vim 可以开始进行开发学习