Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak infra code and documentation #323

Merged
merged 8 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ updates:
directory: /
schedule:
interval: weekly
labels:
- deps

- package-ecosystem: gomod
directory: /
schedule:
interval: weekly
labels:
- deps

- package-ecosystem: cargo
directory: ./third_party/sdmmparser/src
schedule:
interval: weekly
labels:
- deps
14 changes: 1 addition & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,13 @@ jobs:
- name: Lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.59.1
version: v1.62.0

build:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-2019, macos-latest ]
include:
- os: ubuntu-latest
rust-target: 1.79-x86_64-unknown-linux-gnu
- os: windows-2019
rust-target: 1.79-x86_64-pc-windows-gnu
- os: macos-latest
rust-target: 1.79-x86_64-apple-darwin
runs-on: ${{ matrix.os }}
name: Build - ${{ matrix.os }}
steps:
Expand All @@ -57,11 +50,6 @@ jobs:
architecture: x64
cache: true

- name: Setup Rust
run: |
rustup install ${{ matrix.rust-target }}
rustup default ${{ matrix.rust-target }}

- name: Setup Task
uses: arduino/setup-task@v2
with:
Expand Down
57 changes: 45 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,28 +118,49 @@ Building the application involves two steps:
2. Build the editor.

**sdmmparser** is a Rust library based on the [SpacemanDMM](https://github.com/SpaceManiac/SpacemanDMM) parser and is compiled to a `staticlib`.
It can be found at `internal/third_party/sdmmparser/src`.
It can be found at `/third_party/sdmmparser/src`.

### Prerequisites

* [Go](https://go.dev/): version **1.20** or higher.
* [Rust](https://www.rust-lang.org/): version **1.79.0**.
* (Optional) [Task](https://taskfile.dev): for running build scripts.
* [Go](https://go.dev/): version **1.23** or higher.
* [Rust](https://www.rust-lang.org/): version **1.82.0** or higher.
* [Task](https://taskfile.dev): for running build scripts. (Optional, but recommended)

#### For Windows

Ensure your Rust is configured to use the `stable-x86_64-pc-windows-gnu` toolchain, as Go can't use MSVC for builds and requires GNU.
The easiest way to get the GNU compiler is to install MinGW through chocolatey, msys2, etc.
* [MinGW-w64](https://www.mingw-w64.org/)

After installing MinGW, ensure that the path to its bin folder is added to the PATH environment variable.
##### How to install

MinGW can be installed through package managers like choco (Chocolatey) or downloaded and installed directly from the MinGW website.
After installation, make sure the bin directory of MinGW (which contains gcc.exe) is in your system's PATH.

##### Why to use MinGW

MinGW, short for Minimalist GNU for Windows, is a lightweight development environment providing essential tools like a C compiler for Windows.
It is required as the application uses `cgo` to integrate C libraries, enabling the build and compilation of `cgo` code and ensuring all dependencies are handled properly.

Unlike MSVC (Microsoft Visual C++), which uses different conventions and linkers incompatible with `cgo`,
MinGW is designed to work seamlessly with Go's build system, making it the preferred choice for compiling `cgo` code on Windows.

Alternatively, you can use WSL (Windows Subsystem for Linux) to provide a Linux-like environment that supports cgo and C compilers compatible with Go.
In that case look [for linux](#for-linux) dependencies.

#### For Linux

You may need to install dependencies for building GUI apps: `sudo apt install xorg-dev libgtk-3-dev`.
You may need to install dependencies for building GUI apps:

- **`apt` (Debian, Ubuntu):** `sudo apt install xorg-dev libgtk-3-dev`
- **`yum` (Red Hat, CentOS, Fedora):** `sudo yum install xorg-x11-server-devel gtk3-devel`
- **`dnf` (Fedora, newer Red Hat and CentOS):** `sudo dnf install xorg-x11-server-devel gtk3-devel`
- **`pacman` (Arch Linux):** `sudo pacman -S xorg-server-devel gtk3`
- **`zypper` (openSUSE):** `sudo zypper install xorg-x11-server-devel gtk3-devel`
- **`dnf` or `yum` (Amazon Linux):** `sudo dnf install xorg-x11-server-devel gtk3-devel`
- **`apk` (Alpine Linux):** `sudo apk add xorg-server-dev gtk+3.0-dev`

### Steps

#### Using Task
#### Using Task (Recommended)

Task is a cross-platform Make alternative with scripts in `Taskfile.yml`.

Expand All @@ -150,13 +171,25 @@ With Task installed:

#### Manually

1. First, build the **sdmmparser** library.\
Navigate to `third_party/sdmmparser/src` and run `cargo build --release`.\
This step is needed only once unless **sdmmparser** is modified.
1. Build the **sdmmparser** library:
* Navigate to `third_party/sdmmparser/src`
* Run command:
* **Windows:** `RUSTUP_TOOLCHAIN=stable-x86_64-pc-windows-gnu cargo build --release`
* **Linux:** `RUSTUP_TOOLCHAIN=stable-x86_64-unknown-linux-gnu cargo build --release`
* **macOS:** `RUSTUP_TOOLCHAIN=stable-x86_64-apple-darwin cargo build --release`
2. In the root directory:
* `go build .`: Builds the editor (executable named `sdmm.exe`/`sdmm` in the root).
* `go run .`: Runs the editor.

Step #1 is required only when the **sdmmparser** is modified.

##### Why Use a Custom RUSTUP_TOOLCHAIN

The **sdmmparser** library is compiled into a `staticlib` that is linked into the final Go binary.\
The MSVC toolchain is not compatible with Go, as Go relies on the GNU toolchain for CGO (the mechanism that compiles C code natively within Go).
Using a custom `RUSTUP_TOOLCHAIN` ensures that the Rust library is compiled in a way that aligns with Go's requirements,
avoiding compatibility issues and ensuring smooth integration.

## Credits

StrongDMM uses [SpacemanDMM](https://github.com/SpaceManiac/SpacemanDMM) parser made
Expand Down
52 changes: 37 additions & 15 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,60 @@ vars:
sh: echo '{{if eq OS "windows"}}-H windowsgui -extldflags=-static{{end}}'
LD_FLAGS: -s -w {{.BUILD_VARS}} {{.LD_FLAGS_WINDOWS}}
BUILD_ARGS: -trimpath -ldflags="{{.LD_FLAGS}}"
RUSTUP_TOOLCHAIN:
sh: |
if [ "$OS" = "Windows_NT" ]; then
echo "stable-x86_64-pc-windows-gnu"
else
OS_NAME=$(uname -s)
if [ "$OS_NAME" = "Darwin" ]; then
echo "stable-x86_64-apple-darwin"
elif [ "$OS_NAME" = "Linux" ]; then
echo "stable-x86_64-unknown-linux-gnu"
else
echo "stable"
fi
fi

tasks:
clean-sdmm:
default:
cmds:
- rm -frd ./dst
- task: clean
- task: build

clean-sdmmparser:
clean-parser:
dir: third_party/sdmmparser/src
cmds:
- cargo clean

clean-editor:
cmds:
- '{{if eq OS "windows"}}cmd /C "if exist dst (rmdir /S /Q dst)"{{else}}rm -frd ./dst{{end}}'

clean:
deps:
- clean-sdmmparser
- clean-sdmm
- clean-parser
- clean-editor

run:
deps:
- build-sdmmparser
build-parser:
dir: third_party/sdmmparser/src
cmds:
- go run {{.BUILD_ARGS}} .
- RUSTUP_TOOLCHAIN={{.RUSTUP_TOOLCHAIN}} cargo build --release

build:
deps:
- build-sdmmparser
build-editor:
cmds:
- go build {{.BUILD_ARGS}} -o "dst/{{.BIN_DST}}" .

build-sdmmparser:
dir: third_party/sdmmparser/src
build:
cmds:
- cargo build --release
- task: build-parser
- task: build-editor

run:
deps:
- build-parser
cmds:
- go run {{.BUILD_ARGS}} .

release-files-unzip:
dir: dst
Expand Down
11 changes: 4 additions & 7 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,10 @@ fixes #0

#### Tags

- **ci:** everything connected with CI stuff;
- **doc:** all about the project documentation;
- **feature:** adding of massive functionality;
- **fix:** fixing and resolving bugs and problems;
- **refactor:** improves code without changing functionality;
- **tweak:** small improvements to the existing functionality, ex. wording changes, buttons movement etc;
- **up:** when bumping dependencies.
* **feat**: A new feature
* **fix**: A bug fix
* **chore**: Routine tasks, refactoring, updates, minor improvements
* **docs**: Documentation only changes

## License

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module sdmm

go 1.22
go 1.23

require (
github.com/SpaiR/imgui-go v1.12.1-0.20220214190844-a0bad21e1c5d
Expand Down
Loading