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

Packing macOS executable into application #96

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions .github/workflows/automatic_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
run: |
mv linux/sniffcraft sniffcraft-linux-${{ steps.mc-version.outputs.version }}
mv windows/sniffcraft.exe sniffcraft-windows-${{ steps.mc-version.outputs.version }}.exe
mv macos/sniffcraft sniffcraft-macos-${{ steps.mc-version.outputs.version }}
mv macos/sniffcraft.zip sniffcraft-macos-universal-${{ steps.mc-version.outputs.version }}.zip

- name: Remove old latest release
run: gh release delete latest --repo ${{ github.repository }} --cleanup-tag -y
Expand All @@ -100,7 +100,7 @@ jobs:
gh release create latest
sniffcraft-linux-${{ steps.mc-version.outputs.version }}
sniffcraft-windows-${{ steps.mc-version.outputs.version }}.exe
sniffcraft-macos-${{ steps.mc-version.outputs.version }}
sniffcraft-macos-universal-${{ steps.mc-version.outputs.version }}.zip
--repo ${{ github.repository }}
--latest
-F release_note.txt
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/sniffcraft_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,21 @@ jobs:
GH_TOKEN: ${{ github.token }}

- name: Upload artifact
if: ${{ inputs.os != 'macos-latest' }}
uses: actions/upload-artifact@v4
with:
name: sniffcraft-${{ runner.os }}
path: ${{ github.workspace }}/bin/sniffcraft*
retention-days: 1

- name: Archive macOS application
if: ${{ inputs.os == 'macos-latest' }}
run: cd ${{ github.workspace }}/bin && zip -r sniffcraft.zip SniffCraft.app

- name: Upload macOS artifact
if: ${{ inputs.os == 'macos-latest' }}
uses: actions/upload-artifact@v4
with:
name: sniffcraft-${{ runner.os }}
path: ${{ github.workspace }}/bin/sniffcraft.zip
retention-days: 1
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
bin/
build/
lib/
lib/

.vscode/
.idea/

# CLion build directory
/cmake-**

.DS_Store
9 changes: 9 additions & 0 deletions sniffcraft/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ if (MSVC)
set_target_properties(${PROJECT_NAME} PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded")
endif(MSVC)

if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE TRUE)
set_target_properties(${PROJECT_NAME} PROPERTIES
OUTPUT_NAME "SniffCraft"
XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME YES
Copy link
Owner

Choose a reason for hiding this comment

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

XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME seems to be very XCode only. So I think the if condition should also check the generator is xcode, as it's also possible to compile on macos with other generators that don't support these features.

Also, I'm not sure what hardened runtime do exactly, but with a quick internet search, it makes me think it may break the DLL loading for the plugins feature.

Copy link
Author

Choose a reason for hiding this comment

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

XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME seems to be very XCode only. So I think the if condition should also check the generator is xcode, as it's also possible to compile on macos with other generators that don't support these features.

Also, I'm not sure what hardened runtime do exactly, but with a quick internet search, it makes me think it may break the DLL loading for the plugins feature.

This is an optional option, but I've seen many people use it. At the expense of XCode, other compilers will simply ignore these options

XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY libc++
)
endif()

# Add Asio
target_link_libraries(${PROJECT_NAME} PUBLIC asio)
target_compile_definitions(${PROJECT_NAME} PUBLIC ASIO_STANDALONE)
Expand Down
8 changes: 8 additions & 0 deletions sniffcraft/src/conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,20 @@ ProtocolCraft::Json::Value Conf::LoadConf()
{
if (conf_path.empty())
{
#if defined(__APPLE__)
conf_path = "/Users/" + std::string(std::getenv("USER")) + "/Library/Application Support/SniffCraft/conf.json";
#else
conf_path = "conf.json";
#endif
}

// Create file if it doesn't exist
if (!std::filesystem::exists(conf_path))
{
std::filesystem::path parent_directory = std::filesystem::path(conf_path).parent_path();
if (!parent_directory.empty()) {
std::filesystem::create_directories(parent_directory);
}
std::ofstream outfile(conf_path, std::ios::out);
outfile << ProtocolCraft::Json::Value().Dump(4);
}
Expand Down