You can try latexmk, it does almost all of the work when building LaTeX (including getting cross-references right) and can even watch for changes and rebuild the document when necessary, updating your PDF reader too. Just calling _latexmk -pdf -silent -xelatex -pvc mydoc.tex_ should suffice (the -pvc option is for the continuous build and preview mode).