From 51acc22aefbbc33b5c749fd9c378af677070bef6 Mon Sep 17 00:00:00 2001 From: jlieth <37447552+jlieth@users.noreply.github.com> Date: Fri, 16 Aug 2024 09:31:59 +0200 Subject: [PATCH 1/2] build 32bit libraries as well --- .github/workflows/build.yml | 46 +++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c56b823..7ad8bcd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,8 +19,10 @@ jobs: matrix: target: - x86_64-unknown-linux-gnu + - i686-unknown-linux-gnu - aarch64-unknown-linux-gnu - x86_64-pc-windows-gnu + - i686-pc-windows-gnu steps: - name: Checkout code @@ -43,6 +45,9 @@ jobs: if [ "${{ matrix.target }}" = "x86_64-pc-windows-gnu" ]; then sudo apt-get install -y mingw-w64 fi + if [ "${{ matrix.target }}" = "i686-pc-windows-gnu" ]; then + sudo apt-get install -y gcc-mingw-w64-i686 + fi if [ "${{ matrix.target }}" = "aarch64-unknown-linux-gnu" ]; then sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu fi @@ -52,25 +57,42 @@ jobs: # build target for rust echo "TARGET=${{ matrix.target }}" >> $GITHUB_ENV - - name: Build Binary + if [ "${{ matrix.target }}" = "x86_64-pc-windows-gnu" -o "${{ matrix.target }}" = "i686-pc-windows-gnu" ]; then + # windows 64+32 + echo "DEBUG_BINARY_NAME=target/${{ matrix.target }}/debug/ifstat-rs.exe" >> $GITHUB_ENV + echo "DEBUG_LIBRARY_NAME=target/${{ matrix.target }}/debug/ifstat_rs.dll" >> $GITHUB_ENV + echo "RELEASE_BINARY_NAME=target/${{ matrix.target }}/release/ifstat-rs.exe" >> $GITHUB_ENV + echo "RELEASE_LIBRARY_NAME=target/${{ matrix.target }}/release/ifstat_rs.dll" >> $GITHUB_ENV + else + echo "DEBUG_BINARY_NAME=target/${{ matrix.target }}/debug/ifstat-rs" >> $GITHUB_ENV + echo "DEBUG_LIBRARY_NAME=target/${{ matrix.target }}/debug/libifstat_rs.so" >> $GITHUB_ENV + echo "RELEASE_BINARY_NAME=target/${{ matrix.target }}/release/ifstat-rs" >> $GITHUB_ENV + echo "RELEASE_LIBRARY_NAME=target/${{ matrix.target }}/release/libifstat_rs.so" >> $GITHUB_ENV + fi + + mkdir -p build_output/{debug,release} + + - name: Build Binary (Debug) run: | cargo build --target "${{ matrix.target }}" - mkdir -p build_output - cp target/${{ matrix.target }}/debug/ifstat-rs${{ matrix.target == 'x86_64-pc-windows-gnu' && '.exe' || '' }} build_output/ + cp ${{ env.DEBUG_BINARY_NAME }} build_output/debug/ - - name: Build Library + - name: Build Binary (Release) + run: | + cargo build --target "${{ matrix.target }}" --release + cp ${{ env.RELEASE_BINARY_NAME }} build_output/release/ + + - name: Build Library (Debug) run: | cargo build --target "${{ matrix.target }}" --lib - mkdir -p build_output + cp ${{ env.DEBUG_LIBRARY_NAME }} build_output/debug/ - # handle different name under windows - if [ "${{ matrix.target }}" != "x86_64-pc-windows-gnu" ]; then - cp target/${{ matrix.target }}/debug/libifstat_rs${{ matrix.target == 'x86_64-pc-windows-gnu' && '.dll' || '.so' }} build_output/ - else - cp target/${{ matrix.target }}/debug/ifstat_rs.dll build_output/ - fi + - name: Build Library (Release) + run: | + cargo build --target "${{ matrix.target }}" --lib --release + cp ${{ env.RELEASE_LIBRARY_NAME }} build_output/release/ - - name: Upload built Binary + Library + - name: Upload built (Binary + Library)x(Debug + Release) bundle uses: actions/upload-artifact@v4 with: path: build_output/ From 1c530beed69fd5fa06e5c2098e219b63886d8d70 Mon Sep 17 00:00:00 2001 From: jlieth <37447552+jlieth@users.noreply.github.com> Date: Fri, 16 Aug 2024 10:45:50 +0200 Subject: [PATCH 2/2] explicit drop --- src/net_stats/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/net_stats/mod.rs b/src/net_stats/mod.rs index 5409ffb..65659c5 100644 --- a/src/net_stats/mod.rs +++ b/src/net_stats/mod.rs @@ -57,7 +57,7 @@ pub extern "C" fn GetNetDevStats() -> *mut c_char { pub extern "C" fn FreeCString(s: *mut c_char) { if !s.is_null() { unsafe { - let _ = CString::from_raw(s); // This will automatically free the memory + drop(CString::from_raw(s)); } } }