[FFmpeg-devel] [PATCH 1/1] Enable building with WSL and MSVC

Julio C. Rocha dev at rocha.red
Tue Oct 4 03:28:35 EEST 2022


On Mon, Oct 3, 2022 at 8:21 AM Pierre-Anthony Lemieux <pal at sandflow.com>
wrote:

> On Mon, Oct 3, 2022 at 1:11 AM Julio C. Rocha <dev at rocha.red> wrote:
> >
> > On Sun, Oct 2, 2022 at 5:19 PM Pierre-Anthony Lemieux <pal at sandflow.com>
> > wrote:
> >
> > > On Sun, Oct 2, 2022 at 5:14 PM Timo Rothenpieler <
> timo at rothenpieler.org>
> > > wrote:
> > > >
> > > > On 03.10.2022 01:47, Julio C. Rocha wrote:
> > > > > ---
> > > > >   configure | 7 ++++++-
> > > > >   1 file changed, 6 insertions(+), 1 deletion(-)
> > > > >
> > > > > diff --git a/configure b/configure
> > > > > index 6712d045d9..f5f5eb29dd 100755
> > > > > --- a/configure
> > > > > +++ b/configure
> > > > > @@ -4847,7 +4847,12 @@ probe_cc(){
> > > > >           else
> > > > >               _ident=$($_cc --version 2>/dev/null | head -n1 | tr
> -d
> > > '\r')
> > > > >           fi
> > > > > -        _DEPCMD='$(DEP$(1)) $(DEP$(1)FLAGS) $($(1)DEP_FLAGS) $<
> 2>&1
> > > | awk '\''/including/ { sub(/^.*file: */, ""); gsub(/\\/, "/"); if
> > > (!match($$0, / /)) print "$@:", $$0 }'\'' > $(@:.o=.d)'
> > > > > +        if [ "$(grep -i Microsoft /proc/version)" ]; then
> > > >
> > > > Not convinced that this is a good check.
> > > > I can think of a few other situations where Microsoft might appear in
> > > > there. Like, for example on one of their servers, Azure Cloud, Github
> > > > Actions and so on.
> > > >
> > > > > +            # Windows Subsystem for Linux
> > > > > +            _DEPCMD='$(DEP$(1)) $(DEP$(1)FLAGS) $($(1)DEP_FLAGS)
> $<
> > > 2>&1 | awk '\''/including/ { sub(/^.*file: */, ""); gsub(/\\/, "/"); if
> > > (!match($$0, / /)) { cmd="/usr/bin/wslpath \x27" $$0 "\x27"; cmd |&
> getline
> > > pth; print "$@:", pth } }'\'' > $(@:.o=.d)'
> > > > > +        else
> > > > > +            _DEPCMD='$(DEP$(1)) $(DEP$(1)FLAGS) $($(1)DEP_FLAGS)
> $<
> > > 2>&1 | awk '\''/including/ { sub(/^.*file: */, ""); gsub(/\\/, "/"); if
> > > (!match($$0, / /)) print "$@:", $$0 }'\'' > $(@:.o=.d)'
> > > > > +        fi
> > > > >           _DEPFLAGS='$(CPPFLAGS) $(CFLAGS) -showIncludes -Zs'
> > > > >           _cflags_speed="-O2"
> > > > >           _cflags_size="-O1"
> > > >
> > > >
> > > > What actual issue is this solving?
> > > > I've been building in WSL for years, including MSVC builds, and never
> > > > encountered any problems.
> > >
> > > FWIW. I am currently building on WSL:
> > >
> > > $ uname -a
> > > Linux pal-xxxxx 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2
> > > 00:30:59 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
> > >
> > > $ lsb_release -a
> > > No LSB modules are available.
> > > Distributor ID: Ubuntu
> > > Description:    Ubuntu 20.04.4 LTS
> > > Release:        20.04
> > > Codename:       focal
> > >
> >
> > Noted, Pierre.
> > Are you able to build using the Visual Studio compilers (MSVC) without
> any
> > further hacking?
>
> I had never tried it. Quick attempt results in:
>
> $ ./configure --toolchain=msvc
> cl.exe is unable to create an executable file.
> If cl.exe is a cross-compiler, use the --enable-cross-compile option.
>

There are a couple of missing steps:

   1. Enter the Visual Studio Developer Command Prompt (or Native Tools
   Command Prompt).
   See
   https://learn.microsoft.com/en-us/visualstudio/ide/reference/command-prompt-powershell?view=vs-2022
   2. Add the following entries to the `WSLENV` environment variable (so
   the necessary paths are passed to the wsl instance):
   CommandPromptType
   DevEnvDir
   ExtensionSdkDir
   EXTERNAL_INCLUDE
   INCLUDE
   LIB
   LIBPATH
   UCRTVersion
   UniversalCRTSdkDir
   VCIDEInstallDir
   VCINSTALLDIR
   VCToolsInstallDir
   VCToolsRedistDir
   VCToolsVersion
   VisualStudioVersion
   VS170COMNTOOLS
   VSCMD_ARG_app_plat
   VSCMD_ARG_HOST_ARCH
   VSCMD_ARG_TGT_ARCH
   VSCMD_ARG_VCVARS_VER
   VSCMD_ARG_winsdk
   VSCMD_VER
   VSINSTALLDIR
   VSSDK150INSTALL
   VSSDKINSTALL
   WindowsLibPath
   WindowsSDK_ExecutablePath_x64
   WindowsSDK_ExecutablePath_x86
   WindowsSdkBinPath
   WindowsSdkDir
   WindowsSDKLibVersion
   WindowsSdkVerBinPath
   WindowsSDKVersion
   3. Start WSL from that command prompt.
   4. Go to the ffmpeg clone.
   5. ./configure  --toolchain=msvc
   6. make
   Succeeds, because it only generates the .d files without using them this
   first time around.
   7. make install
   Or clean, or pretty much any other subsequent make target.
   Will fail with the following message:
   doc/print_options.d:1: *** target pattern contains no '%'.  Stop.

Looking into doc/print_options.d (or any other generated .d file), contents
are like this:
doc/print_options.o: D:/Extra/ffmpeg/wsl/libavutil/attributes.h
...

Such paths work fine with CYGWIN, but not with a real Linux userland (such
as WSL).
Running ./configure with this proposed patch fixes the issue, generating .d
files with content like this:
doc/print_options.o: /mnt/d/Extra/ffmpeg/wsl/libavutil/attributes.h


More information about the ffmpeg-devel mailing list