Skip to content

Module Pre-processing/reorg#324

Merged
Volte6 merged 14 commits intomasterfrom
module-reorg
Apr 22, 2025
Merged

Module Pre-processing/reorg#324
Volte6 merged 14 commits intomasterfrom
module-reorg

Conversation

@Volte6
Copy link
Member

@Volte6 Volte6 commented Apr 21, 2025

Description

This reorganizes modules into their own packages/folders. Modules have been included in a single folder to allow them to be "automatically" compiled into the final binary thanks to a single include in main.go: _ "github.com/GoMudEngine/GoMud/modules"

However, the result is a cluttered folder containing all sorts of files or folders for various modules.

This change fixes 2 issues:

  1. Cleans up clutter and organizational issues, making it easy to add/remove individual modules from your project, since they will be found within their own subfolder.
  2. Forces module code to its own package namespace, no longer shared with other packages. This helps prevent namespace pollution and a tendency module-creators may have to directly reference code in other modules.

Concerns

  • Modules will not be included in the build unless go generate is run before the build. This can be automated for those that use a make command, but for anyone on windows or unfamiliar with make, it needs to be explicitly called out to run go generate first.
    • To mitigate this somewhat, I've added a halt to the execution of the server if the go-generate hasn't been run yet:
~/dev/GoMud % go run .
!!! Run "go generate" before building this project !!!

Changes

  • Moved all modules into their own subfolders
  • Standardized module file embeds to files folder name within their own folder.
  • Added cmd/generate/module-imports.go - this is only intended to be invoked via go generate, which handles the following compiler directive in main.go:
    • //go:generate go run cmd/generate/module-imports.go
    • This parses the modules folder off of the repo root and writes all folder names into the all-modules.go include, thereby forcing all modules to be included.
    • This allows the step to remain agnostic to operating system, instead of using specialized shell commands or scripts, a Go program does all of the work.

Example

Screenshot of output:
image

@Volte6 Volte6 marked this pull request as ready for review April 21, 2025 19:58
Makefile Outdated
Comment on lines +105 to +111
.PHONY: ungenerate
ungenerate: ### Build a binary for a raspberry pi zero 2w
@cp cmd/generate/_all-modules.go modules/all-modules.go

.PHONY: generate
generate: ### Build a binary for a raspberry pi zero 2w
@go generate
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments are inaccurate

Copy link
Member Author

@Volte6 Volte6 Apr 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

~/dev/GoMud % make help

Build Targets                     
  build_rpi_zero2w: generate          - Build a binary for a raspberry pi zero 2w
  build_win64: generate               - Build a binary for 64bit windows
  build_linux64: generate             - Build a binary for linux
  build: validate build_local         - Validate the code and build the binary.
  ungenerate:                         - Reverts to a clean version of modules/all-modules.go
  generate:                           - Generates include directives for modules

Run Targets                       
  run:                                - Build and run server.
  client:                             - Build and run client terminal client

Help                              
  help:                               - List makefile targets.

@lostsnow
Copy link
Member

LGTM

@Volte6 Volte6 merged commit 915a4de into master Apr 22, 2025
1 check passed
@Volte6 Volte6 deleted the module-reorg branch April 22, 2025 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants