robo9k / rust-magic-sys

Rust declarations crate for the `libmagic` C library
Apache License 2.0
10 stars 6 forks source link

Investigation of `pkg-config`, `brew` / `vcpkg` on GHA #35

Closed robo9k closed 1 year ago

robo9k commented 1 year ago

In order to see how viable #1 is I've tested this with GitHub Actions on their shared runners.

At the time of writing:

ubuntu-22.04

macos-12

windows-2022

on:
  workflow_dispatch: 

jobs:
  ubuntu:
    runs-on: ubuntu-22.04

    steps:
      - run: |
          sudo apt-get update
          sudo apt-get install libmagic1 libmagic-dev pkg-config

      - run: |
          which pkg-config
          pkg-config --version

      - run: ls $(pkg-config --variable=libdir libmagic)/libmagic*

      - run: pkg-config --debug --validate libmagic

      - run: |
          pkg-config --static --libs --cflags libmagic
          pkg-config --libs --cflags libmagic
  macos:
    runs-on: macos-12

    steps:
      - run: |
          brew update
          brew install libmagic pkg-config

      - run: |
          which pkg-config
          pkg-config --version
          brew --version

      - run: ls $(pkg-config --variable=libdir libmagic)/libmagic*

      - run: pkg-config --debug --validate libmagic

      - run: |
          pkg-config --static --libs --cflags libmagic
          pkg-config --libs --cflags libmagic

  windows:
      runs-on: windows-2022
      env:
        VCPKG_BINARY_SOURCES: clear;x-gha,readwrite

      steps:
        - uses: actions/github-script@v6
          with:
            script: |
              core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
              core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');

        - run: |
            vcpkg update
            vcpkg install libmagic

        - run: |
            vcpkg version

        - run: |
            vcpkg search libmagic
            vcpkg depend-info libmagic

While this did not actually test a build of magic-sys (with neither pkg-config nor (cargo) vcpkg, it looks like at least GHA should be able to build with a hard requirement on

robo9k commented 1 year ago

Looking at the static build flags explains missing symbols in https://github.com/robo9k/rust-magic-sys/pull/30#issuecomment-1337537973 and https://github.com/robo9k/rust-magic-sys/issues/34#issue-1549794589

It doesn't help explain https://github.com/robo9k/rust-magic-sys/issues/37#issue-1925130619 so that needs further investigation. There was another vcpkg workaround in https://github.com/robo9k/rust-magic-sys/pull/16#issuecomment-949094327

In general I believe the current way of building with the MAGIC_DIR, MAGIC_STATIC env is too simplistic in that it makes half-baked assumptions about the installed libmagic library. Instead we should lean in fully on pkg-config and vcpkg, so that users will have to configure those crates/binaries instead. Maybe we could keep a MAGIC_LINK env with auto|dynamic|static which attempts to detect a sensible default for auto or else passes dynamic/static to pkg-config & vcpkg.

This would mean a change in requirements (see #5 ) and thus in supported systems. I'll do some more research in #36

I'm still not sold entirely on #4 as I'd rather not pull in a whole submodule and possibly autotools (crate) dependency. Using apt-get, brew, vcpkg is probably enough for the common cases.

robo9k commented 1 year ago

See https://github.com/robo9k/rust-magic-sys/pull/39#issue-1931419619 for a series of pull requests that implement builds with GHA for this repo now