Xerxes Rånby
2009-May-18 15:03 UTC
[LLVMdev] [PATCH] llvm-config: add svn revision to --version
Frits van Bommel skrev:> Benjamin Kramer wrote: > >> At the moment llvm-config outputs "2.6svn" if llvm is build from trunk >> >> $ llvm-config --version >> 2.6svn >> >> Some external projects (built out-of-tree) need to know which revision >> of llvm is installed. LDC currently asks llvm-config --src-root for the >> source directory and then parses svn info's output to get the revision >> number. This requires the user to keep the llvm source tree around even >> if it is not needed to build ldc. >> > > Not technically true; it's not *required*. However, if this isn't done you need > to set it manually in the cmake configuration... > > >> The attached patch modifies the llvm build system (both autotools and >> cmake) to write the revision into PACKAGE_VERSION: >> >> $ llvm-config --version >> 2.6-71981 >> > > I don't think that's enough for LDC; we want to be able to compare the version > with #if, so we need it to produce something like '#define LLVM_REV 71981' (i.e. > a raw integer, not a string). >When we build Icedtea shark JIT we use the llvm-config version to make the icedtea code compatible with api changes in llvm. I belive you are trying to do something similarwith LDC. This can be done without changing the llvm codebase. I suggest the following: add to the LDC configure. LLVM_CFLAGS="$LLVM_CFLAGS -DLLVM_VERSION=`$LLVM_CONFIG --version | sed 's/\.//;s/svn.*//'`" this will take the llvm-config --version output and truncates the versionnumber from 2.6svn to 26 now the LLVM_VERSION can be used in your source code like this: #if LLVM_VERSION >= 26 /*llvm 2.6 and above compatible code*/ #endif #if LLVM_VERSION >= 25 // etc... #endif cheers Xerxes
Frits van Bommel
2009-May-18 17:06 UTC
[LLVMdev] [PATCH] llvm-config: add svn revision to --version
Xerxes Rånby wrote:> Frits van Bommel skrev: >> Benjamin Kramer wrote: >>> The attached patch modifies the llvm build system (both autotools and >>> cmake) to write the revision into PACKAGE_VERSION: >>> >>> $ llvm-config --version >>> 2.6-71981 >>> >> I don't think that's enough for LDC; we want to be able to compare the version >> with #if, so we need it to produce something like '#define LLVM_REV 71981' (i.e. >> a raw integer, not a string). >> > When we build Icedtea shark JIT we use the llvm-config version to make > the icedtea code compatible with api changes in llvm. > I belive you are trying to do something similarwith LDC. This can be > done without changing the llvm codebase. > > I suggest the following: > add to the LDC configure. > > LLVM_CFLAGS="$LLVM_CFLAGS -DLLVM_VERSION=`$LLVM_CONFIG --version | sed 's/\.//;s/svn.*//'`" > > this will take the llvm-config --version output and truncates the versionnumber from > > 2.6svn to 26 > > now the LLVM_VERSION can be used in your source code like this: > > #if LLVM_VERSION >= 26 > /*llvm 2.6 and above compatible code*/ > #endif > > #if LLVM_VERSION >= 25 > // etc... > #endifThat's not precise enough. API changes are introduced in svn all the time, and bugs are fixed (obsoleting workarounds). We currently test for 5 different trunk revisions after 2.5. Though I suppose a similar technique could be used with the original version of the patch, sed'ing out the revision nr. It'd certainly be less error-prone than the current approach.
Török Edwin
2009-May-18 17:13 UTC
[LLVMdev] [PATCH] llvm-config: add svn revision to --version
On 2009-05-18 20:06, Frits van Bommel wrote:> Xerxes Rånby wrote: > >> Frits van Bommel skrev: >> >>> Benjamin Kramer wrote: >>> >>>> The attached patch modifies the llvm build system (both autotools and >>>> cmake) to write the revision into PACKAGE_VERSION: >>>> >>>> $ llvm-config --version >>>> 2.6-71981 >>>> >>>> >>> I don't think that's enough for LDC; we want to be able to compare the version >>> with #if, so we need it to produce something like '#define LLVM_REV 71981' (i.e. >>> a raw integer, not a string). >>> >>> >> When we build Icedtea shark JIT we use the llvm-config version to make >> the icedtea code compatible with api changes in llvm. >> I belive you are trying to do something similarwith LDC. This can be >> done without changing the llvm codebase. >> >> I suggest the following: >> add to the LDC configure. >> >> LLVM_CFLAGS="$LLVM_CFLAGS -DLLVM_VERSION=`$LLVM_CONFIG --version | sed 's/\.//;s/svn.*//'`" >> >> this will take the llvm-config --version output and truncates the versionnumber from >> >> 2.6svn to 26 >> >> now the LLVM_VERSION can be used in your source code like this: >> >> #if LLVM_VERSION >= 26 >> /*llvm 2.6 and above compatible code*/ >> #endif >> >> #if LLVM_VERSION >= 25 >> // etc... >> #endif >> > > That's not precise enough. API changes are introduced in svn all the time, and > bugs are fixed (obsoleting workarounds). We currently test for 5 different trunk > revisions after 2.5. > > Though I suppose a similar technique could be used with the original version of > the patch, sed'ing out the revision nr. It'd certainly be less error-prone than > the current approach.I think you don't need to support all trunk revisions. People using trunk could be told to either update to a certain revision, or stick to a released version. This should suffice: #if LLVM_VERSION >= 25 .... #endif #if LLVM_VERSION == 26 #if LLVM_REVISION < MINIMUM_THAT_CONTAINS_ALLYOUNEED #error "Please update to SVN rXYZ" #else //code for SVN API #endif Best regards, --Edwin
Apparently Analagous Threads
- [LLVMdev] [PATCH] llvm-config: add svn revision to --version
- [LLVMdev] [PATCH] llvm-config: add svn revision to --version
- [LLVMdev] [PATCH] llvm-config: add svn revision to --version
- [LLVMdev] [PATCH] llvm-config: add svn revision to --version
- [LLVMdev] dragonegg now requires clang